diff --git a/README.md b/README.md new file mode 100644 index 0000000..a7a70ee --- /dev/null +++ b/README.md @@ -0,0 +1,3 @@ +# script.movielib + +Readme kommt diff --git a/addon.xml b/addon.xml index fead130..4a2f750 100644 --- a/addon.xml +++ b/addon.xml @@ -1,10 +1,10 @@ - + @@ -34,4 +34,4 @@ regss84@gmail.com https://github.com/Regss/script.movielib - \ No newline at end of file + diff --git a/changelog.txt b/changelog.txt index d07e1e7..f8a46e7 100644 --- a/changelog.txt +++ b/changelog.txt @@ -1,3 +1,9 @@ +[B]1.5.X BETA - has no sync in Kodi for urllib-Errors[/B] +- new User: me! +- Phytoncode upgraded from Version 2 to Version 3 with Phyton Script "2to3" +- Kodi intern Flags corrected +- Debug Code changed + [B]1.4.11[/B] - sync trigger "on player stop" now sync only movie that stopped - Fixed: allow to sync when server var POST_MAX_SIZE is set to 0 @@ -140,4 +146,4 @@ - Added: Sync Watched, LastPlayed, RecentlyAdded [B]1.0.0[/B] -- Initial \ No newline at end of file +- Initial diff --git a/resources/lib/art.py b/resources/lib/art.py index 667632d..8315c5d 100644 --- a/resources/lib/art.py +++ b/resources/lib/art.py @@ -5,10 +5,12 @@ import xbmcaddon import os from PIL import Image -import cStringIO +from io import StringIO +from urllib.request import urlopen import json import urllib + __addon__ = xbmcaddon.Addon() __addon_id__ = __addon__.getAddonInfo('id') __datapath__ = xbmc.translatePath(os.path.join('special://profile/addon_data/', __addon_id__)).replace('\\', '/') @@ -42,7 +44,7 @@ def create(source, i, width, height, q): if file_path[8:12] == 'http': try: link = urllib.unquote(file_path[8:][:-1]).encode('utf-8') - file = cStringIO.StringIO(urllib.urlopen(link).read()) + file = cStringIO.StringIO(urllib.request.urlopen(link).read()) except: file = '' else: @@ -81,4 +83,4 @@ def create(source, i, width, height, q): debug.debug(str(Error)) return output - \ No newline at end of file + diff --git a/resources/lib/debug.py b/resources/lib/debug.py index 133a9ee..9e56f88 100644 --- a/resources/lib/debug.py +++ b/resources/lib/debug.py @@ -10,9 +10,9 @@ def debug(msg): xbmc.log('>>>> Movielib <<<< ' + msg, level=xbmc.LOGDEBUG) def notice(msg): - xbmc.log('>>>> Movielib <<<< ' + msg, level=xbmc.LOGNOTICE) + xbmc.log('>>>> Movielib <<<< ' + msg, level=xbmc.LOGLOGNOTICE) def notify(msg): if 'true' in __addon__.getSetting('notify'): xbmc.executebuiltin('Notification(Movielib, ' + msg + ', 4000, ' + __icon__ + ')') - \ No newline at end of file + diff --git a/resources/lib/prepareValues.py b/resources/lib/prepareValues.py index b913342..54ab802 100644 --- a/resources/lib/prepareValues.py +++ b/resources/lib/prepareValues.py @@ -2,10 +2,8 @@ import xbmcvfs import os -import urllib2 import base64 import hashlib - import art import debug @@ -92,4 +90,53 @@ def prep(self, m, t): values[q] = val[q] debug.debug(str(values)) - return values \ No newline at end of file + return values + 'runtime': str(m['runtime'] / 60) if 'runtime' in m else '', + 'genre[]': panelsValue['genre'] if 'genre' in m else '', + 'director[]': panelsValue['director'] if 'director' in m else '', + 'originaltitle': m['originaltitle'].encode('utf-8') if 'originaltitle' in m else '', + 'country[]': panelsValue['country'] if 'country' in m else '', + 'set': m['set'].encode('utf-8') if 'set' in m else '', + 'imdbid': m['imdbnumber'] if 'imdbnumber' in m else '', + 'actor[]': panelsValue['actor'] if 'cast' in m else '', + 'studio[]': panelsValue['studio'] if 'studio' in m else '', + 'premiered': m['premiered'] if 'premiered' in m else '', + 'episode': str(m['episode']) if 'episode' in m else '', + 'season': str(m['season']) if 'season' in m else '', + 'tvshow': str(m['tvshowid']) if 'tvshowid' in m else '', + 'firstaired': m['firstaired'] if 'firstaired' in m else '', + 'file': m['file'].replace('\\', '/').encode('utf-8') if 'file' in m else '', + 'play_count': str(m['playcount']), + 'last_played': m['lastplayed'], + 'date_added': m['dateadded'], + 'trailer': trailer, + 'hash': hashlib.md5(str(m)).hexdigest() + } + + # streamdetails + if 'streamdetails' in m: + stream = [] + if len(m['streamdetails']['video']) > 0: + for s in m['streamdetails']['video']: + stream.append(';'.join(['v',s['codec'], str(s['aspect']), str(s['width']), str(s['height']), str(s['duration'] / 60), '', '', '', ''])) + + if len(m['streamdetails']['audio']) > 0: + for s in m['streamdetails']['audio']: + stream.append(';'.join(['a', '', '', '', '', '', s['codec'], str(s['channels']), s['language'], ''])) + + if len(m['streamdetails']['subtitle']) > 0: + for s in m['streamdetails']['subtitle']: + stream.append(';'.join(['s', '', '', '', '', '', '', '', '', s['language']])) + + val.update({ + 'stream[]': stream + }) + + # add only values support for this video type + values = {} + for q in self.tn[t]['values']: + if q in val and len(val[q]) > 0: + values[q] = val[q] + + debug.debug(str(values)) + return values diff --git a/resources/lib/sendRequest.py b/resources/lib/sendRequest.py index c10b366..c72c9d0 100644 --- a/resources/lib/sendRequest.py +++ b/resources/lib/sendRequest.py @@ -2,8 +2,8 @@ import xbmc import xbmcaddon -import urllib -import urllib2 +import urllib.request +import urllib.parse import json import time import base64 @@ -23,7 +23,7 @@ def send(self, option, values=''): debug.debug('[REQUEST]: ' + str(values)) # try send data - data = urllib.urlencode(values, True) + data = urllib.parse.urlencode(values, True) data_len = len(data) debug.debug('[REQUEST DATA SIZE]: ' + str(data_len) + ' bytes') @@ -35,11 +35,11 @@ def send(self, option, values=''): for l in range(1, 4): try: - request = urllib2.Request(self.setXBMC['URL'] + option, data) + request = urllib.request.Request(self.setXBMC['URL'] + option, data) if 'true' in self.setXBMC['Auth']: base64string = base64.encodestring(self.setXBMC['AuthLogin'] + ':' + self.setXBMC['AuthPass']).replace('\n', '') request.add_header('Authorization', 'Basic ' + base64string) - result = urllib2.urlopen(request) + result = urllib.request(request) output = result.read() except Exception as Error: conn = False @@ -73,4 +73,4 @@ def send(self, option, values=''): return False return output - \ No newline at end of file + diff --git a/resources/lib/sync.py b/resources/lib/sync.py index da02e2e..1663727 100644 --- a/resources/lib/sync.py +++ b/resources/lib/sync.py @@ -322,4 +322,4 @@ def getDataFromXBMC(self, dataSORT): debug.debug('[' + t + type.title() + 'XBMC]: ' + str(val)) return dataXBMC - \ No newline at end of file + diff --git a/resources/lib/syncImage.py b/resources/lib/syncImage.py index c40aa86..b5cbaba 100644 --- a/resources/lib/syncImage.py +++ b/resources/lib/syncImage.py @@ -4,9 +4,9 @@ import xbmcaddon import os import urllib -import urllib2 import hashlib import base64 +from urllib.request import urlopen __addon__ = xbmcaddon.Addon() __addonname__ = __addon__.getAddonInfo('name') @@ -106,6 +106,93 @@ def addImg(self, ImagesXBMC, ImagesToAdd, ImagesSORT): if addedCount > 0: debug.notify(__lang__(32104).encode('utf-8') + ' ' + __lang__(32121).encode('utf-8') + ' (' + __lang__(self.lang[type]).encode('utf-8') + ' - ' + __lang__(self.lang[img_type]).encode('utf-8') + '): ' + str(addedCount)) +def removeImg(self, ImagesToRemove): + # removing images + toRemove = {} + removedCount = 0 + for type, vals in ImagesToRemove.items(): + for img_type, v in vals.items(): + if len(v) > 0: + debug.debug('=== REMOVING ' + type.upper() + ' ' + img_type.upper() + ' IMAGES ===') + for file in v: + if 'poster' == img_type: + toRemove[removedCount] = type + '_' + str(file) + '.jpg' + if 'fanart' == img_type: + toRemove[removedCount] = type + '_' + str(file) + '_f.jpg' + if 'thumb' == img_type: + toRemove[removedCount] = 'actors/' + str(file) + '.jpg' + if 'exthumb' == img_type: + toRemove[removedCount] = type + '_' + str(file) + '.jpg' + removedCount += 1 + toRemove[removedCount] = type + '_' + str(file) + 'm.jpg' + removedCount += 1 + if len(toRemove) > 0: + if sendRequest.send(self, 'removeimages', toRemove) is False: + return False + debug.notify(__lang__(32105).encode('utf-8') + ' ' + __lang__(32121).encode('utf-8') + ': ' + str(removedCount)) + + ImagesToRemove = {} + for v_type in ImagesXBMC.keys(): + ImagesToRemove[v_type] = {} + for img_type in ImagesXBMC[v_type].keys(): + ImagesToRemove[v_type][img_type] = set(ImagesSite[v_type][img_type]) - set(ImagesXBMC[v_type][img_type].keys()) + debug.debug('[ImagesToRemove]: ' + str(ImagesToRemove)) + removeImg(self, ImagesToRemove) + + # update hash + value = { 'images': str(hashImagesXBMC) } + if sendRequest.send(self, 'updatehash', value) is False: + return False + +def addImg(self, ImagesXBMC, ImagesToAdd, ImagesSORT): + # adding new images + for type in ImagesSORT['images']: + + for img_type in ImagesSORT[type]: + + if len(ImagesToAdd[type][img_type]) > 0: + debug.debug('=== ADDING ' + type.upper() + ' ' + img_type.upper() + ' IMAGES ===') + + countToAdd = len(ImagesToAdd[type][img_type]) + addedCount = 0 + self.progBar.create(__lang__(32200), __addonname__ + ', ' + __lang__(32204) + ' ' + __lang__(32121) + ' (' + __lang__(self.lang[type]) + ' - ' + __lang__(self.lang[img_type]) + ')') + + for id in ImagesToAdd[type][img_type]: + # progress bar update + p = int((float(100) / float(countToAdd)) * float(addedCount)) + self.progBar.update(p, str(addedCount + 1) + '/' + str(countToAdd) + ' - ' + self.namesXBMC[type][id]) + + if 'poster' == img_type and 'episodes' in type: + t = art.create(ImagesXBMC[type][img_type][id], 'p', 200, 113, 70) + if 'poster' == img_type and 'episodes' not in type: + t = art.create(ImagesXBMC[type][img_type][id], 'p', 200, 294, 70) + if 'fanart' == img_type: + t = art.create(ImagesXBMC[type][img_type][id], 'f', 1280, 720, 70) + if 'thumb' == img_type: + t = art.create(ImagesXBMC[type][img_type][id], 'a', 75, 100, 70) + if 'exthumb' == img_type: + ex_size = self.setSITE['xbmc_exthumbs_q'].split('x') + t = art.create('image://' + urllib.quote_plus(ImagesXBMC[type][img_type][id].encode('utf-8')) + '/', 'e', int(ex_size[0]), int(ex_size[1]), 70) + + if len(t) > 0: + if 'actors' in type: + name = 'actors/' + str(id) + '.jpg' + else: + f = '_f' if 'fanart' in img_type else '' + name = type + '_' + str(id) + f + '.jpg' + value = { + 'name': name, + 'img': base64.b64encode(t) + } + if sendRequest.send(self, 'addimages', value) is False: + self.progBar.close() + return False + addedCount += 1 + self.progBar.close() + + if addedCount > 0: + debug.notify(__lang__(32104).encode('utf-8') + ' ' + __lang__(32121).encode('utf-8') + ' (' + __lang__(self.lang[type]).encode('utf-8') + ' - ' + __lang__(self.lang[img_type]).encode('utf-8') + '): ' + str(addedCount)) + def removeImg(self, ImagesToRemove): # removing images toRemove = {} diff --git a/service.py b/service.py index 9476607..a9da0a2 100644 --- a/service.py +++ b/service.py @@ -21,25 +21,25 @@ def __init__(self): # start Movielib on KODI start if 'true' in __addon__.getSetting('OnStart'): - xbmc.executebuiltin('XBMC.RunScript(' + __addon_id__ + ', 1)') + xbmc.executebuiltin('RunScript(' + __addon_id__ + ', 1)') def onNotification(self, sender, method, data): data = json.loads(data) # start Movielib for update banner (Now Playing) if method == 'Player.OnPlay': if 'item' in data and 'type' in data['item'] and 'id' in data['item']: - xbmc.executebuiltin('XBMC.RunScript(' + __addon_id__ + ', 2, ' + str(data['item']['id']) + ', ' + data['item']['type'] + ')') + xbmc.executebuiltin('RunScript(' + __addon_id__ + ', 2, ' + str(data['item']['id']) + ', ' + data['item']['type'] + ')') # start Movielib on trigger if method in __trigger__.keys() and 'true' in __trigger__[method]: if method == 'Player.OnStop': if 'item' in data and 'type' in data['item'] and 'id' in data['item']: - xbmc.executebuiltin('XBMC.RunScript(' + __addon_id__ + ', 3, ' + str(data['item']['id']) + ', ' + data['item']['type'] + ')') + xbmc.executebuiltin('RunScript(' + __addon_id__ + ', 3, ' + str(data['item']['id']) + ', ' + data['item']['type'] + ')') else: - xbmc.executebuiltin('XBMC.RunScript(' + __addon_id__ + ', 1)') + xbmc.executebuiltin('RunScript(' + __addon_id__ + ', 1)') monitor = Monitor() -while(not xbmc.abortRequested): +while(not xbmc.Monitor().abortRequested()): xbmc.sleep(100) - \ No newline at end of file +