def modes(): if not sys.argv[2]: Log('Version: %s' % addon.getAddonInfo('version')) Log('Unicode support: %s' % os.path.supports_unicode_filenames) cm = {} updateall = (getString(30103), 'RunPlugin(%s?mode=appfeed&sitemode=updateAll)' % sys.argv[0]) cm['wl'] = [(getString(30185) % 'Watchlist', 'RunPlugin(%s?mode=appfeed&sitemode=ExportList&url=%s)' % (sys.argv[0], wl)), updateall] cm['lib'] = [ (getString(30185) % getString(30060), 'RunPlugin(%s?mode=appfeed&sitemode=ExportList&url=%s)' % (sys.argv[0], lib)), (getString(30116), 'RunPlugin(%s?mode=appfeed&sitemode=RefreshList&url=%s)' % (sys.argv[0], lib)), updateall ] cm['movie'] = [ updateall, (getString(30102), 'RunPlugin(%s?mode=movies&sitemode=addMoviesdb&url=f)' % sys.argv[0]) ] cm['tv'] = [ updateall, (getString(30105), 'RunPlugin(%s?mode=tv&sitemode=addTVdb&url=f)' % sys.argv[0]) ] cm['search'] = [updateall] if updateRunning(): updaterun = json.dumps( (getString(30135), 'RunPlugin(%s?mode=appfeed&sitemode=updateAll)' % sys.argv[0])) cm = json.loads( json.dumps(cm).replace(json.dumps(updateall), updaterun)) addDir('Watchlist', 'appfeed', 'ListMenu', wl, cm=cm['wl']) addDir(getString(30104), 'listmovie', 'LIST_MOVIE_ROOT', cm=cm['movie']) addDir(getString(30107), 'listtv', 'LIST_TV_ROOT', cm=cm['tv']) addDir(getString(30108), 'appfeed', 'SEARCH_DB', cm=cm['search']) addDir(getString(30060), 'appfeed', 'ListMenu', lib, cm=cm['lib']) if addon.getSetting('update_mm') == 'true': addDir(cm['search'][0][0], 'appfeed', 'updateAll') xbmcplugin.endOfDirectory(pluginhandle) else: exec 'import resources.lib.%s as sitemodule' % args.get('mode') exec 'sitemodule.%s()' % args.get('sitemode')
def modes(): if not sys.argv[2]: Log('Version: %s' % addon.getAddonInfo('version')) Log('Unicode support: %s' % os.path.supports_unicode_filenames) cm_watchlist = [ (getString(30185) % 'Watchlist', 'RunPlugin(%s?mode=appfeed&sitemode=ExportList&url=%s)' % (sys.argv[0], wl)) ] cm_library = [ (getString(30185) % getString(30060), 'RunPlugin(%s?mode=appfeed&sitemode=ExportList&url=%s)' % (sys.argv[0], lib)), (getString(30116), 'RunPlugin(%s?mode=appfeed&sitemode=RefreshList&url=%s)' % (sys.argv[0], lib)) ] updatemovie = [ (getString(30103), 'RunPlugin(%s?mode=appfeed&sitemode=updateAll)' % sys.argv[0]), (getString(30102), 'RunPlugin(%s?mode=movies&sitemode=addMoviesdb&url=f)' % sys.argv[0]) ] updatetv = [ (getString(30103), 'RunPlugin(%s?mode=appfeed&sitemode=updateAll)' % sys.argv[0]), (getString(30105), 'RunPlugin(%s?mode=tv&sitemode=addTVdb&url=f)' % sys.argv[0]) ] if updateRunning(): updatemovie = updatetv = [ (getString(30135), 'RunPlugin(%s?mode=appfeed&sitemode=updateAll)' % sys.argv[0]) ] addDir('Watchlist', 'appfeed', 'ListMenu', wl, cm=cm_watchlist) addDir(getString(30104), 'listmovie', 'LIST_MOVIE_ROOT', cm=updatemovie) addDir(getString(30107), 'listtv', 'LIST_TV_ROOT', cm=updatetv) addDir(getString(30108), 'appfeed', 'SEARCH_DB') addDir(getString(30060), 'appfeed', 'ListMenu', lib, cm=cm_library) xbmcplugin.endOfDirectory(pluginhandle) else: exec 'import resources.lib.%s as sitemodule' % args.get('mode') exec 'sitemodule.%s()' % args.get('sitemode')
def updateAll(): from service import updateRunning from datetime import datetime if updateRunning(): return writeConfig('update_running', datetime.today().strftime('%Y-%m-%d %H:%M')) cj = MechanizeLogin() if not cj: writeConfig('update_running', 'false') return import movies import tv Log('Starting DBUpdate') Notif(getString(30106)) xbmc.executebuiltin('Container.Refresh') tvresult = tv.addTVdb(False, cj=cj) mvresult = movies.addMoviesdb(False, cj=cj) NewAsins = getCategories() if tvresult and mvresult: writeConfig('last_update', datetime.today().strftime('%Y-%m-%d')) if mvresult: movies.setNewest(NewAsins) movies.updateFanart() if tvresult: tv.setNewest(NewAsins) tv.updateFanart() writeConfig('update_running', 'false') if xbmc.getInfoLabel( 'Container.FolderPath') == 'plugin://plugin.video.amazon/': xbmc.executebuiltin('Container.Refresh') Notif(getString(30126)) Log('DBUpdate finished')
def updateAll(): from service import updateRunning from datetime import datetime if updateRunning(): return writeConfig('update_running', datetime.today().strftime('%Y-%m-%d %H:%M')) cj = MechanizeLogin() if not cj: writeConfig('update_running', 'false') return import movies import tv Log('Starting DBUpdate') Notif(getString(30106)) xbmc.executebuiltin('Container.Refresh') tvresult = tv.addTVdb(False, cj=cj) mvresult = movies.addMoviesdb(False, cj=cj) NewAsins = getCategories() if tvresult and mvresult: writeConfig('last_update', datetime.today().strftime('%Y-%m-%d')) if mvresult: movies.setNewest(NewAsins) movies.updateFanart() if tvresult: tv.setNewest(NewAsins) tv.updateFanart() writeConfig('update_running', 'false') if xbmc.getInfoLabel('Container.FolderPath') == 'plugin://plugin.video.amazon/': xbmc.executebuiltin('Container.Refresh') Notif(getString(30126)) Log('DBUpdate finished')
def modes(): if not sys.argv[2]: Log('Version: {}'.format(var.addon.getAddonInfo('version'))) Log('Unicode filename support: {}'.format(os.path.supports_unicode_filenames)) cm = {} updateall = (getString(30103), 'RunPlugin({}?mode=appfeed&sitemode=updateAll)'.format(sys.argv[0])) cm['wl'] = [(getString(30185).format('Watchlist'), 'RunPlugin({}?mode=appfeed&sitemode=ExportList&url={})'.format(sys.argv[0], wl)), updateall] cm['lib'] = [(getString(30185).format(getString(30060)), 'RunPlugin({}?mode=appfeed&sitemode=ExportList&url={})'.format(sys.argv[0], lib)), (getString(30116), 'RunPlugin({}?mode=appfeed&sitemode=RefreshList&url={})'.format(sys.argv[0], lib)), updateall] cm['movie'] = [updateall, (getString(30102), 'RunPlugin({}?mode=movies&sitemode=addMoviesdb&url=f)'.format(sys.argv[0]))] cm['tv'] = [updateall, (getString(30105), 'RunPlugin({}?mode=tv&sitemode=addTVdb&url=f)'.format(sys.argv[0]))] cm['search'] = [updateall] if updateRunning(): updaterun = json.dumps((getString(30135), 'RunPlugin({}?mode=appfeed&sitemode=updateAll)'.format(sys.argv[0]))) cm = json.loads(json.dumps(cm).replace(json.dumps(updateall), updaterun)) if var.multiuser: cm['mu'] = [(getString(30174).split('.')[0], 'RunPlugin({}?mode=common&sitemode=MechanizeLogin&ask=true)'.format(sys.argv[0])), (getString(30175).split('.')[0], 'RunPlugin({}?mode=common&sitemode=removeUser)'.format(sys.argv[0])), (getString(30176), 'RunPlugin({}?mode=common&sitemode=renameUser)'.format(sys.argv[0]))] addDir(getString(30178) + loadUser()['name'], 'common', 'switchUser', '', cm=cm['mu']) addDir('Watchlist', 'appfeed', 'ListMenu', wl, cm=cm['wl']) addDir(getString(30104), 'listmovie', 'LIST_MOVIE_ROOT', cm=cm['movie']) addDir(getString(30107), 'listtv', 'LIST_TV_ROOT', cm=cm['tv']) addDir(getString(30108), 'appfeed', 'SEARCH_DB', cm=cm['search']) addDir(getString(30060), 'appfeed', 'ListMenu', lib, cm=cm['lib']) if var.addon.getSetting('update_mm') == 'true': addDir(cm['search'][0][0], 'appfeed', 'updateAll') xbmcplugin.endOfDirectory(var.pluginhandle) else: exec('import resources.lib.{} as sitemodule'.format(var.args.get('mode'))) exec('sitemodule.{}()'.format(var.args.get('sitemode')))
def modes(): if not sys.argv[2]: Log('Version: %s' % var.addon.getAddonInfo('version')) Log('Unicode filename support: %s' % os.path.supports_unicode_filenames) cm = {} updateall = (getString(30103), 'RunPlugin(%s?mode=appfeed&sitemode=updateAll)' % sys.argv[0]) cm['wl'] = [(getString(30185) % 'Watchlist', 'RunPlugin(%s?mode=appfeed&sitemode=ExportList&url=%s)' % (sys.argv[0], wl)), updateall] cm['lib'] = [(getString(30185) % getString(30060), 'RunPlugin(%s?mode=appfeed&sitemode=ExportList&url=%s)' % (sys.argv[0], lib)), (getString(30116), 'RunPlugin(%s?mode=appfeed&sitemode=RefreshList&url=%s)' % (sys.argv[0], lib)), updateall] cm['movie'] = [updateall, (getString(30102), 'RunPlugin(%s?mode=movies&sitemode=addMoviesdb&url=f)' % sys.argv[0])] cm['tv'] = [updateall, (getString(30105), 'RunPlugin(%s?mode=tv&sitemode=addTVdb&url=f)' % sys.argv[0])] cm['search'] = [updateall] if updateRunning(): updaterun = json.dumps((getString(30135), 'RunPlugin(%s?mode=appfeed&sitemode=updateAll)' % sys.argv[0])) cm = json.loads(json.dumps(cm).replace(json.dumps(updateall), updaterun)) if var.multiuser: cm['mu'] = [(getString(30174).split('.')[0], 'RunPlugin(%s?mode=common&sitemode=LogIn)' % sys.argv[0]), (getString(30175).split('.')[0], 'RunPlugin(%s?mode=common&sitemode=removeUser)' % sys.argv[0]), (getString(30176), 'RunPlugin(%s?mode=common&sitemode=renameUser)' % sys.argv[0])] addDir(getString(30178) + loadUser()['name'], 'common', 'switchUser', '', cm=cm['mu']) addDir('Watchlist', 'appfeed', 'ListMenu', wl, cm=cm['wl']) addDir(getString(30104), 'listmovie', 'LIST_MOVIE_ROOT', cm=cm['movie']) addDir(getString(30107), 'listtv', 'LIST_TV_ROOT', cm=cm['tv']) addDir(getString(30108), 'appfeed', 'SEARCH_DB', cm=cm['search']) addDir(getString(30060), 'appfeed', 'ListMenu', lib, cm=cm['lib']) if var.addon.getSetting('update_mm') == 'true': addDir(cm['search'][0][0], 'appfeed', 'updateAll') xbmcplugin.endOfDirectory(var.pluginhandle) else: exec 'import resources.lib.%s as sitemodule' % var.args.get('mode') exec 'sitemodule.%s()' % var.args.get('sitemode')
def addTVdb(full_update=True, libasins=None, cj=True): if isinstance(cj, bool): cj = mechanizeLogin() if not cj: return prime = True new_libasins = False endIndex = 0 goAhead = 1 SERIES_COUNT = 0 SEASON_COUNT = 0 EPISODE_COUNT = 0 approx = 0 if full_update and not libasins: if updateRunning(): return if not Dialog.yesno(getString(30136), getString(30137), getString(30138) % '30'): return DialogPG.create(getString(30130)) DialogPG.update(0, getString(30131)) createTVdb() ALL_SERIES_ASINS = '' ALL_SEASONS_ASINS = [] else: cleanDB() ALL_SEASONS_ASINS = getTVdbAsins('seasons', retlist=True, value='asin,episodetotal') ALL_SERIES_ASINS = getTVdbAsins('shows') if libasins: prime = False ALL_SEASONS_ASINS = [] new_libasins = checkLibraryAsins(libasins, cj) if not new_libasins: return while goAhead == 1: jsondata = appfeed.getList('TVEpisode&RollUpToSeason=T', endIndex, isPrime=prime, OrderBy='Title', NumberOfResults=MAX, AsinList=new_libasins) if not jsondata: goAhead = -1 break titles = jsondata['message']['body']['titles'] approx = jsondata['message']['body'].get('approximateSize', approx) endI = jsondata['message']['body']['endIndex'] if endI: endIndex = endI else: endIndex += len(titles) del jsondata if titles: SERIES_ASINS = '' EPISODE_ASINS = [] EPISODE_NUM = [] for title in titles: if full_update and DialogPG.iscanceled(): goAhead = -1 break SEASONS_ASIN = title['titleId'] if onlyGer and re.compile('(?i)\[(ov|omu)[(\W|omu|ov)]*\]' ).search(title['title']): Log('Season Ignored: %s' % title['title'], xbmc.LOGDEBUG) found = True else: season_size = int(title['childTitles'][0]['size']) found, ALL_SEASONS_ASINS = compasin( ALL_SEASONS_ASINS, SEASONS_ASIN, season_size) if not found: if ASIN_ADD([title]): SEASON_COUNT += 1 if title['ancestorTitles']: SERIES_KEY = title['ancestorTitles'][0]['titleId'] else: SERIES_KEY = title['titleId'] if SERIES_KEY not in ALL_SERIES_ASINS and 'bbl test' not in title[ 'title'].lower(): SERIES_COUNT += 1 SERIES_ASINS += SERIES_KEY + ',' ALL_SERIES_ASINS += SERIES_KEY + ',' if season_size < 1: season_size = MAX parsed = urlparse.urlparse( title['childTitles'][0]['feedUrl']) EPISODE_ASINS.append( urlparse.parse_qs(parsed.query)['SeasonASIN']) EPISODE_NUM.append(season_size) if (approx and endIndex + 1 >= approx) or (not approx and len(titles) < 1): goAhead = 0 del titles if SERIES_ASINS: ASIN_ADD(0, asins=SERIES_ASINS) if full_update: DialogPG.update(int(EPISODE_COUNT * 100.0 / EPI_TOTAL), getString(30132) % SERIES_COUNT, getString(30133) % SEASON_COUNT, getString(30134) % EPISODE_COUNT) episodes = 0 AsinList = '' EPISODE_NUM.append(MAX + 1) for index, item in enumerate(EPISODE_ASINS): episodes += EPISODE_NUM[index] AsinList += ','.join(item) + ',' if (episodes + EPISODE_NUM[index + 1]) > MAX: jsondata = appfeed.getList('TVEpisode', 0, isPrime=prime, NumberOfResults=MAX, AsinList=AsinList) titles = jsondata['message']['body']['titles'] if titles: EPISODE_COUNT += ASIN_ADD(titles) if full_update and DialogPG.iscanceled(): goAhead = -1 break episodes = 0 AsinList = '' if full_update: DialogPG.update(int(EPISODE_COUNT * 100.0 / EPI_TOTAL), getString(30132) % SERIES_COUNT, getString(30133) % SEASON_COUNT, getString(30134) % EPISODE_COUNT) del titles else: goAhead = 0 if goAhead == 0: if not libasins: updatePop() delShows, delSeasons, delEpisodes = deleteremoved( getcompresult(ALL_SEASONS_ASINS)) UpdateDialog(SERIES_COUNT, SEASON_COUNT, EPISODE_COUNT, delShows, delSeasons, delEpisodes) addTVdb(False, 'full', cj) fixDBLShows() fixYears() fixStars() fixHDshows() updateEpisodes() fixTitles() if full_update: setNewest() DialogPG.close() updateFanart() tvDB.commit() writeConfig("EpisodesTotal", countDB('episodes')) return True return False
def addMoviesdb(full_update=True, cj=True): MOV_TOTAL = int(getConfig('MoviesTotal', '6000')) dialog = xbmcgui.DialogProgress() if isinstance(cj, bool): cj = MechanizeLogin() if not cj: return if full_update: if updateRunning(): return dialog.create(getString(30120)) dialog.update(0, getString(30121)) db.createDatabase(MovieDB, 'movie') MOVIE_ASINS = [] else: MOVIE_ASINS = getMoviedbAsins(retlist=True) page = 1 goAhead = 1 endIndex = 0 new_mov = 0 retrycount = 0 approx = 0 while not approx: jsondata = appfeed.getList('Movie', randint(1, 20), NumberOfResults=1) approx = jsondata['message']['body'].get('approximateSize', 0) xbmc.sleep(randint(500, 1000)) while goAhead == 1: MAX = randint(5, MAX_RES) jsondata = appfeed.getList('Movie', endIndex, NumberOfResults=MAX, OrderBy='Title') if not jsondata: goAhead = -1 break titles = jsondata['message']['body']['titles'] del jsondata if titles: for title in titles: retrycount = 0 if full_update and dialog.iscanceled(): goAhead = -1 break if 'titleId' in title.keys(): asin = title['titleId'] if '_duplicate_' not in title['title']: if var.onlyGer and re.compile(regex_ovf).search( title['title']): Log('Movie Ignored: {}'.format(title['title']), xbmc.LOGDEBUG) found = True else: found, MOVIE_ASINS = compasin(MOVIE_ASINS, asin) if not found: new_mov += ASIN_ADD(title) else: retrycount += 1 endIndex += 1 if retrycount > 2: wait_time = 3 # randint(180, 420) Log('Getting {} times a empty response. Waiting {} sec'.format( retrycount, wait_time)) sleep(wait_time) retrycount = 0 endIndex += len(titles) if (approx and endIndex + 1 >= approx) or (not approx and len(titles) == 10): goAhead = 0 page += 1 if full_update: if approx: MOV_TOTAL = approx dialog.update(int(endIndex * 100.0 / MOV_TOTAL), getString(30122).format(page), getString(30123).format(new_mov)) if full_update and dialog.iscanceled(): goAhead = -1 if len(titles) > 9: endIndex -= 10 if goAhead == 0: endIndex += 10 updateLibrary(cj=cj) updatePop() writeConfig("MoviesTotal", endIndex) Log('Movie Update: New {} Deleted {} Total {}'.format( new_mov, deleteremoved(MOVIE_ASINS), endIndex)) if full_update: setNewest() dialog.close() updateFanart() xbmc.executebuiltin("XBMC.Container.Refresh") # MovieDB.commit() return True return False
def addTVdb(full_update=True, libasins=None, cj=True): if isinstance(cj, bool): cj = MechanizeLogin() if not cj: return prime = True new_libasins = False endIndex = 0 goAhead = 1 SERIES_COUNT = 0 SEASON_COUNT = 0 EPISODE_COUNT = 0 approx = 0 retrycount = 0 if full_update and not libasins: if updateRunning(): return if not Dialog.yesno(getString(30136), getString(30137), getString(30138).format('30')): return DialogPG.create(getString(30130)) DialogPG.update(0, getString(30131)) db.createDatabase(tvDB, 'tv') ALL_SERIES_ASINS = '' ALL_SEASONS_ASINS = [] else: cleanDB() ALL_SEASONS_ASINS = getTVdbAsins('seasons', retlist=True, value='asin,episodetotal') ALL_SERIES_ASINS = getTVdbAsins('shows') if libasins: prime = False ALL_SEASONS_ASINS = [] new_libasins = checkLibraryAsins(libasins, cj) if not new_libasins: return False else: while not approx: jsondata = appfeed.getList('TVEpisode&RollUpToSeason=T', randint(1, 20), NumberOfResults=1) approx = jsondata['message']['body'].get('approximateSize', 0) xbmc.sleep(randint(500, 1000)) while goAhead == 1: MAX = randint(20, MAX_RES) if new_libasins: jsondata = appfeed.ASIN_LOOKUP(new_libasins) else: jsondata = appfeed.getList('TVEpisode&RollUpToSeason=T', endIndex, isPrime=prime, OrderBy='Title', NumberOfResults=MAX) if not jsondata: goAhead = -1 break titles = jsondata['message']['body']['titles'] endIndex += len(titles) if titles: retrycount = 0 SERIES_ASINS = '' EPISODE_ASINS = [] EPISODE_NUM = [] for title in titles: if full_update and DialogPG.iscanceled(): goAhead = -1 break SEASONS_ASIN = title['titleId'] if var.onlyGer and not libasins and re.compile(regex_ovf).search(title['title']): Log('Season Ignored: {}'.format(title['title']), xbmc.LOGDEBUG) found = True else: season_size = int(title['childTitles'][0]['size']) found, ALL_SEASONS_ASINS = compasin(ALL_SEASONS_ASINS, SEASONS_ASIN, season_size) if not found: if ASIN_ADD([title]): SEASON_COUNT += 1 if title['ancestorTitles']: SERIES_KEY = title['ancestorTitles'][0]['titleId'] else: SERIES_KEY = title['titleId'] if SERIES_KEY not in ALL_SERIES_ASINS and 'bbl test' not in title['title'].lower(): SERIES_COUNT += 1 SERIES_ASINS += SERIES_KEY + ',' ALL_SERIES_ASINS += SERIES_KEY + ',' if season_size < 1: season_size = MAX parsed = urlparse(title['childTitles'][0]['feedUrl']) EPISODE_ASINS.append(parse_qs(parsed.query)['SeasonASIN']) EPISODE_NUM.append(season_size) if (approx and endIndex + 1 >= approx) or (not approx and len(titles) < 1): goAhead = 0 del titles if SERIES_ASINS: ASIN_ADD(0, asins=SERIES_ASINS) if full_update: DialogPG.update(int(SEASON_COUNT * 100.0 / approx), getString(30132).format(SERIES_COUNT), getString(30133).format(SEASON_COUNT), getString(30134).format(EPISODE_COUNT)) episodes = 0 AsinList = '' EPISODE_NUM.append(MAX + 1) for index, item in enumerate(EPISODE_ASINS): episodes += EPISODE_NUM[index] AsinList += ','.join(item) + ',' if (episodes + EPISODE_NUM[index + 1]) > MAX: jsondata = appfeed.getList('TVEpisode', 0, isPrime=prime, NumberOfResults=MAX, AsinList=AsinList) titles = jsondata['message']['body']['titles'] if titles: EPISODE_COUNT += ASIN_ADD(titles) if full_update and DialogPG.iscanceled(): goAhead = -1 break episodes = 0 AsinList = '' if full_update: DialogPG.update(int(SEASON_COUNT * 100.0 / approx), getString(30132).format(SERIES_COUNT), getString(30133).format(SEASON_COUNT), getString(30134).format(EPISODE_COUNT)) del titles else: retrycount += 1 endIndex += 1 if (approx and endIndex + 1 >= approx) or (not approx): goAhead = 0 if retrycount > 2: wait_time = 3 # randint(180, 420) Log('Getting {} times a empty response. Waiting {} sec'.format(retrycount, wait_time)) sleep(wait_time) retrycount = 0 if goAhead == 0: finished = False if not libasins: updatePop() delShows, delSeasons, delEpisodes = deleteremoved(getcompresult(ALL_SEASONS_ASINS)) UpdateDialog(SERIES_COUNT, SEASON_COUNT, EPISODE_COUNT, delShows, delSeasons, delEpisodes) finished = addTVdb(False, 'full', cj) if not finished: fixDBLShows() fixYears() fixStars() fixHDshows() updateEpisodes() fixTitles() if full_update: setNewest() DialogPG.close() updateFanart() tvDB.commit() return True return False
def addMoviesdb(full_update=True, cj=True): MOV_TOTAL = int(getConfig('MoviesTotal', '6000')) dialog = xbmcgui.DialogProgress() if isinstance(cj, bool): cj = mechanizeLogin() if not cj: return if full_update: if updateRunning(): return dialog.create(getString(30120)) dialog.update(0, getString(30121)) createMoviedb() MOVIE_ASINS = [] else: MOVIE_ASINS = getMoviedbAsins(retlist=True) page = 1 goAhead = 1 endIndex = 0 new_mov = 0 retrycount = 0 approx = appfeed.getList('Movie', 0, NumberOfResults=1)['message']['body'].get( 'approximateSize', 0) filter_mov = approx > 8000 while goAhead == 1: jsondata = appfeed.getList('Movie', endIndex, NumberOfResults=MAX, OrderBy='Title', enablefilter=filter_mov) if not jsondata: goAhead = -1 break approx = jsondata['message']['body'].get('approximateSize', approx) titles = jsondata['message']['body']['titles'] del jsondata if titles: for title in titles: if full_update and dialog.iscanceled(): goAhead = -1 break if 'titleId' in title.keys(): asin = title['titleId'] if '_duplicate_' not in title['title']: if onlyGer and re.compile( '(?i)\[(ov|omu)[(\W|omu|ov)]*\]').search( title['title']): Log('Movie Ignored: %s' % title['title'], xbmc.LOGDEBUG) found = True else: found, MOVIE_ASINS = compasin(MOVIE_ASINS, asin) if not found: new_mov += ASIN_ADD(title) else: retrycount += 1 if retrycount > 3: Log('Waiting 5min') sleep(300) appfeed.getList('Movie', endIndex - randint(1, MAX - 1), NumberOfResults=randint(1, 10), enablefilter=filter_mov) retrycount = 0 endIndex += len(titles) if (approx and endIndex + 1 >= approx) or (not approx and len(titles) == 10): goAhead = 0 page += 1 if full_update: if approx: MOV_TOTAL = approx dialog.update(int(endIndex * 100.0 / MOV_TOTAL), getString(30122) % page, getString(30123) % new_mov) if full_update and dialog.iscanceled(): goAhead = -1 if len(titles) > 9: endIndex -= 10 if goAhead == 0: endIndex += 10 updateLibrary(cj=cj) updatePop() writeConfig("MoviesTotal", endIndex) Log('Movie Update: New %s Deleted %s Total %s' % (new_mov, deleteremoved(MOVIE_ASINS), endIndex)) if full_update: setNewest() dialog.close() updateFanart() xbmc.executebuiltin("XBMC.Container.Refresh") MovieDB.commit() return True return False
def addTVdb(full_update=True, libasins=None, cj=True): if isinstance(cj, bool): cj = MechanizeLogin() if not cj: return prime = True new_libasins = False endIndex = 0 goAhead = 1 SERIES_COUNT = 0 SEASON_COUNT = 0 EPISODE_COUNT = 0 approx = 0 retrycount = 0 if full_update and not libasins: if updateRunning(): return if not Dialog.yesno(getString(30136), getString(30137), getString(30138) % '30'): return DialogPG.create(getString(30130)) DialogPG.update(0, getString(30131)) db.createDatabase(tvDB, 'tv') ALL_SERIES_ASINS = '' ALL_SEASONS_ASINS = [] else: cleanDB() ALL_SEASONS_ASINS = getTVdbAsins('seasons', retlist=True, value='asin,episodetotal') ALL_SERIES_ASINS = getTVdbAsins('shows') if libasins: prime = False ALL_SEASONS_ASINS = [] new_libasins = checkLibraryAsins(libasins, cj) if not new_libasins: return else: while not approx: jsondata = appfeed.getList('TVEpisode&RollUpToSeason=T', randint(1, 20), NumberOfResults=1) approx = jsondata['message']['body'].get('approximateSize', 0) xbmc.sleep(randint(500, 1000)) while goAhead == 1: jsondata = appfeed.getList('TVEpisode&RollUpToSeason=T', endIndex, isPrime=prime, OrderBy='Title', NumberOfResults=MAX, AsinList=new_libasins) if not jsondata: goAhead = -1 break titles = jsondata['message']['body']['titles'] endI = jsondata['message']['body']['endIndex'] if endI: endIndex = endI else: endIndex += len(titles) del jsondata if titles: SERIES_ASINS = '' EPISODE_ASINS = [] EPISODE_NUM = [] for title in titles: if full_update and DialogPG.iscanceled(): goAhead = -1 break SEASONS_ASIN = title['titleId'] if var.onlyGer and not libasins and re.compile(regex_ovf).search(title['title']): Log('Season Ignored: %s' % title['title'], xbmc.LOGDEBUG) found = True else: season_size = int(title['childTitles'][0]['size']) found, ALL_SEASONS_ASINS = compasin(ALL_SEASONS_ASINS, SEASONS_ASIN, season_size) if not found: if ASIN_ADD([title]): SEASON_COUNT += 1 if title['ancestorTitles']: SERIES_KEY = title['ancestorTitles'][0]['titleId'] else: SERIES_KEY = title['titleId'] if SERIES_KEY not in ALL_SERIES_ASINS and 'bbl test' not in title['title'].lower(): SERIES_COUNT += 1 SERIES_ASINS += SERIES_KEY + ',' ALL_SERIES_ASINS += SERIES_KEY + ',' if season_size < 1: season_size = MAX parsed = urlparse.urlparse(title['childTitles'][0]['feedUrl']) EPISODE_ASINS.append(urlparse.parse_qs(parsed.query)['SeasonASIN']) EPISODE_NUM.append(season_size) if (approx and endIndex + 1 >= approx) or (not approx and len(titles) < 1): goAhead = 0 del titles if SERIES_ASINS: ASIN_ADD(0, asins=SERIES_ASINS) if full_update: DialogPG.update(int(SEASON_COUNT * 100.0 / approx), getString(30132) % SERIES_COUNT, getString(30133) % SEASON_COUNT, getString(30134) % EPISODE_COUNT) episodes = 0 AsinList = '' EPISODE_NUM.append(MAX + 1) for index, item in enumerate(EPISODE_ASINS): episodes += EPISODE_NUM[index] AsinList += ','.join(item) + ',' if (episodes + EPISODE_NUM[index + 1]) > MAX: jsondata = appfeed.getList('TVEpisode', 0, isPrime=prime, NumberOfResults=MAX, AsinList=AsinList) titles = jsondata['message']['body']['titles'] if titles: EPISODE_COUNT += ASIN_ADD(titles) if full_update and DialogPG.iscanceled(): goAhead = -1 break episodes = 0 AsinList = '' if full_update: DialogPG.update(int(SEASON_COUNT * 100.0 / approx), getString(30132) % SERIES_COUNT, getString(30133) % SEASON_COUNT, getString(30134) % EPISODE_COUNT) del titles else: retrycount += 1 if (approx and endIndex + 1 >= approx) or (not approx): goAhead = 0 if retrycount > 3: Log('Waiting 5min') sleep(300) appfeed.getList('TVEpisode&RollUpToSeason=T', endIndex-randint(1, MAX-1), isPrime=prime, NumberOfResults=randint(1, 10), AsinList=new_libasins) retrycount = 0 if goAhead == 0: if not libasins: updatePop() delShows, delSeasons, delEpisodes = deleteremoved(getcompresult(ALL_SEASONS_ASINS)) UpdateDialog(SERIES_COUNT, SEASON_COUNT, EPISODE_COUNT, delShows, delSeasons, delEpisodes) addTVdb(False, 'full', cj) fixDBLShows() fixYears() fixStars() fixHDshows() updateEpisodes() fixTitles() if full_update: setNewest() DialogPG.close() updateFanart() tvDB.commit() return True return False