def play_source(self, title, year, season, episode, imdb, tmdb, tvdb, url, meta, debridPackCall=False): try: from sys import argv # some functions like ActivateWindow() throw invalid handle less this is imported here. if not url: raise Exception self.media_type = 'movie' if season is None or episode is None else 'episode' self.title, self.year = title, str(year) if self.media_type == 'movie': self.name, self.season, self.episode = '%s (%s)' % (title, self.year), None, None elif self.media_type == 'episode': self.name, self.season, self.episode = '%s S%02dE%02d' % (title, int(season), int(episode)), '%01d' % int(season), '%01d' % int(episode) self.imdb, self.tmdb, self.tvdb = imdb or '', tmdb or '', tvdb or '' self.ids = {'imdb': self.imdb, 'tmdb': self.tmdb, 'tvdb': self.tvdb} ## - compare meta received to database and use largest(eventually switch to a request to fetch missing db meta for item) self.imdb_user = control.setting('imdb.user').replace('ur', '') self.tmdb_key = control.setting('tmdb.api.key') if not self.tmdb_key: self.tmdb_key = '3320855e65a9758297fec4f7c9717698' self.tvdb_key = control.setting('tvdb.api.key') if self.media_type == 'episode': self.user = str(self.imdb_user) + str(self.tvdb_key) else: self.user = str(self.tmdb_key) self.lang = control.apiLanguage()['tvdb'] meta1 = dict((k, v) for k, v in iter(meta.items()) if v is not None and v != '') if meta else None meta2 = metacache.fetch([{'imdb': self.imdb, 'tmdb': self.tmdb, 'tvdb': self.tvdb}], self.lang, self.user)[0] if meta2 != self.ids: meta2 = dict((k, v) for k, v in iter(meta2.items()) if v is not None and v != '') if meta1 is not None: try: if len(meta2) > len(meta1): meta2.update(meta1) meta = meta2 else: meta = meta1 except: log_utils.error() else: meta = meta2 if meta2 != self.ids else meta1 ################## self.poster = meta.get('poster') if meta else '' self.fanart = meta.get('fanart') if meta else '' self.meta = meta poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = self.getMeta(meta) self.offset = Bookmarks().get(name=self.name, imdb=imdb, tmdb=tmdb, tvdb=tvdb, season=season, episode=episode, year=self.year, runtime=meta.get('duration') if meta else 0) if self.offset == '-1': log_utils.log('User requested playback cancel', level=log_utils.LOGDEBUG) control.notification(message=32328) return control.cancelPlayback() item = control.item(path=url) item.setUniqueIDs(self.ids) if self.media_type == 'episode': item.setArt({'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.discart': discart, 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart}) else: item.setArt({'clearart': clearart, 'clearlogo': clearlogo, 'discart': discart, 'thumb': thumb, 'poster': poster, 'fanart': fanart}) if 'castandart' in meta: item.setCast(meta.get('castandart', '')) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.setProperty('IsPlayable', 'true') if debridPackCall: control.player.play(url, item) # seems this is only way browseDebrid pack files will play and have meta marked as watched else: control.resolve(int(argv[1]), True, item) homeWindow.setProperty('script.trakt.ids', jsdumps(self.ids)) self.keepAlive() homeWindow.clearProperty('script.trakt.ids') except: log_utils.error() return control.cancelPlayback()
def play(self, url): try: control.execute('ActivateWindow(busydialog)') control.execute('Dialog.Close(busydialog)') meta = {} for i in [ 'title', 'originaltitle', 'tvshowtitle', 'year', 'season', 'episode', 'genre', 'rating', 'votes', 'director', 'writer', 'plot', 'tagline' ]: try: meta[i] = control.infoLabel('listitem.%s' % i) except: pass meta = dict((k, v) for k, v in meta.iteritems() if not v == '') if 'title' not in meta: meta['title'] = control.infoLabel('listitem.label') icon = control.infoLabel('listitem.icon') self.name = meta['title'] self.year = meta['year'] if 'year' in meta else '0' item = control.item(path=url, iconImage=icon, thumbnailImage=icon) item.setInfo(type='Video', infoLabels=control.metadataClean(meta)) control.player.play(url, item) except: return
def playlistAdd(name, url, meta, art): # if not name is None: name.encode('utf-8') labelPosition = position(label=name) if labelPosition >= 0: return control.notification( title=35522, message='Title already in playlist', icon='default', sound=(control.setting('notification.sound') == 'true')) if isinstance(meta, basestring): meta = json.loads(meta) if isinstance(art, basestring): art = json.loads(art) item = control.item(label=name) item.setArt(art) item.setProperty('IsPlayable', 'true') item.setInfo(type='video', infoLabels=control.metadataClean(meta)) video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) cm = [] item.addContextMenuItems(cm) playlist().add(url=url, listitem=item) if notification: control.notification( title=35522, message=str(name) + ' Added to playlist', icon='default', sound=(control.setting('notification.sound') == 'true'))
def run(self, title, year, season, episode, imdb, tvdb, url, meta): try: control.sleep(200) self.totalTime = 0 self.currentTime = 0 self.content = 'movie' if season == None or episode == None else 'episode' self.title = title self.year = year self.name = urllib.quote_plus(title) + urllib.quote_plus( ' (%s)' % year) if self.content == 'movie' else urllib.quote_plus( title) + urllib.quote_plus(' S%01dE%01d' % (int(season), int(episode))) self.name = urllib.unquote_plus(self.name) self.season = '%01d' % int( season) if self.content == 'episode' else None self.episode = '%01d' % int( episode) if self.content == 'episode' else None self.DBID = None self.imdb = imdb if not imdb == None else '0' self.tvdb = tvdb if not tvdb == None else '0' self.ids = {'imdb': self.imdb, 'tvdb': self.tvdb} self.ids = dict( (k, v) for k, v in self.ids.iteritems() if not v == '0') self.offset = bookmarks().get(self.name, season, episode, imdb, self.year) poster, thumb, meta = self.getMeta(meta) item = control.item(path=url) item.setArt({ 'icon': thumb, 'thumb': thumb, 'poster': poster, 'tvshow.poster': poster, 'season.poster': poster }) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) if 'plugin' in control.infoLabel('Container.PluginName'): control.player.play(url, item) control.resolve(int(sys.argv[1]), True, item) control.window.setProperty('script.trakt.ids', json.dumps(self.ids)) self.keepPlaybackAlive() control.window.clearProperty('script.trakt.ids') except: return
def playlistAdd(name, url, meta, art): labelPosition = position(label=name) if labelPosition >= 0: return control.notification(title=35522, message=32120) if isinstance(meta, py_tools.string_types): meta = jsloads(meta) if isinstance(art, py_tools.string_types): art = jsloads(art) try: item = control.item(label=name, offscreen=True) except: item = control.item(label=name) item.setArt(art) item.setProperty('IsPlayable', 'true') item.setInfo(type='video', infoLabels=control.metadataClean(meta)) cm = [] item.addContextMenuItems(cm) playlist().add(url=url, listitem=item) if notification: control.notification(title=35522, message=control.lang(32121) % str(name))
def playlistAdd(name, url, meta, art): labelPosition = position(label=name) if labelPosition >= 0: return control.notification(title=35522, message=32120) # if isinstance(meta, basestring): if isinstance(meta, py_tools.string_types): meta = jsloads(meta) # if isinstance(art, basestring): if isinstance(art, py_tools.string_types): art = jsloads(art) item = control.item(label=name) item.setArt(art) item.setProperty('IsPlayable', 'true') item.setInfo(type='video', infoLabels=control.metadataClean(meta)) video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) cm = [] item.addContextMenuItems(cm) playlist().add(url=url, listitem=item) if notification: control.notification(title=35522, message=control.lang(32121) % str(name))
def seasonDirectory(self, items): if items is None or len(items) == 0: control.hide() control.notification(title = 32054, message = 33049, icon = 'INFO', sound=notificationSound) sys.exit() settingFanart = control.setting('fanart') addonPoster = control.addonPoster() addonFanart = control.addonFanart() addonBanner = control.addonBanner() try: indicators = playcount.getSeasonIndicators(items[0]['imdb']) except : pass unwatchedEnabled = control.setting('tvshows.unwatched.enabled') unwatchedLimit = False seasoncountEnabled = control.setting('tvshows.seasoncount.enabled') if trakt.getTraktIndicatorsInfo() is True: watchedMenu = control.lang(32068).encode('utf-8') unwatchedMenu = control.lang(32069).encode('utf-8') else: watchedMenu = control.lang(32066).encode('utf-8') unwatchedMenu = control.lang(32067).encode('utf-8') traktManagerMenu = control.lang(32070).encode('utf-8') # playlistManagerMenu = control.lang(35522).encode('utf-8') queueMenu = control.lang(32065).encode('utf-8') showPlaylistMenu = control.lang(35517).encode('utf-8') clearPlaylistMenu = control.lang(35516).encode('utf-8') labelMenu = control.lang(32055).encode('utf-8') playRandom = control.lang(32535).encode('utf-8') addToLibrary = control.lang(32551).encode('utf-8') try: multi = [i['tvshowtitle'] for i in items] except: multi = [] multi = len([x for y,x in enumerate(multi) if x not in multi[:y]]) multi = True if multi > 1 else False for i in items: try: imdb, tmdb, tvdb, year, season = i.get('imdb', '0'), i.get('tmdb', '0'), i.get('tvdb', '0'), i.get('year', '0'), i['season'] title = i['tvshowtitle'] label = '%s %s' % (labelMenu, i['season']) if self.season_special is False and control.setting('tv.specials') == 'true': self.season_special = True if int(season) == 0 else False try: if i['unaired'] == 'true': label = '[COLOR %s][I]%s[/I][/COLOR]' % (self.unairedcolor, label) except: pass systitle = urllib.quote_plus(title) meta = dict((k, v) for k, v in i.iteritems() if v != '0') meta.update({'code': imdb, 'imdbnumber': imdb}) meta.update({'mediatype': 'tvshow'}) meta.update({'tag': [imdb, tvdb]}) # Some descriptions have a link at the end that. Remove it. try: plot = meta['plot'] index = plot.rfind('See full summary') if index >= 0: plot = plot[:index] plot = plot.strip() if re.match('[a-zA-Z\d]$', plot): plot += ' ...' meta['plot'] = plot except: pass try: meta.update({'duration': str(int(meta['duration']) * 60)}) except: pass try: meta.update({'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass try: meta.update({'tvshowtitle': i['label']}) except: pass try: # Year is the shows year, not the seasons year. Extract the correct year frpm the premier date. yearNew = i['premiered'] yearNew = re.findall('(\d{4})', yearNew)[0] yearNew = yearNew.encode('utf-8') meta.update({'year': yearNew}) except: pass # First check thumbs, since they typically contains the seasons poster. The normal poster contains the show poster. poster1 = meta.get('poster') poster2 = meta.get('poster2') poster3 = meta.get('poster3') poster4 = meta.get('thumb') poster = poster4 or poster3 or poster2 or poster1 or addonPoster fanart = '' if settingFanart: fanart1 = meta.get('fanart') fanart2 = meta.get('fanart2') fanart3 = meta.get('fanart3') fanart = fanart3 or fanart2 or fanart1 or addonFanart # landscape = meta.get('landscape') thumb = meta.get('thumb') or poster icon = meta.get('icon') or poster banner1 = meta.get('banner') banner2 = meta.get('banner2') banner3 = meta.get('banner3') banner = banner3 or banner2 or banner1 or addonBanner clearlogo = meta.get('clearlogo') clearart = meta.get('clearart') art = {} art.update({'poster': poster, 'tvshow.poster': poster, 'season.poster': poster, 'fanart': fanart, 'icon': icon, 'thumb': thumb, 'banner': banner, 'clearlogo': clearlogo, 'clearart': clearart}) ####-Context Menu and Overlays-#### cm = [] if self.traktCredentials is True: cm.append((traktManagerMenu, 'RunPlugin(%s?action=traktManager&name=%s&imdb=%s&tvdb=%s&season=%s)' % (sysaddon, systitle, imdb, tvdb, season))) try: overlay = int(playcount.getSeasonOverlay(indicators, imdb, tvdb, season)) watched = overlay == 7 if watched: meta.update({'playcount': 1, 'overlay': 7}) cm.append((unwatchedMenu, 'RunPlugin(%s?action=tvPlaycount&name=%s&imdb=%s&tvdb=%s&season=%s&query=6)' % (sysaddon, systitle, imdb, tvdb, season))) else: meta.update({'playcount': 0, 'overlay': 6}) cm.append((watchedMenu, 'RunPlugin(%s?action=tvPlaycount&name=%s&imdb=%s&tvdb=%s&season=%s&query=7)' % (sysaddon, systitle, imdb, tvdb, season))) except: pass # sysmeta = urllib.quote_plus(json.dumps(meta)) # sysart = urllib.quote_plus(json.dumps(art)) url = '%s?action=episodes&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&season=%s' % (sysaddon, systitle, year, imdb, tmdb, tvdb, season) # sysurl = urllib.quote_plus(url) cm.append((playRandom, 'RunPlugin(%s?action=random&rtype=episode&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s&season=%s)' % ( sysaddon, systitle, year, imdb, tvdb, season))) # cm.append((playlistManagerMenu, 'RunPlugin(%s?action=playlistManager&name=%s&url=%s&meta=%s&art=%s)' % (sysaddon, systitle, sysurl, sysmeta, sysart))) cm.append((queueMenu, 'RunPlugin(%s?action=queueItem&name=%s)' % (sysaddon, systitle))) cm.append((showPlaylistMenu, 'RunPlugin(%s?action=showPlaylist)' % sysaddon)) cm.append((clearPlaylistMenu, 'RunPlugin(%s?action=clearPlaylist)' % sysaddon)) if control.setting('library.service.update') == 'true': cm.append((addToLibrary, 'RunPlugin(%s?action=tvshowToLibrary&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s)' % (sysaddon, systitle, year, imdb, tmdb, tvdb))) cm.append((control.lang(32610).encode('utf-8'), 'RunPlugin(%s?action=clearAllCache&opensettings=false)' % sysaddon)) cm.append(('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=openSettings)' % sysaddon)) #################################### if not i.get('trailer'): meta.update({'trailer': '%s?action=trailer&type=%s&name=%s&year=%s&imdb=%s' % (sysaddon, 'show', urllib.quote_plus(title), year, imdb)}) item = control.item(label = label) if 'castandart' in i: item.setCast(i['castandart']) if 'episodeIDS' in i: item.setUniqueIDs(i['episodeIDS']) if unwatchedEnabled == 'true': count = playcount.getSeasonCount(imdb, season, self.season_special, unwatchedLimit) if count: item.setProperty('TotalEpisodes', str(count['total'])) item.setProperty('WatchedEpisodes', str(count['watched'])) item.setProperty('UnWatchedEpisodes', str(count['unwatched'])) if seasoncountEnabled == 'true' and self.traktCredentials is True: total_seasons = trakt.getSeasons(imdb, full=False) if total_seasons is not None: total_seasons = [i['number'] for i in total_seasons] season_special = True if 0 in total_seasons else False total_seasons = len(total_seasons) if control.setting('tv.specials') == 'false' and season_special is True: total_seasons = total_seasons - 1 item.setProperty('TotalSeasons', str(total_seasons)) item.setArt(art) item.setProperty('IsPlayable', 'false') if is_widget: item.setProperty('isVenom_widget', 'true') item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.addContextMenuItems(cm) video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: log_utils.error() pass try: control.property(syshandle, 'showplot', items[0]['plot']) except: pass control.content(syshandle, 'seasons') control.directory(syshandle, cacheToDisc=True) views.setView('seasons', {'skin.estuary': 55, 'skin.confluence': 500})
def tvshowDirectory(self, items, next=True): control.playlist.clear() if not items: # with reuselanguageinvoker on an empty directory must be loaded, do not use sys.exit() control.hide() ; control.notification(title=32002, message=33049) sysaddon, syshandle = argv[0], int(argv[1]) is_widget = 'plugin' not in control.infoLabel('Container.PluginName') settingFanart = control.setting('fanart') == 'true' addonPoster, addonFanart, addonBanner = control.addonPoster(), control.addonFanart(), control.addonBanner() indicators = getTVShowIndicators(refresh=True) unwatchedEnabled = control.setting('tvshows.unwatched.enabled') == 'true' flatten = control.setting('flatten.tvshows') == 'true' if trakt.getTraktIndicatorsInfo(): watchedMenu, unwatchedMenu = control.lang(32068), control.lang(32069) else: watchedMenu, unwatchedMenu = control.lang(32066), control.lang(32067) traktManagerMenu, queueMenu = control.lang(32070), control.lang(32065) showPlaylistMenu, clearPlaylistMenu = control.lang(35517), control.lang(35516) playRandom, addToLibrary = control.lang(32535), control.lang(32551) nextMenu = control.lang(32053) for i in items: try: imdb, tmdb, tvdb, year, trailer = i.get('imdb', ''), i.get('tmdb', ''), i.get('tvdb', ''), i.get('year', ''), i.get('trailer', '') title = i.get('tvshowtitle') or i.get('title') systitle = quote_plus(title) meta = dict((k, v) for k, v in iter(i.items()) if v is not None and v != '') meta.update({'code': imdb, 'imdbnumber': imdb, 'mediatype': 'tvshow', 'tag': [imdb, tmdb]}) # "tag" and "tagline" for movies only, but works in my skin mod so leave if unwatchedEnabled: trakt.seasonCount(imdb) # pre-cache season counts for the listed shows try: meta.update({'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass try: if 'tvshowtitle' not in meta: meta.update({'tvshowtitle': title}) except: pass poster = meta.get('poster3') or meta.get('poster2') or meta.get('poster') or addonPoster landscape = meta.get('landscape') fanart = '' if settingFanart: fanart = meta.get('fanart3') or meta.get('fanart2') or meta.get('fanart') or landscape or addonFanart thumb = meta.get('thumb') or poster or landscape icon = meta.get('icon') or poster banner = meta.get('banner3') or meta.get('banner2') or meta.get('banner') or addonBanner art = {} art.update({'poster': poster, 'tvshow.poster': poster, 'fanart': fanart, 'icon': icon, 'thumb': thumb, 'banner': banner, 'clearlogo': meta.get('clearlogo', ''), 'tvshow.clearlogo': meta.get('clearlogo', ''), 'clearart': meta.get('clearart', ''), 'tvshow.clearart': meta.get('clearart', ''), 'landscape': landscape}) for k in ('poster2', 'poster3', 'fanart2', 'fanart3', 'banner2', 'banner3', 'trailer'): meta.pop(k, None) meta.update({'poster': poster, 'fanart': fanart, 'banner': banner, 'thumb': thumb, 'icon': icon}) ####-Context Menu and Overlays-#### cm = [] try: overlay = int(getTVShowOverlay(indicators, imdb, tvdb)) watched = (overlay == 5) if self.traktCredentials: cm.append((traktManagerMenu, 'RunPlugin(%s?action=tools_traktManager&name=%s&imdb=%s&tvdb=%s&watched=%s)' % (sysaddon, systitle, imdb, tvdb, watched))) if watched: meta.update({'playcount': 1, 'overlay': 5}) cm.append((unwatchedMenu, 'RunPlugin(%s?action=playcount_TVShow&name=%s&imdb=%s&tvdb=%s&query=4)' % (sysaddon, systitle, imdb, tvdb))) else: meta.update({'playcount': 0, 'overlay': 4}) cm.append((watchedMenu, 'RunPlugin(%s?action=playcount_TVShow&name=%s&imdb=%s&tvdb=%s&query=5)' % (sysaddon, systitle, imdb, tvdb))) except: pass sysmeta, sysart = quote_plus(jsdumps(meta)), quote_plus(jsdumps(art)) cm.append(('Find similar', 'ActivateWindow(10025,%s?action=tvshows&url=https://api.trakt.tv/shows/%s/related,return)' % (sysaddon, imdb))) cm.append((playRandom, 'RunPlugin(%s?action=play_Random&rtype=season&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&art=%s)' % (sysaddon, systitle, year, imdb, tmdb, tvdb, sysart))) cm.append((queueMenu, 'RunPlugin(%s?action=playlist_QueueItem&name=%s)' % (sysaddon, systitle))) cm.append((showPlaylistMenu, 'RunPlugin(%s?action=playlist_Show)' % sysaddon)) cm.append((clearPlaylistMenu, 'RunPlugin(%s?action=playlist_Clear)' % sysaddon)) cm.append((addToLibrary, 'RunPlugin(%s?action=library_tvshowToLibrary&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s)' % (sysaddon, systitle, year, imdb, tmdb, tvdb))) cm.append(('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=tools_openSettings)' % sysaddon)) #################################### if flatten: url = '%s?action=episodes&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&meta=%s' % (sysaddon, systitle, year, imdb, tmdb, tvdb, sysmeta) else: url = '%s?action=seasons&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&art=%s' % (sysaddon, systitle, year, imdb, tmdb, tvdb, sysart) if trailer: meta.update({'trailer': trailer}) else: meta.update({'trailer': '%s?action=play_Trailer&type=%s&name=%s&year=%s&imdb=%s' % (sysaddon, 'show', systitle, year, imdb)}) item = control.item(label=title, offscreen=True) if 'castandart' in i: item.setCast(i['castandart']) item.setArt(art) if unwatchedEnabled: try: count = getShowCount(indicators, imdb, tvdb) # this is threaded without .join() so not all results are immediately seen if count: item.setProperties({'WatchedEpisodes': str(count['watched']), 'UnWatchedEpisodes': str(count['unwatched'])}) item.setProperties({'TotalSeasons': str(meta.get('total_seasons', '')), 'TotalEpisodes': str(count['total'])}) else: item.setProperties({'WatchedEpisodes': '0', 'UnWatchedEpisodes': str(meta.get('total_aired_episodes', ''))}) # temp use TMDb's "total_aired_episodes" for threads not finished....next load counts will update with trakt data item.setProperties({'TotalSeasons': str(meta.get('total_seasons', '')), 'TotalEpisodes': str(meta.get('total_aired_episodes', ''))}) except: pass item.setProperty('IsPlayable', 'false') item.setProperty('tmdb_id', str(tmdb)) if is_widget: item.setProperty('isVenom_widget', 'true') item.setUniqueIDs({'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb}) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.addContextMenuItems(cm) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: from resources.lib.modules import log_utils log_utils.error() if next: try: if not items: raise Exception() url = items[0]['next'] if not url: raise Exception() url_params = dict(parse_qsl(urlsplit(url).query)) if 'imdb.com' in url and 'start' in url_params: page = ' [I](%s)[/I]' % str(int(((int(url_params.get('start')) - 1) / int(self.page_limit)) + 1)) else: page = ' [I](%s)[/I]' % url_params.get('page') nextMenu = '[COLOR skyblue]' + nextMenu + page + '[/COLOR]' u = urlparse(url).netloc.lower() if u in self.imdb_link or u in self.trakt_link: url = '%s?action=tvshowPage&url=%s' % (sysaddon, quote_plus(url)) elif u in self.tmdb_link: url = '%s?action=tmdbTvshowPage&url=%s' % (sysaddon, quote_plus(url)) elif u in self.tvmaze_link: url = '%s?action=tvmazeTvshowPage&url=%s' % (sysaddon, quote_plus(url)) item = control.item(label=nextMenu, offscreen=True) icon = control.addonNext() item.setProperty('IsPlayable', 'false') item.setArt({'icon': icon, 'thumb': icon, 'poster': icon, 'banner': icon}) item.setProperty ('SpecialSort', 'bottom') control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: from resources.lib.modules import log_utils log_utils.error() control.content(syshandle, 'tvshows') control.directory(syshandle, cacheToDisc=True) # control.sleep(500) views.setView('tvshows', {'skin.estuary': 55, 'skin.confluence': 500})
def seasonDirectory(self, items): if not items: control.hide() control.notification(title=32054, message=33049) sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) is_widget = 'plugin' not in control.infoLabel('Container.PluginName') settingFanart = control.setting('fanart') addonPoster = control.addonPoster() addonFanart = control.addonFanart() addonBanner = control.addonBanner() try: indicators = playcount.getSeasonIndicators(items[0]['imdb'], refresh=True) except: indicators = None unwatchedEnabled = control.setting( 'tvshows.unwatched.enabled') == 'true' if trakt.getTraktIndicatorsInfo(): watchedMenu = control.lang(32068) unwatchedMenu = control.lang(32069) else: watchedMenu = control.lang(32066) unwatchedMenu = control.lang(32067) traktManagerMenu = control.lang(32070) queueMenu = control.lang(32065) showPlaylistMenu = control.lang(35517) clearPlaylistMenu = control.lang(35516) labelMenu = control.lang(32055) playRandom = control.lang(32535) addToLibrary = control.lang(32551) try: multi = [i['tvshowtitle'] for i in items] except: multi = [] multi = len([x for y, x in enumerate(multi) if x not in multi[:y]]) multi = True if multi > 1 else False if self.disable_fanarttv != 'true': tvdb = [i['tvdb'] for i in items][0] from resources.lib.indexers import fanarttv extended_art = cache.get(fanarttv.get_tvshow_art, 168, tvdb) else: extended_art = None for i in items: try: imdb, tmdb, tvdb, year, season = i.get('imdb', '0'), i.get( 'tmdb', '0'), i.get('tvdb', '0'), i.get('year', '0'), i['season'] title = i['tvshowtitle'] label = '%s %s' % (labelMenu, i['season']) if not self.season_special and control.setting( 'tv.specials') == 'true': self.season_special = True if int(season) == 0 else False try: if i['unaired'] == 'true': label = '[COLOR %s][I]%s[/I][/COLOR]' % ( self.unairedcolor, label) except: pass systitle = quote_plus(title) meta = dict((k, v) for k, v in i.iteritems() if v != '0') meta.update({ 'code': imdb, 'imdbnumber': imdb, 'mediatype': 'tvshow', 'tag': [imdb, tvdb] }) # Some descriptions have a link at the end that. Remove it. try: plot = meta['plot'] index = plot.rfind('See full summary') if index >= 0: plot = plot[:index] plot = plot.strip() if re.match(r'[a-zA-Z\d]$', plot): plot += ' ...' meta['plot'] = plot except: pass try: meta.update({'duration': str(int(meta['duration']) * 60)}) except: pass try: meta.update( {'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass try: meta.update({'tvshowtitle': i['label']}) except: pass try: # Year is the shows year, not the seasons year. Extract the correct year from the premier date. yearNew = re.findall(r'(\d{4})', i['premiered'])[0] yearNew = yearNew.encode('utf-8') meta.update({'year': yearNew}) except: pass # First check thumbs, since they typically contains the seasons poster. The normal poster contains the show poster. poster = meta.get('thumb') or meta.get('poster3') or meta.get( 'poster2') or poster1 or addonPoster fanart = '' if settingFanart: fanart = meta.get('fanart3') or meta.get( 'fanart2') or meta.get('fanart') or addonFanart thumb = meta.get('thumb') or poster icon = meta.get('icon') or poster banner = meta.get('banner3') or meta.get( 'banner2') or meta.get('banner') or addonBanner if extended_art: clearlogo = extended_art.get('clearlogo') clearart = extended_art.get('clearart') else: clearlogo = '0' clearart = '0' art = {} art.update({ 'poster': poster, 'tvshow.poster': poster, 'season.poster': poster, 'fanart': fanart, 'icon': icon, 'thumb': thumb, 'banner': banner, 'clearlogo': clearlogo, 'clearart': clearart }) ####-Context Menu and Overlays-#### cm = [] if self.traktCredentials: cm.append(( traktManagerMenu, 'RunPlugin(%s?action=tools_traktManager&name=%s&imdb=%s&tvdb=%s&season=%s)' % (sysaddon, systitle, imdb, tvdb, season))) try: overlay = int( playcount.getSeasonOverlay(indicators, imdb, tvdb, season)) watched = overlay == 7 if watched: meta.update({'playcount': 1, 'overlay': 7}) cm.append(( unwatchedMenu, 'RunPlugin(%s?action=playcount_TVShow&name=%s&imdb=%s&tvdb=%s&season=%s&query=6)' % (sysaddon, systitle, imdb, tvdb, season))) else: meta.update({'playcount': 0, 'overlay': 6}) cm.append(( watchedMenu, 'RunPlugin(%s?action=playcount_TVShow&name=%s&imdb=%s&tvdb=%s&season=%s&query=7)' % (sysaddon, systitle, imdb, tvdb, season))) except: pass url = '%s?action=episodes&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&season=%s' % ( sysaddon, systitle, year, imdb, tmdb, tvdb, season) cm.append(( playRandom, 'RunPlugin(%s?action=random&rtype=episode&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s&season=%s)' % (sysaddon, systitle, year, imdb, tvdb, season))) cm.append((queueMenu, 'RunPlugin(%s?action=playlist_QueueItem&name=%s)' % (sysaddon, systitle))) cm.append((showPlaylistMenu, 'RunPlugin(%s?action=playlist_Show)' % sysaddon)) cm.append((clearPlaylistMenu, 'RunPlugin(%s?action=playlist_Clear)' % sysaddon)) cm.append(( addToLibrary, 'RunPlugin(%s?action=library_tvshowToLibrary&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s)' % (sysaddon, systitle, year, imdb, tmdb, tvdb))) cm.append( ('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=tools_openSettings)' % sysaddon)) #################################### if not i.get('trailer'): meta.update({ 'trailer': '%s?action=trailer&type=%s&name=%s&year=%s&imdb=%s' % (sysaddon, 'show', quote_plus(title), year, imdb) }) item = control.item(label=label) if 'castandart' in i: item.setCast(i['castandart']) if 'episodeIDS' in i: item.setUniqueIDs(i['episodeIDS']) if unwatchedEnabled: count = playcount.getSeasonCount(imdb, season, self.season_special) if count: item.setProperty('TotalEpisodes', str(count['total'])) item.setProperty('WatchedEpisodes', str(count['watched'])) item.setProperty('UnWatchedEpisodes', str(count['unwatched'])) if 'total_seasons' in meta: item.setProperty('TotalSeasons', str(meta.get('total_seasons'))) item.setArt(art) item.setProperty('IsPlayable', 'false') if is_widget: item.setProperty('isVenom_widget', 'true') item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.addContextMenuItems(cm) video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: log_utils.error() try: control.property(syshandle, 'showplot', items[0]['plot']) except: pass control.content(syshandle, 'seasons') control.directory(syshandle, cacheToDisc=True) views.setView('seasons', {'skin.estuary': 55, 'skin.confluence': 500})
def seasonDirectory(self, items): if not items: # with reuselanguageinvoker on an empty directory must be loaded, do not use sys.exit() control.hide() control.notification(title=32054, message=33049) sysaddon, syshandle = argv[0], int(argv[1]) is_widget = 'plugin' not in control.infoLabel('Container.PluginName') settingFanart = control.setting('fanart') == 'true' addonPoster, addonFanart, addonBanner = control.addonPoster( ), control.addonFanart(), control.addonBanner() try: indicators = playcount.getSeasonIndicators(items[0]['imdb'], refresh=True) except: indicators = None unwatchedEnabled = control.setting( 'tvshows.unwatched.enabled') == 'true' if trakt.getTraktIndicatorsInfo(): watchedMenu, unwatchedMenu = control.lang(32068), control.lang( 32069) else: watchedMenu, unwatchedMenu = control.lang(32066), control.lang( 32067) traktManagerMenu, queueMenu = control.lang(32070), control.lang(32065) showPlaylistMenu, clearPlaylistMenu = control.lang( 35517), control.lang(35516) labelMenu, playRandom = control.lang(32055), control.lang(32535) addToLibrary = control.lang(32551) try: multi = [i['tvshowtitle'] for i in items] except: multi = [] multi = True if len( [x for y, x in enumerate(multi) if x not in multi[:y]]) > 1 else False for i in items: try: imdb, tmdb, tvdb, year, season = i.get('imdb', ''), i.get( 'tmdb', ''), i.get('tvdb', ''), i.get('year', ''), i.get('season') title = i.get('tvshowtitle') label = '%s %s' % (labelMenu, i.get('season')) if not self.season_special and self.showspecials: self.season_special = True if int(season) == 0 else False try: if i['unaired'] == 'true': label = '[COLOR %s][I]%s[/I][/COLOR]' % ( self.unairedcolor, label) except: pass systitle = quote_plus(title) meta = dict((k, v) for k, v in control.iteritems(i) if v is not None and v != '') # setting mediatype to "season" causes "Infomation" and "play trailer" to not be available in some skins meta.update( { 'code': imdb, 'imdbnumber': imdb, 'mediatype': 'season', 'tag': [imdb, tmdb] } ) # "tag" and "tagline" for movies only, but works in my skin mod so leave try: meta.update( {'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass # First check thumbs, since they typically contains the seasons poster. The normal poster contains the show poster. poster = meta.get('thumb') or meta.get('poster3') or meta.get( 'poster2') or meta.get('poster') or addonPoster season_poster = meta.get('season_poster') or poster landscape = meta.get('landscape') fanart = '' if settingFanart: fanart = meta.get('fanart3') or meta.get( 'fanart2') or meta.get( 'fanart') or landscape or addonFanart thumb = season_poster icon = meta.get('icon') or poster banner = meta.get('banner3') or meta.get( 'banner2') or meta.get('banner') or addonBanner art = {} art.update({ 'poster': season_poster, 'tvshow.poster': poster, 'season.poster': season_poster, 'fanart': fanart, 'icon': icon, 'thumb': thumb, 'banner': banner, 'clearlogo': meta.get('clearlogo'), 'clearart': meta.get('clearart'), 'landscape': landscape }) for k in ('poster2', 'poster3', 'fanart2', 'fanart3', 'banner2', 'banner3'): meta.pop(k, None) meta.update({ 'poster': poster, 'fanart': fanart, 'banner': banner, 'thumb': thumb, 'icon': icon }) ####-Context Menu and Overlays-#### cm = [] if self.traktCredentials: cm.append(( traktManagerMenu, 'RunPlugin(%s?action=tools_traktManager&name=%s&imdb=%s&tvdb=%s&season=%s)' % (sysaddon, systitle, imdb, tvdb, season))) try: overlay = int( playcount.getSeasonOverlay(indicators, imdb, tvdb, season)) watched = (overlay == 5) if watched: meta.update({'playcount': 1, 'overlay': 5}) cm.append(( unwatchedMenu, 'RunPlugin(%s?action=playcount_TVShow&name=%s&imdb=%s&tvdb=%s&season=%s&query=4)' % (sysaddon, systitle, imdb, tvdb, season))) else: meta.update({'playcount': 0, 'overlay': 4}) cm.append(( watchedMenu, 'RunPlugin(%s?action=playcount_TVShow&name=%s&imdb=%s&tvdb=%s&season=%s&query=5)' % (sysaddon, systitle, imdb, tvdb, season))) except: pass sysmeta = quote_plus(jsdumps(meta)) cm.append(( playRandom, 'RunPlugin(%s?action=random&rtype=episode&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&meta=%s&season=%s)' % (sysaddon, systitle, year, imdb, tmdb, tvdb, sysmeta, season))) cm.append((queueMenu, 'RunPlugin(%s?action=playlist_QueueItem&name=%s)' % (sysaddon, systitle))) cm.append((showPlaylistMenu, 'RunPlugin(%s?action=playlist_Show)' % sysaddon)) cm.append((clearPlaylistMenu, 'RunPlugin(%s?action=playlist_Clear)' % sysaddon)) cm.append(( addToLibrary, 'RunPlugin(%s?action=library_tvshowToLibrary&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s)' % (sysaddon, systitle, year, imdb, tmdb, tvdb))) cm.append( ('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=tools_openSettings)' % sysaddon)) #################################### url = '%s?action=episodes&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&meta=%s&season=%s' % ( sysaddon, systitle, year, imdb, tmdb, tvdb, sysmeta, season) try: item = control.item(label=label, offscreen=True) except: item = control.item(label=label) if 'castandart' in i: item.setCast(i['castandart']) item.setArt(art) if unwatchedEnabled: try: count = playcount.getSeasonCount( imdb, season, self.season_special ) # self.season_special is just a flag to set if a season special exists and we are set to show it if count: item.setProperties({ 'WatchedEpisodes': str(count['watched']), 'UnWatchedEpisodes': str(count['unwatched']) }) else: item.setProperties( { 'WatchedEpisodes': '0', 'UnWatchedEpisodes': str( meta.get('counts', {}).get(str(season), '')) } ) # temp use TMDb's season-episode count for threads not finished....next load counts will update with trakt data except: pass try: item.setProperties({ 'TotalSeasons': str(meta.get('total_seasons', '')), 'TotalEpisodes': str(meta.get('total_episodes', '')) }) except: pass #da hell with 17 users if is_widget: item.setProperty('isVenom_widget', 'true') try: # Year is the shows year, not the seasons year. Extract year from premier date for InfoLabels to have "season_year". season_year = re.findall(r'(\d{4})', i.get('premiered', ''))[0] meta.update({'year': season_year}) except: pass item.setUniqueIDs({'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb}) item.setProperty('IsPlayable', 'false') item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.addContextMenuItems(cm) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: log_utils.error() try: control.property(syshandle, 'showplot', items[0]['plot']) except: pass control.content(syshandle, 'seasons') control.directory(syshandle, cacheToDisc=True) views.setView('seasons', {'skin.estuary': 55, 'skin.confluence': 500})
def play_source(self, title, year, season, episode, imdb, tvdb, url, meta, select=None): try: if url is None: control.cancelPlayback() raise Exception control.sleep(200) self.media_type = 'movie' if season is None or episode is None else 'episode' self.title = title self.year = str(year) if self.media_type == 'movie': self.name = urllib.quote_plus(title) + urllib.quote_plus( ' (%s)' % self.year) self.season = None self.episode = None elif self.media_type == 'episode': self.name = urllib.quote_plus(title) + urllib.quote_plus( ' S%02dE%02d' % (int(season), int(episode))) self.season = '%01d' % int(season) self.episode = '%01d' % int(episode) self.name = urllib.unquote_plus(self.name) self.DBID = None self.imdb = imdb if imdb is not None else '0' self.tvdb = tvdb if tvdb is not None else '0' self.ids = {'imdb': self.imdb, 'tvdb': self.tvdb} self.ids = dict( (k, v) for k, v in self.ids.iteritems() if v != '0') self.meta = meta self.offset = Bookmarks().get(self.name, self.year) poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = self.getMeta( meta) item = control.item(path=url) if self.media_type == 'episode': if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: item.setArt({ 'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.discart': discart, 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'poster': poster, 'fanart': fanart }) else: item.setArt({ 'clearart': clearart, 'clearlogo': clearlogo, 'discart': discart, 'thumb': thumb, 'poster': poster, 'fanart': fanart }) if self.media_type == 'episode': self.episodeIDS = meta.get('episodeIDS', '0') item.setUniqueIDs(self.episodeIDS) else: item.setUniqueIDs(self.ids) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) if self.media_type == 'episode': if ('plugin' not in control.infoLabel('Container.PluginName') or control.setting('enable.upnext') == 'true' or control.setting('hosts.mode') == '0') or select != '1': if control.window.getProperty('infodialogs.active'): control.closeAll() control.resolve(syshandle, True, item) elif (control.setting('enable.upnext') == 'false' and control.setting('hosts.mode') == '1') or select == '1': control.closeAll() control.player.play(url, item) elif self.media_type == 'movie': if ('plugin' not in control.infoLabel('Container.PluginName') or control.setting('hosts.mode') == '0') or select != '1': if control.window.getProperty('infodialogs.active'): control.closeAll() control.resolve(syshandle, True, item) elif control.setting('hosts.mode') == '1' or select == '1': control.closeAll() control.player.play(url, item) self.keepAlive() control.window.setProperty('script.trakt.ids', json.dumps(self.ids)) control.window.clearProperty('script.trakt.ids') except: import traceback traceback.print_exc() return control.cancelPlayback()
def play_source(self, title, year, season, episode, imdb, tvdb, url, meta, select=None): try: if url is None: control.cancelPlayback() raise Exception control.sleep(200) self.media_type = 'movie' if season is None or episode is None else 'episode' self.title = title self.year = str(year) if self.media_type == 'movie': self.name = urllib.quote_plus(title) + urllib.quote_plus( ' (%s)' % self.year) self.season = None self.episode = None elif self.media_type == 'episode': self.name = urllib.quote_plus(title) + urllib.quote_plus( ' S%02dE%02d' % (int(season), int(episode))) self.season = '%01d' % int(season) self.episode = '%01d' % int(episode) self.name = urllib.unquote_plus(self.name) self.DBID = None self.imdb = imdb if imdb is not None else '0' self.tvdb = tvdb if tvdb is not None else '0' self.ids = {'imdb': self.imdb, 'tvdb': self.tvdb} self.ids = dict( (k, v) for k, v in self.ids.iteritems() if v != '0') self.meta = meta self.offset = Bookmarks().get(self.name, self.year) poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = self.getMeta( meta) item = control.item(path=url) if self.media_type == 'episode': self.episodeIDS = meta.get('episodeIDS', '0') item.setUniqueIDs(self.episodeIDS) if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: item.setArt({ 'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.discart': discart, 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: item.setUniqueIDs(self.ids) if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'poster': poster, 'fanart': fanart }) else: item.setArt({ 'clearart': clearart, 'clearlogo': clearlogo, 'discart': discart, 'thumb': thumb, 'poster': poster, 'fanart': fanart }) # self.tvdb_key = 'N1I4U1paWDkwVUE5WU1CVQ==' # self.imdb_user = control.setting('imdb.user').replace('ur', '') # self.user = str(self.imdb_user) + str(self.tvdb_key) # self.lang = control.apiLanguage()['tvdb'] # items = [{'imdb': imdb, 'tvdb': tvdb}] # list = metacache.fetch(items, self.lang, self.user) # if 'castandart' in str(list): # item.setCast(list[0].get('castandart', '')) # test = control.infoLabel('ListItem.thumb') # log_utils.log('thumb = %s' % test, __name__, log_utils.LOGDEBUG) if 'castandart' in meta: item.setCast(meta.get('castandart', '')) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) if 'plugin' not in control.infoLabel( 'Container.PluginName') or select != '1': if control.window.getProperty('infodialogs.active'): control.closeAll() control.resolve(syshandle, True, item) elif select == '1': control.closeAll() control.player.play(url, item) self.keepAlive() control.window.setProperty('script.trakt.ids', json.dumps(self.ids)) control.window.clearProperty('script.trakt.ids') except: log_utils.error() return control.cancelPlayback()
def addItem(self, title): control.playlist.clear() items = control.window.getProperty(self.itemProperty) items = json.loads(items) if items is None or len(items) == 0: control.idle() sys.exit() meta = control.window.getProperty(self.metaProperty) meta = json.loads(meta) # (Kodi bug?) [name,role] is incredibly slow on this directory, # [name] is barely tolerable, so just nuke it for speed! if 'cast' in meta: del(meta['cast']) sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) downloads = True if control.setting('downloads') == 'true' and not ( control.setting('movie.download.path') == '' or control.setting('tv.download.path') == '') else False systitle = sysname = urllib.quote_plus(title) if 'tvshowtitle' in meta and 'season' in meta and 'episode' in meta: sysname += urllib.quote_plus(' S%02dE%02d' % (int(meta['season']), int(meta['episode']))) elif 'year' in meta: sysname += urllib.quote_plus(' (%s)' % meta['year']) poster = meta['poster3'] if 'poster3' in meta else '0' if poster == '0': poster = meta['poster'] if 'poster' in meta else '0' fanart = meta['fanart2'] if 'fanart2' in meta else '0' if fanart == '0': fanart = meta['fanart'] if 'fanart' in meta else '0' thumb = meta['thumb'] if 'thumb' in meta else '0' if thumb == '0': thumb = poster if thumb == '0': thumb = fanart banner = meta['banner'] if 'banner' in meta else '0' if banner == '0': banner = poster if poster == '0': poster = control.addonPoster() if banner == '0': banner = control.addonBanner() if not control.setting('fanart') == 'true': fanart = '0' if fanart == '0': fanart = control.addonFanart() if thumb == '0': thumb = control.addonFanart() sysimage = urllib.quote_plus(poster.encode('utf-8')) downloadMenu = control.lang(32403).encode('utf-8') for i in range(len(items)): try: label = items[i]['label'] syssource = urllib.quote_plus(json.dumps([items[i]])) sysurl = '%s?action=playItem&title=%s&source=%s' % (sysaddon, systitle, syssource) cm = [] if downloads is True: cm.append(( downloadMenu, 'RunPlugin(%s?action=download&name=%s&image=%s&source=%s)' % ( sysaddon, sysname, sysimage, syssource))) item = control.item(label=label) item.setArt({'icon': thumb, 'thumb': thumb, 'poster': poster, 'banner': banner}) item.setProperty('Fanart_Image', fanart) video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) item.addContextMenuItems(cm) item.setInfo(type='Video', infoLabels=control.metadataClean(meta)) # item.setInfo(type='Video', infoLabels = meta) # old code control.addItem(handle=syshandle, url=sysurl, listitem=item, isFolder=False) except: pass control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
def seasonDirectory(self, items): from sys import argv # some functions like ActivateWindow() throw invalid handle less this is imported here. if not items: # with reuselanguageinvoker on an empty directory must be loaded, do not use sys.exit() control.hide() control.notification(title=32054, message=33049) sysaddon, syshandle = argv[0], int(argv[1]) is_widget = 'plugin' not in control.infoLabel('Container.PluginName') settingFanart = getSetting('fanart') == 'true' addonPoster, addonFanart, addonBanner = control.addonPoster( ), control.addonFanart(), control.addonBanner() try: indicators = getSeasonIndicators( items[0]['imdb']) # refresh not needed now due to service sync except: indicators = None if trakt.getTraktIndicatorsInfo(): watchedMenu, unwatchedMenu = getLS(32068), getLS(32069) else: watchedMenu, unwatchedMenu = getLS(32066), getLS(32067) traktManagerMenu, queueMenu = getLS(32070), getLS(32065) showPlaylistMenu, clearPlaylistMenu = getLS(35517), getLS(35516) labelMenu, playRandom = getLS(32055), getLS(32535) addToLibrary = getLS(32551) try: multi = [i['tvshowtitle'] for i in items] except: multi = [] multi = True if len( [x for y, x in enumerate(multi) if x not in multi[:y]]) > 1 else False for i in items: try: title, imdb, tmdb, tvdb, year, season = i.get( 'tvshowtitle'), i.get('imdb', ''), i.get('tmdb', ''), i.get( 'tvdb', ''), i.get('year', ''), i.get('season') label = '%s %s' % (labelMenu, season) try: if i['unaired'] == 'true': label = '[COLOR %s][I]%s[/I][/COLOR]' % ( self.unairedcolor, label) except: pass systitle = quote_plus(title) meta = dict((k, v) for k, v in iter(i.items()) if v is not None and v != '') # setting mediatype to "season" causes "Infomation" and "play trailer" to not be available in some skins meta.update( { 'code': imdb, 'imdbnumber': imdb, 'mediatype': 'tvshow', 'tag': [imdb, tmdb] } ) # "tag" and "tagline" for movies only, but works in my skin mod so leave try: meta.update( {'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass poster = meta.get( 'tvshow.poster') or addonPoster # tvshow.poster if self.prefer_tmdbArt: season_poster = meta.get('season_poster') or meta.get( 'season_poster2') or poster else: season_poster = meta.get('season_poster2') or meta.get( 'season_poster') or poster fanart = '' if settingFanart: fanart = meta.get('fanart') or addonFanart icon = meta.get('icon') or poster banner = meta.get('banner') or addonBanner art = {} art.update({ 'poster': season_poster, 'tvshow.poster': poster, 'season.poster': season_poster, 'fanart': fanart, 'icon': icon, 'thumb': season_poster, 'banner': banner, 'clearlogo': meta.get('clearlogo', ''), 'tvshow.clearlogo': meta.get('clearlogo', ''), 'clearart': meta.get('clearart', ''), 'tvshow.clearart': meta.get('clearart', ''), 'landscape': meta.get('landscape') }) # for k in ('poster2', 'poster3', 'fanart2', 'fanart3', 'banner2', 'banner3'): meta.pop(k, None) meta.update({ 'poster': poster, 'fanart': fanart, 'banner': banner, 'thumb': season_poster, 'season_poster': season_poster, 'icon': icon }) ####-Context Menu and Overlays-#### cm = [] try: overlay = int( getSeasonOverlay(indicators, imdb, tvdb, season)) watched = (overlay == 5) if self.traktCredentials: cm.append(( traktManagerMenu, 'RunPlugin(%s?action=tools_traktManager&name=%s&imdb=%s&tvdb=%s&season=%s&watched=%s)' % (sysaddon, systitle, imdb, tvdb, season, watched))) if watched: meta.update({'playcount': 1, 'overlay': 5}) cm.append(( unwatchedMenu, 'RunPlugin(%s?action=playcount_TVShow&name=%s&imdb=%s&tvdb=%s&season=%s&query=4)' % (sysaddon, systitle, imdb, tvdb, season))) else: meta.update({'playcount': 0, 'overlay': 4}) cm.append(( watchedMenu, 'RunPlugin(%s?action=playcount_TVShow&name=%s&imdb=%s&tvdb=%s&season=%s&query=5)' % (sysaddon, systitle, imdb, tvdb, season))) except: pass sysmeta = quote_plus(jsdumps(meta)) cm.append(( playRandom, 'RunPlugin(%s?action=play_Random&rtype=episode&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&meta=%s&season=%s)' % (sysaddon, systitle, year, imdb, tmdb, tvdb, sysmeta, season))) cm.append((queueMenu, 'RunPlugin(%s?action=playlist_QueueItem&name=%s)' % (sysaddon, systitle))) cm.append((showPlaylistMenu, 'RunPlugin(%s?action=playlist_Show)' % sysaddon)) cm.append((clearPlaylistMenu, 'RunPlugin(%s?action=playlist_Clear)' % sysaddon)) cm.append(( addToLibrary, 'RunPlugin(%s?action=library_tvshowToLibrary&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s)' % (sysaddon, systitle, year, imdb, tmdb, tvdb))) cm.append( ('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=tools_openSettings)' % sysaddon)) #################################### url = '%s?action=episodes&tvshowtitle=%s&year=%s&imdb=%s&tmdb=%s&tvdb=%s&meta=%s&season=%s' % ( sysaddon, systitle, year, imdb, tmdb, tvdb, sysmeta, season) item = control.item(label=label, offscreen=True) if 'castandart' in i: item.setCast(i['castandart']) item.setArt(art) try: count = getSeasonCount(imdb, season) if count: item.setProperties({ 'WatchedEpisodes': str(count['watched']), 'UnWatchedEpisodes': str(count['unwatched']) }) item.setProperties({ 'TotalSeasons': str(meta.get('total_seasons', '')), 'TotalEpisodes': str(count['total']) }) else: if meta.get('status') != 'Returning Series' or ( meta.get('status') == 'Returning Series' and meta.get('last_episode_to_air', {}).get( 'season_number') > int(season)): item.setProperties({ 'WatchedEpisodes': '0', 'UnWatchedEpisodes': str( meta.get('counts', {}).get(str(season), '')) }) item.setProperties({ 'TotalSeasons': str(meta.get('total_seasons', '')), 'TotalEpisodes': str(meta.get('total_episodes', '')) }) else: if meta.get( 'last_episode_to_air', {}).get('season_number') == int(season): item.setProperties({ 'WatchedEpisodes': '0', 'UnWatchedEpisodes': str( meta.get('last_episode_to_air', {}).get('episode_number')) }) item.setProperties({ 'TotalSeasons': str(meta.get('total_seasons', '')), 'TotalEpisodes': str( meta.get('last_episode_to_air', {}).get('episode_number')) }) else: item.setProperties({ 'WatchedEpisodes': '0', 'UnWatchedEpisodes': '0' }) item.setProperties({ 'TotalSeasons': str(meta.get('total_seasons', '')), 'TotalEpisodes': '0' }) except: pass if is_widget: item.setProperty('isVenom_widget', 'true') try: # Year is the shows year, not the seasons year. Extract year from premier date for InfoLabels to have "season_year". season_year = re.findall(r'(\d{4})', i.get('premiered', ''))[0] meta.update({'year': season_year}) except: pass item.setUniqueIDs({'imdb': imdb, 'tmdb': tmdb, 'tvdb': tvdb}) item.setProperty('IsPlayable', 'false') item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.addContextMenuItems(cm) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: from resources.lib.modules import log_utils log_utils.error() try: control.property(syshandle, 'showplot', items[0]['plot']) except: pass control.content(syshandle, 'seasons') control.directory( syshandle, cacheToDisc=False ) # disable cacheToDisc so unwatched counts loads fresh data counts if changes made views.setView('seasons', {'skin.estuary': 55, 'skin.confluence': 500})
def play_source(self, title, year, season, episode, imdb, tvdb, url, meta): try: control.sleep(200) self.media_type = 'movie' if season is None or episode is None else 'episode' self.title = title self.year = str(year) if self.media_type == 'movie': self.name = urllib.quote_plus(title) + urllib.quote_plus( ' (%s)' % self.year) self.season = None self.episode = None elif self.media_type == 'episode': self.name = urllib.quote_plus(title) + urllib.quote_plus( ' S%02dE%02d' % (int(season), int(episode))) self.season = '%01d' % int(season) self.episode = '%01d' % int(episode) self.name = urllib.unquote_plus(self.name) self.DBID = None self.imdb = imdb if imdb is not None else '0' self.tvdb = tvdb if tvdb is not None else '0' self.ids = {'imdb': self.imdb, 'tvdb': self.tvdb} self.ids = dict( (k, v) for k, v in self.ids.iteritems() if not v == '0') self.meta = meta self.offset = Bookmarks().get(self.name, self.year) poster, thumb, fanart, clearart, clearlogo, discart, meta = self.getMeta( meta) item = control.item(path=url) item.setArt({ 'clearart': clearart, 'clearlogo': clearlogo, 'discart': discart, 'thumb': thumb, 'poster': poster, 'tvshow.poster': poster, 'season.poster': poster, 'fanart': fanart }) if self.media_type == 'episode': self.episodeIDS = meta.get('episodeIDS') item.setUniqueIDs(self.episodeIDS) else: item.setUniqueIDs(self.ids) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) control.player.play(url, item) xbmc.sleep(2000) control.closeAll() control.resolve(syshandle, True, item) control.window.setProperty('script.trakt.ids', json.dumps(self.ids)) self.keepAlive() control.window.clearProperty('script.trakt.ids') except: import traceback traceback.print_exc()
def play_source(self, title, year, season, episode, imdb, tvdb, url, meta, select=None): try: if url is None: control.cancelPlayback() raise Exception control.sleep(200) self.media_type = 'movie' if season is None or episode is None else 'episode' self.title = title self.year = str(year) if self.media_type == 'movie': self.name = quote_plus(title) + quote_plus(' (%s)' % self.year) self.season = None self.episode = None elif self.media_type == 'episode': self.name = quote_plus(title) + quote_plus( ' S%02dE%02d' % (int(season), int(episode))) self.season = '%01d' % int(season) self.episode = '%01d' % int(episode) self.name = unquote_plus( self.name) # this looks dumb, quote to only unquote? self.DBID = None self.imdb = imdb if imdb is not None else '0' self.tvdb = tvdb if tvdb is not None else '0' self.ids = {'imdb': self.imdb, 'tvdb': self.tvdb} self.ids = dict( (k, v) for k, v in self.ids.iteritems() if v != '0') self.meta = meta self.offset = Bookmarks().get(self.name, self.year) item = control.item(path=url) ## - compare meta received to database and use largest(eventually switch to a request to fetch missing db meta for item) self.imdb_user = control.setting('imdb.user').replace('ur', '') self.tmdb_key = control.setting('tm.user') if self.tmdb_key == '' or self.tmdb_key is None: self.tmdb_key = '3320855e65a9758297fec4f7c9717698' self.tvdb_key = 'N1I4U1paWDkwVUE5WU1CVQ==' if self.media_type == 'episode': self.user = str(self.imdb_user) + str(self.tvdb_key) else: self.user = str(self.tmdb_key) self.lang = control.apiLanguage()['tvdb'] items = [{ 'imdb': imdb, 'tvdb': tvdb }] # need to add tmdb but it's not passed as of now items_ck = copy.deepcopy(items) meta1 = meta meta2 = metacache.fetch(items, self.lang, self.user)[0] if meta1 is not None: if len(meta2) > len(meta1): meta = meta2 else: meta = meta1 else: meta = meta2 if meta2 != items_ck[0] else meta1 ################## poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = self.getMeta( meta) if self.media_type == 'episode': self.episodeIDS = meta.get('episodeIDS', '0') item.setUniqueIDs(self.episodeIDS) if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: item.setArt({ 'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.discart': discart, 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: item.setUniqueIDs(self.ids) if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'poster': poster, 'fanart': fanart }) else: item.setArt({ 'clearart': clearart, 'clearlogo': clearlogo, 'discart': discart, 'thumb': thumb, 'poster': poster, 'fanart': fanart }) if 'castandart' in meta: item.setCast(meta.get('castandart', '')) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) if 'plugin' not in control.infoLabel( 'Container.PluginName') or select != '1': if control.window.getProperty('infodialogs.active'): control.closeAll() control.resolve(syshandle, True, item) elif select == '1': control.closeAll() control.player.play(url, item) self.keepAlive() control.window.setProperty('script.trakt.ids', json.dumps(self.ids)) control.window.clearProperty('script.trakt.ids') except: log_utils.error() return control.cancelPlayback()
def movieDirectory(self, items, unfinished=False, next=True): if not items: # with reuselanguageinvoker on an empty directory must be loaded, do not use sys.exit() control.hide() ; control.notification(title=32001, message=33049) from resources.lib.modules.player import Bookmarks sysaddon, syshandle = argv[0], int(argv[1]) disable_player_art = control.setting('disable.player.art') == 'true' hosts_mode = control.setting('hosts.mode') is_widget = 'plugin' not in control.infoLabel('Container.PluginName') settingFanart = control.setting('fanart') == 'true' addonPoster, addonFanart, addonBanner = control.addonPoster(), control.addonFanart(), control.addonBanner() indicators = playcount.getMovieIndicators(refresh=True) isPlayable = 'false' if 'plugin' not in control.infoLabel('Container.PluginName'): isPlayable = 'true' elif hosts_mode != '1': isPlayable = 'true' if hosts_mode == '2': playbackMenu = control.lang(32063) else: playbackMenu = control.lang(32064) if trakt.getTraktIndicatorsInfo(): watchedMenu, unwatchedMenu = control.lang(32068), control.lang(32069) else: watchedMenu, unwatchedMenu = control.lang(32066), control.lang(32067) playlistManagerMenu, queueMenu = control.lang(35522), control.lang(32065) traktManagerMenu, addToLibrary = control.lang(32070), control.lang(32551) nextMenu, clearSourcesMenu = control.lang(32053), control.lang(32611) for i in items: try: imdb, tmdb, title, year = i.get('imdb', ''), i.get('tmdb', ''), i['title'], i.get('year', '') trailer, runtime = i.get('trailer'), i.get('duration') label = '%s (%s)' % (title, year) try: labelProgress = label + '[COLOR %s] [%s][/COLOR]' % (self.highlight_color, str(round(float(i['progress'] * 100), 1)) + '%') except: labelProgress = label try: if int(re.sub(r'[^0-9]', '', str(i['premiered']))) > int(re.sub(r'[^0-9]', '', str(self.today_date))): labelProgress = '[COLOR %s][I]%s[/I][/COLOR]' % (self.unairedcolor, labelProgress) except: pass if i.get('traktHistory') is True: try: air_time = tools.Time.convert(stringTime=i.get('lastplayed', ''), zoneFrom='utc', zoneTo='local', formatInput='%Y-%m-%dT%H:%M:%S.000Z', formatOutput='%b %d %Y %I:%M %p') if air_time[12] == '0': air_time = air_time[:12] + '' + air_time[13:] labelProgress = labelProgress + '[COLOR %s] [%s][/COLOR]' % (self.highlight_color, air_time) except: pass sysname, systitle = quote_plus(label), quote_plus(title) meta = dict((k, v) for k, v in control.iteritems(i) if v is not None and v != '') meta.update({'code': imdb, 'imdbnumber': imdb, 'mediatype': 'movie', 'tag': [imdb, tmdb]}) try: meta.update({'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass poster = meta.get('poster3') or meta.get('poster2') or meta.get('poster') or addonPoster fanart = '' if settingFanart: fanart = meta.get('fanart3') or meta.get('fanart2') or meta.get('fanart') or addonFanart landscape = meta.get('landscape') or fanart thumb = meta.get('thumb') or poster or landscape icon = meta.get('icon') or poster banner = meta.get('banner3') or meta.get('banner2') or meta.get('banner') or addonBanner art = {} if disable_player_art and hosts_mode == '2': # setResolvedUrl uses the selected ListItem so pop keys out here if user wants no player art for k in ('clearart', 'clearlogo', 'discart'): meta.pop(k, None) art.update({'icon': icon, 'thumb': thumb, 'banner': banner, 'poster': poster, 'fanart': fanart, 'landscape': landscape, 'clearlogo': meta.get('clearlogo', ''), 'clearart': meta.get('clearart', ''), 'discart': meta.get('discart', ''), 'keyart': meta.get('keyart', '')}) for k in ('poster2', 'poster3', 'fanart2', 'fanart3', 'banner2', 'banner3', 'trailer'): meta.pop(k, None) meta.update({'poster': poster, 'fanart': fanart, 'banner': banner}) ####-Context Menu and Overlays-#### cm = [] if self.traktCredentials: cm.append((traktManagerMenu, 'RunPlugin(%s?action=tools_traktManager&name=%s&imdb=%s)' % (sysaddon, sysname, imdb))) try: overlay = int(playcount.getMovieOverlay(indicators, imdb)) watched = (overlay == 5) if watched: cm.append((unwatchedMenu, 'RunPlugin(%s?action=playcount_Movie&name=%s&imdb=%s&query=4)' % (sysaddon, sysname, imdb))) meta.update({'playcount': 1, 'overlay': 5}) # lastplayed = trakt.watchedMoviesTime(imdb) # meta.update({'lastplayed': lastplayed}) else: cm.append((watchedMenu, 'RunPlugin(%s?action=playcount_Movie&name=%s&imdb=%s&query=5)' % (sysaddon, sysname, imdb))) meta.update({'playcount': 0, 'overlay': 4}) except: pass sysmeta, sysart = quote_plus(jsdumps(meta)), quote_plus(jsdumps(art)) url = '%s?action=play&title=%s&year=%s&imdb=%s&tmdb=%s&meta=%s' % (sysaddon, systitle, year, imdb, tmdb, sysmeta) sysurl = quote_plus(url) cm.append((playlistManagerMenu, 'RunPlugin(%s?action=playlist_Manager&name=%s&url=%s&meta=%s&art=%s)' % (sysaddon, sysname, sysurl, sysmeta, sysart))) cm.append((queueMenu, 'RunPlugin(%s?action=playlist_QueueItem&name=%s)' % (sysaddon, sysname))) cm.append((playbackMenu, 'RunPlugin(%s?action=alterSources&url=%s&meta=%s)' % (sysaddon, sysurl, sysmeta))) if hosts_mode == '1': cm.append(('Rescrape Item', 'RunPlugin(%s?action=play&title=%s&year=%s&imdb=%s&tmdb=%s&meta=%s&rescrape=true)' % (sysaddon, systitle, year, imdb, tmdb, sysmeta))) elif hosts_mode != '1': cm.append(('Rescrape Item', 'PlayMedia(%s?action=play&title=%s&year=%s&imdb=%s&tmdb=%s&meta=%s&rescrape=true)' % (sysaddon, systitle, year, imdb, tmdb, sysmeta))) cm.append((addToLibrary, 'RunPlugin(%s?action=library_movieToLibrary&name=%s&title=%s&year=%s&imdb=%s&tmdb=%s)' % (sysaddon, sysname, systitle, year, imdb, tmdb))) cm.append(('Find similar', 'ActivateWindow(10025,%s?action=movies&url=https://api.trakt.tv/movies/%s/related,return)' % (sysaddon, imdb))) cm.append((clearSourcesMenu, 'RunPlugin(%s?action=cache_clearSources)' % sysaddon)) cm.append(('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=tools_openSettings)' % sysaddon)) #################################### if trailer: meta.update({'trailer': trailer}) else: meta.update({'trailer': '%s?action=trailer&type=%s&name=%s&year=%s&imdb=%s' % (sysaddon, 'movie', sysname, year, imdb)}) item = control.item(label=labelProgress, offscreen=True) if 'castandart' in i: item.setCast(i['castandart']) item.setArt(art) item.setUniqueIDs({'imdb': imdb, 'tmdb': tmdb}) item.setProperty('IsPlayable', isPlayable) if is_widget: item.setProperty('isVenom_widget', 'true') resumetime = Bookmarks().get(name=label, imdb=imdb, tmdb=tmdb, year=str(year), runtime=runtime, ck=True) # item.setProperty('TotalTime', str(meta['duration'])) # Adding this property causes the Kodi bookmark CM items to be added item.setProperty('ResumeTime', str(resumetime)) try: watched_percent = round(float(resumetime) / float(runtime) * 100, 1) # resumetime and runtime are both in seconds item.setProperty('PercentPlayed', str(watched_percent)) except: pass item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.addContextMenuItems(cm) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) except: log_utils.error() if next: try: if not items: raise Exception() url = items[0]['next'] if not url: raise Exception() url_params = dict(parse_qsl(urlsplit(url).query)) if 'imdb.com' in url and 'start' in url_params: page = ' [I](%s)[/I]' % str(int(((int(url_params.get('start')) - 1) / int(self.count)) + 1)) else: page = ' [I](%s)[/I]' % url_params.get('page') nextMenu = '[COLOR skyblue]' + nextMenu + page + '[/COLOR]' u = urlparse(url).netloc.lower() if u not in self.tmdb_link: url = '%s?action=moviePage&url=%s' % (sysaddon, quote_plus(url)) elif u in self.tmdb_link: url = '%s?action=tmdbmoviePage&url=%s' % (sysaddon, quote_plus(url)) item = control.item(label=nextMenu, offscreen=True) icon = control.addonNext() item.setProperty('IsPlayable', 'false') item.setArt({'icon': icon, 'thumb': icon, 'poster': icon, 'banner': icon}) item.setProperty ('SpecialSort', 'bottom') control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: log_utils.error() control.content(syshandle, 'movies') control.directory(syshandle, cacheToDisc=True) control.sleep(500) views.setView('movies', {'skin.estuary': 55, 'skin.confluence': 500})
def channelDirectory(self, items): if items == None or len(items) == 0: return #control.idle() ; sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) addonPoster, addonBanner = control.addonPoster(), control.addonBanner() addonFanart = control.addonFanart() traktCredentials = trakt.getTraktCredentialsInfo() kodiVersion = control.getKodiVersion() isPlayable = True if not 'plugin' in control.infoLabel('Container.PluginName') else False indicators = playcount.getMovieIndicators(refresh=True) if action == 'movies' else playcount.getMovieIndicators() if self.trailer_source == '0': trailerAction = 'tmdb_trailer' elif self.trailer_source == '1': trailerAction = 'yt_trailer' else: trailerAction = 'imdb_trailer' playbackMenu = control.lang(32063) if control.setting('hosts.mode') == '2' else control.lang(32064) watchedMenu = control.lang(32068) if trakt.getTraktIndicatorsInfo() == True else control.lang(32066) unwatchedMenu = control.lang(32069) if trakt.getTraktIndicatorsInfo() == True else control.lang(32067) queueMenu = control.lang(32065) traktManagerMenu = control.lang(32070) nextMenu = control.lang(32053) addToLibrary = control.lang(32551) clearProviders = control.lang(32081) findSimilar = control.lang(32100) infoMenu = control.lang(32101) for i in items: try: imdb, tmdb, title, year = i['imdb'], i['tmdb'], i['originaltitle'], i['year'] label = i['label'] if 'label' in i and not i['label'] == '0' else title label = '%s (%s)' % (label, year) if 'channel' in i: label = '[B]%s[/B] : %s' % (i['channel'].upper(), label) status = i['status'] if 'status' in i else '0' sysname = urllib_parse.quote_plus('%s (%s)' % (title, year)) systitle = urllib_parse.quote_plus(title) meta = dict((k,v) for k, v in six.iteritems(i) if not v == '0') meta.update({'imdbnumber': imdb, 'code': tmdb}) meta.update({'mediatype': 'movie'}) meta.update({'trailer': '%s?action=%s&name=%s&tmdb=%s&imdb=%s' % (sysaddon, trailerAction, systitle, tmdb, imdb)}) if not 'duration' in i: meta.update({'duration': '120'}) elif i['duration'] == '0': meta.update({'duration': '120'}) try: meta.update({'duration': str(int(meta['duration']) * 60)}) except: pass try: meta.update({'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass if 'castwiththumb' in i and not i['castwiththumb'] == '0': meta.pop('cast', '0') poster = i['poster'] if 'poster' in i and not i['poster'] == '0' else addonPoster meta.update({'poster': poster}) sysmeta = urllib_parse.quote_plus(json.dumps(meta)) url = '%s?action=play&title=%s&year=%s&imdb=%s&meta=%s&t=%s' % (sysaddon, systitle, year, imdb, sysmeta, self.systime) sysurl = urllib_parse.quote_plus(url) #path = '%s?action=play&title=%s&year=%s&imdb=%s' % (sysaddon, systitle, year, imdb) cm = [] cm.append((findSimilar, 'Container.Update(%s?action=movies&url=%s)' % (sysaddon, urllib_parse.quote_plus(self.related_link % tmdb)))) cm.append(('[I]Cast[/I]', 'RunPlugin(%s?action=moviecredits&tmdb=%s&status=%s)' % (sysaddon, tmdb, status))) cm.append((queueMenu, 'RunPlugin(%s?action=queueItem)' % sysaddon)) try: overlay = int(playcount.getMovieOverlay(indicators, imdb)) if overlay == 7: cm.append((unwatchedMenu, 'RunPlugin(%s?action=moviePlaycount&imdb=%s&query=6)' % (sysaddon, imdb))) meta.update({'playcount': 1, 'overlay': 7}) else: cm.append((watchedMenu, 'RunPlugin(%s?action=moviePlaycount&imdb=%s&query=7)' % (sysaddon, imdb))) meta.update({'playcount': 0, 'overlay': 6}) except: pass if traktCredentials == True: cm.append((traktManagerMenu, 'RunPlugin(%s?action=traktManager&name=%s&imdb=%s&content=movie)' % (sysaddon, sysname, imdb))) cm.append((playbackMenu, 'RunPlugin(%s?action=alterSources&url=%s&meta=%s)' % (sysaddon, sysurl, sysmeta))) if kodiVersion < 17: cm.append((infoMenu, 'Action(Info)')) cm.append((addToLibrary, 'RunPlugin(%s?action=movieToLibrary&name=%s&title=%s&year=%s&imdb=%s&tmdb=%s)' % (sysaddon, sysname, systitle, year, imdb, tmdb))) cm.append(('[I]Scrape Filterless[/I]', 'RunPlugin(%s?action=playUnfiltered&title=%s&year=%s&imdb=%s&meta=%s&t=%s)' % (sysaddon, systitle, year, imdb, sysmeta, self.systime))) cm.append((clearProviders, 'RunPlugin(%s?action=clearCacheProviders)' % sysaddon)) try: item = control.item(label=label, offscreen=True) except: item = control.item(label=label) art = {} art.update({'icon': poster, 'thumb': poster, 'poster': poster}) fanart = i['fanart'] if 'fanart' in i and not i['fanart'] == '0' else addonFanart if self.settingFanart == 'true': art.update({'fanart': fanart}) else: art.update({'fanart': addonFanart}) if 'banner' in i and not i['banner'] == '0': art.update({'banner': i['banner']}) else: art.update({'banner': addonBanner}) if 'clearlogo' in i and not i['clearlogo'] == '0': art.update({'clearlogo': i['clearlogo']}) if 'clearart' in i and not i['clearart'] == '0': art.update({'clearart': i['clearart']}) if 'landscape' in i and not i['landscape'] == '0': landscape = i['landscape'] else: landscape = fanart art.update({'landscape': landscape}) if 'discart' in i and not i['discart'] == '0': art.update({'discart': i['discart']}) item.setArt(art) item.addContextMenuItems(cm) if isPlayable: item.setProperty('IsPlayable', 'true') castwiththumb = i.get('castwiththumb') if castwiththumb and not castwiththumb == '0': if kodiVersion >= 18: item.setCast(castwiththumb) else: cast = [(p['name'], p['role']) for p in castwiththumb] meta.update({'cast': cast}) offset = bookmarks.get('movie', imdb, '', '', True) if float(offset) > 120: percentPlayed = int(float(offset) / float(meta['duration']) * 100) item.setProperty('resumetime', str(offset)) item.setProperty('percentplayed', str(percentPlayed)) item.setProperty('imdb_id', imdb) item.setProperty('tmdb_id', tmdb) try: item.setUniqueIDs({'imdb': imdb, 'tmdb': tmdb}) except: pass item.setInfo(type='Video', infoLabels = control.metadataClean(meta)) video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) except: log_utils.log('channels_dir', 1) pass control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
def movieDirectory(self, items): if items is None or len(items) == 0: control.idle() sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) addonPoster, addonBanner = control.addonPoster(), control.addonBanner() addonFanart, settingFanart = control.addonFanart(), control.setting('fanart') traktCredentials = trakt.getTraktCredentialsInfo() try: isOld = False control.item().getArt('type') except: isOld = True isPlayable = 'true' if 'plugin' not in control.infoLabel('Container.PluginName') else 'false' indicators = playcount.getMovieIndicators(refresh=True) if action == 'movies' else playcount.getMovieIndicators() playbackMenu = control.lang(32063).encode('utf-8') if control.setting('hosts.mode') == '2' else control.lang(32064).encode('utf-8') watchedMenu = control.lang(32068).encode('utf-8') if trakt.getTraktIndicatorsInfo() is True else control.lang(32066).encode('utf-8') unwatchedMenu = control.lang(32069).encode('utf-8') if trakt.getTraktIndicatorsInfo() is True else control.lang(32067).encode('utf-8') queueMenu = control.lang(32065).encode('utf-8') traktManagerMenu = control.lang(32070).encode('utf-8') nextMenu = control.lang(32053).encode('utf-8') addToLibrary = control.lang(32551).encode('utf-8') for i in items: try: label = '%s (%s)' % (i['title'], i['year']) imdb, tmdb, title, year = i['imdb'], i['tmdb'], i['originaltitle'], i['year'] sysname = urllib.quote_plus('%s (%s)' % (title, year)) systitle = urllib.quote_plus(title) meta = dict((k, v) for k, v in i.iteritems() if not v == '0') meta.update({'code': imdb, 'imdbnumber': imdb, 'imdb_id': imdb}) meta.update({'tmdb_id': tmdb}) meta.update({'mediatype': 'movie'}) meta.update({'trailer': '%s?action=trailer&name=%s' % (sysaddon, urllib.quote_plus(label))}) # meta.update({'trailer': 'plugin://script.extendedinfo/?info=playtrailer&&id=%s' % imdb}) if 'duration' not in i: meta.update({'duration': '120'}) elif i['duration'] == '0': meta.update({'duration': '120'}) try: meta.update({'duration': str(int(meta['duration']) * 60)}) except: pass try: meta.update({'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass poster = [i[x] for x in ['poster3', 'poster', 'poster2'] if i.get(x, '0') != '0'] poster = poster[0] if poster else addonPoster meta.update({'poster': poster}) sysmeta = urllib.quote_plus(json.dumps(meta)) url = '%s?action=play&title=%s&year=%s&imdb=%s&meta=%s&t=%s' % (sysaddon, systitle, year, imdb, sysmeta, self.systime) sysurl = urllib.quote_plus(url) path = '%s?action=play&title=%s&year=%s&imdb=%s' % (sysaddon, systitle, year, imdb) cm = [] cm.append( ('Find similar', 'ActivateWindow(10025,%s?action=movies&url=https://api.trakt.tv/movies/%s/related,return)' % (sysaddon, imdb))) cm.append((queueMenu, 'RunPlugin(%s?action=queueItem)' % sysaddon)) try: overlay = int(playcount.getMovieOverlay(indicators, imdb)) if overlay == 7: cm.append((unwatchedMenu, 'RunPlugin(%s?action=moviePlaycount&imdb=%s&query=6)' % (sysaddon, imdb))) meta.update({'playcount': 1, 'overlay': 7}) else: cm.append((watchedMenu, 'RunPlugin(%s?action=moviePlaycount&imdb=%s&query=7)' % (sysaddon, imdb))) meta.update({'playcount': 0, 'overlay': 6}) except: pass if traktCredentials is True: cm.append((traktManagerMenu, 'RunPlugin(%s?action=traktManager&name=%s&imdb=%s&content=movie)' % (sysaddon, sysname, imdb))) cm.append((playbackMenu, 'RunPlugin(%s?action=alterSources&url=%s&meta=%s)' % (sysaddon, sysurl, sysmeta))) if isOld is True: cm.append((control.lang2(19033).encode('utf-8'), 'Action(Info)')) cm.append( (addToLibrary, 'RunPlugin(%s?action=movieToLibrary&name=%s&title=%s&year=%s&imdb=%s&tmdb=%s)' % (sysaddon, sysname, systitle, year, imdb, tmdb))) item = control.item(label=label) art = {} art.update({'icon': poster, 'thumb': poster, 'poster': poster}) if 'banner' in i and not i['banner'] == '0': art.update({'banner': i['banner']}) else: art.update({'banner': addonBanner}) if 'clearlogo' in i and not i['clearlogo'] == '0': art.update({'clearlogo': i['clearlogo']}) if 'clearart' in i and not i['clearart'] == '0': art.update({'clearart': i['clearart']}) if settingFanart == 'true' and 'fanart2' in i and not i['fanart2'] == '0': item.setProperty('Fanart_Image', i['fanart2']) elif settingFanart == 'true' and 'fanart' in i and not i['fanart'] == '0': item.setProperty('Fanart_Image', i['fanart']) elif addonFanart is not None: item.setProperty('Fanart_Image', addonFanart) item.setArt(art) item.addContextMenuItems(cm) item.setProperty('IsPlayable', isPlayable) item.setInfo(type='Video', infoLabels=control.metadataClean(meta)) # item.setInfo(type='Video', infoLabels=meta) # old code video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) except: pass try: url = items[0]['next'] if url == '': raise Exception() icon = control.addonNext() url = '%s?action=moviePage&url=%s' % (sysaddon, urllib.quote_plus(url)) item = control.item(label=nextMenu) item.setArt({'icon': icon, 'thumb': icon, 'poster': icon, 'banner': icon}) if addonFanart is not None: item.setProperty('Fanart_Image', addonFanart) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: pass control.content(syshandle, 'movies') control.directory(syshandle, cacheToDisc=True) control.sleep(1000) views.setView('movies', {'skin.estuary': 55, 'skin.confluence': 500})
def seasonDirectory(self, items): if items is None or len(items) == 0: control.idle() control.notification(title=32054, message=33049, icon='INFO') sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) addonPoster, addonBanner = control.addonPoster(), control.addonBanner() addonFanart, settingFanart = control.addonFanart(), control.setting( 'fanart') traktCredentials = trakt.getTraktCredentialsInfo() if trakt.getTraktIndicatorsInfo() is True: watchedMenu = control.lang(32068).encode('utf-8') unwatchedMenu = control.lang(32069).encode('utf-8') else: watchedMenu = control.lang(32066).encode('utf-8') unwatchedMenu = control.lang(32067).encode('utf-8') traktManagerMenu = control.lang(32070).encode('utf-8') playlistManagerMenu = control.lang(35522).encode('utf-8') queueMenu = control.lang(32065).encode('utf-8') showPlaylistMenu = control.lang(35517).encode('utf-8') clearPlaylistMenu = control.lang(35516).encode('utf-8') labelMenu = control.lang(32055).encode('utf-8') playRandom = control.lang(32535).encode('utf-8') addToLibrary = control.lang(32551).encode('utf-8') try: multi = [i['tvshowtitle'] for i in items] except: multi = [] multi = len([x for y, x in enumerate(multi) if x not in multi[:y]]) multi = True if multi > 1 else False for i in items: try: imdb, tvdb, year, season = i['imdb'], i['tvdb'], i['year'], i[ 'season'] title = i['tvshowtitle'] label = '%s %s' % (labelMenu, i['season']) if self.season_special is False and control.setting( 'tv.specials') == 'true': self.season_special = True if int(season) == 0 else False try: if i['unaired'] == 'true': label = '[COLOR %s][I]%s[/I][/COLOR]' % ( self.unairedcolor, label) except: pass systitle = sysname = urllib.quote_plus(title) meta = dict((k, v) for k, v in i.iteritems() if not v == '0') meta.update({ 'code': imdb, 'imdbnumber': imdb, 'imdb_id': imdb }) meta.update({'tvdb_id': tvdb}) meta.update({'mediatype': 'tvshow'}) meta.update({ 'trailer': '%s?action=trailer&name=%s' % (sysaddon, sysname) }) try: plot = meta['plot'] index = plot.rfind('See full summary') if index >= 0: plot = plot[:index] plot = plot.strip() if re.match('[a-zA-Z\d]$', plot): plot += ' ...' meta['plot'] = plot except: pass try: meta.update({'duration': str(int(meta['duration']) * 60)}) except: pass try: meta.update( {'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass try: meta.update({'tvshowtitle': i['label']}) except: pass try: # Year is the shows year, not the seasons year. Extract the correct year frpm the premier date. yearNew = i['premiered'] yearNew = re.findall('(\d{4})', yearNew)[0] yearNew = yearNew.encode('utf-8') meta.update({'year': yearNew}) except: pass # First check thumbs, since they typically contains the seasons poster. The normal poster contains the show poster. poster = '0' if poster == '0' and 'thumb3' in i: poster = i['thumb3'] if poster == '0' and 'thumb2' in i: poster = i['thumb2'] if poster == '0' and 'thumb' in i: poster = i['thumb'] if poster == '0' and 'poster3' in i: poster = i['poster3'] if poster == '0' and 'poster2' in i: poster = i['poster2'] if poster == '0' and 'poster' in i: poster = i['poster'] icon = '0' if icon == '0' and 'icon3' in i: icon = i['icon3'] if icon == '0' and 'icon2' in i: icon = i['icon2'] if icon == '0' and 'icon' in i: icon = i['icon'] thumb = '0' if thumb == '0' and 'thumb3' in i: thumb = i['thumb3'] if thumb == '0' and 'thumb2' in i: thumb = i['thumb2'] if thumb == '0' and 'thumb' in i: thumb = i['thumb'] banner = '0' if banner == '0' and 'banner3' in i: banner = i['banner3'] if banner == '0' and 'banner2' in i: banner = i['banner2'] if banner == '0' and 'banner' in i: banner = i['banner'] fanart = '0' if settingFanart: if fanart == '0' and 'fanart3' in i: fanart = i['fanart3'] if fanart == '0' and 'fanart2' in i: fanart = i['fanart2'] if fanart == '0' and 'fanart' in i: fanart = i['fanart'] clearlogo = '0' if clearlogo == '0' and 'clearlogo' in i: clearlogo = i['clearlogo'] clearart = '0' if clearart == '0' and 'clearart' in i: clearart = i['clearart'] if poster == '0': poster = addonPoster if icon == '0': icon = poster if thumb == '0': thumb = poster if banner == '0': banner = addonBanner if fanart == '0': fanart = addonFanart art = {} if not poster == '0' and not poster is None: art.update({ 'poster': poster, 'tvshow.poster': poster, 'season.poster': poster }) if not fanart == '0' and not fanart is None: art.update({'fanart': fanart}) if not icon == '0' and not icon is None: art.update({'icon': icon}) if not thumb == '0' and not thumb is None: art.update({'thumb': thumb}) if not banner == '0' and not banner is None: art.update({'banner': banner}) if not clearlogo == '0' and not clearlogo is None: art.update({'clearlogo': clearlogo}) if not clearart == '0' and not clearart is None: art.update({'clearart': clearart}) ####-Context Menu and Overlays-#### cm = [] if traktCredentials is True: cm.append(( traktManagerMenu, 'RunPlugin(%s?action=traktManager&name=%s&imdb=%s&tvdb=%s&season=%s)' % (sysaddon, sysname, imdb, tvdb, season))) try: indicators = playcount.getSeasonIndicators(imdb) overlay = int( playcount.getSeasonOverlay(indicators, imdb, tvdb, season)) watched = overlay == 7 if watched: meta.update({'playcount': 1, 'overlay': 7}) cm.append(( unwatchedMenu, 'RunPlugin(%s?action=tvPlaycount&name=%s&imdb=%s&tvdb=%s&season=%s&query=6)' % (sysaddon, systitle, imdb, tvdb, season))) else: meta.update({'playcount': 0, 'overlay': 6}) cm.append(( watchedMenu, 'RunPlugin(%s?action=tvPlaycount&name=%s&imdb=%s&tvdb=%s&season=%s&query=7)' % (sysaddon, systitle, imdb, tvdb, season))) except: pass sysmeta = urllib.quote_plus(json.dumps(meta)) sysart = urllib.quote_plus(json.dumps(art)) url = '%s?action=episodes&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s&season=%s' % ( sysaddon, systitle, year, imdb, tvdb, season) sysurl = urllib.quote_plus(url) cm.append(( playRandom, 'RunPlugin(%s?action=random&rtype=episode&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s&season=%s)' % (sysaddon, urllib.quote_plus(systitle), urllib.quote_plus(year), urllib.quote_plus(imdb), urllib.quote_plus(tvdb), urllib.quote_plus(season)))) # cm.append((playlistManagerMenu, 'RunPlugin(%s?action=playlistManager&name=%s&url=%s&meta=%s&art=%s)' % (sysaddon, systitle, sysurl, sysmeta, sysart))) cm.append( (queueMenu, 'RunPlugin(%s?action=queueItem&name=%s)' % (sysaddon, systitle))) cm.append((showPlaylistMenu, 'RunPlugin(%s?action=showPlaylist)' % sysaddon)) cm.append((clearPlaylistMenu, 'RunPlugin(%s?action=clearPlaylist)' % sysaddon)) cm.append(( addToLibrary, 'RunPlugin(%s?action=tvshowToLibrary&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s)' % (sysaddon, systitle, year, imdb, tvdb))) cm.append(('[COLOR red]Venom Settings[/COLOR]', 'RunPlugin(%s?action=openSettings&query=(0,0))' % sysaddon)) #################################### item = control.item(label=label) unwatchedEnabled = True unwatchedLimit = False if unwatchedEnabled: count = playcount.getSeasonCount(imdb, season, self.season_special, unwatchedLimit) if count: item.setProperty('TotalEpisodes', str(count['total'])) item.setProperty('WatchedEpisodes', str(count['watched'])) item.setProperty('UnWatchedEpisodes', str(count['unwatched'])) total_seasons = trakt.getSeasons(imdb, full=False) if not total_seasons is None: total_seasons = [i['number'] for i in total_seasons] total_seasons = len(total_seasons) if control.setting( 'tv.specials' ) == 'false' or self.season_special is False: total_seasons = total_seasons - 1 item.setProperty('TotalSeasons', str(total_seasons)) if 'episodeIDS' in i: item.setUniqueIDs(i['episodeIDS']) if 'cast' in i: item.setCast(i['cast']) # if not fanart == '0' and not fanart is None: # item.setProperty('Fanart_Image', fanart) item.setArt(art) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) item.addContextMenuItems(cm) video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: pass try: control.property(syshandle, 'showplot', items[0]['plot']) except: pass control.content(syshandle, 'seasons') control.directory(syshandle, cacheToDisc=True) views.setView('seasons', {'skin.estuary': 55, 'skin.confluence': 500})
def channelDirectory(self, items): if items == None or len(items) == 0: control.idle() sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) addonPoster, addonBanner = control.addonPoster(), control.addonBanner() addonFanart, settingFanart = control.addonFanart(), control.setting( 'fanart') try: isOld = False control.item().getArt('type') except: isOld = True isPlayable = 'true' if not 'plugin' in control.infoLabel( 'Container.PluginName') else 'false' playbackMenu = control.lang(32063) if control.setting( 'hosts.mode') == '2' else control.lang(32064) queueMenu = control.lang(32065) refreshMenu = control.lang(32072) infoMenu = control.lang(32101) for i in items: try: label = '[B]%s[/B] : %s (%s)' % (i['channel'].upper(), i['title'], i['year']) sysname = urllib_parse.quote_plus('%s (%s)' % (i['title'], i['year'])) systitle = urllib_parse.quote_plus(i['title']) imdb, tmdb, year = i['imdb'], i['tmdb'], i['year'] meta = dict( (k, v) for k, v in six.iteritems(i) if not v == '0') meta.update({ 'code': imdb, 'imdbnumber': imdb, 'imdb_id': imdb }) meta.update({'tmdb_id': tmdb}) meta.update({'mediatype': 'movie'}) meta.update({ 'trailer': '%s?action=trailer&name=%s' % (sysaddon, sysname) }) #meta.update({'trailer': 'plugin://script.extendedinfo/?info=playtrailer&&id=%s' % imdb}) meta.update({'playcount': 0, 'overlay': 6}) try: meta.update( {'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass sysmeta = urllib_parse.quote_plus(json.dumps(meta)) url = '%s?action=play&title=%s&year=%s&imdb=%s&meta=%s&t=%s' % ( sysaddon, systitle, year, imdb, sysmeta, self.systime) sysurl = urllib_parse.quote_plus(url) cm = [] cm.append( (queueMenu, 'RunPlugin(%s?action=queueItem)' % sysaddon)) cm.append( (refreshMenu, 'RunPlugin(%s?action=refresh)' % sysaddon)) cm.append((playbackMenu, 'RunPlugin(%s?action=alterSources&url=%s&meta=%s)' % (sysaddon, sysurl, sysmeta))) if isOld == True: cm.append((infoMenu, 'Action(Info)')) item = control.item(label=label) art = {} if 'poster2' in i and not i['poster2'] == '0': art.update({ 'icon': i['poster2'], 'thumb': i['poster2'], 'poster': i['poster2'] }) elif 'poster' in i and not i['poster'] == '0': art.update({ 'icon': i['poster'], 'thumb': i['poster'], 'poster': i['poster'] }) else: art.update({ 'icon': addonPoster, 'thumb': addonPoster, 'poster': addonPoster }) art.update({'banner': addonBanner}) if settingFanart == 'true' and 'fanart' in i and not i[ 'fanart'] == '0': item.setProperty('Fanart_Image', i['fanart']) elif not addonFanart == None: item.setProperty('Fanart_Image', addonFanart) item.setArt(art) item.addContextMenuItems(cm) item.setProperty('IsPlayable', isPlayable) item.setInfo(type='Video', infoLabels=control.metadataClean(meta)) video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) except: pass control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=True)
def play_source(self, title, year, season, episode, imdb, tmdb, tvdb, url, meta, select=None): try: if not url: raise Exception self.media_type = 'movie' if season is None or episode is None else 'episode' self.title = title self.year = str(year) if self.media_type == 'movie': self.name = '%s (%s)' % (title, self.year) self.season = None self.episode = None elif self.media_type == 'episode': self.name = '%s S%02dE%02d' % (title, int(season), int(episode)) self.season = '%01d' % int(season) self.episode = '%01d' % int(episode) self.DBID = None self.imdb = imdb if imdb is not None else '' self.tmdb = tmdb if tmdb is not None else '' self.tvdb = tvdb if tvdb is not None else '' self.ids = { 'imdb': self.imdb, 'tmdb': self.tmdb, 'tvdb': self.tvdb } ## - compare meta received to database and use largest(eventually switch to a request to fetch missing db meta for item) self.imdb_user = control.setting('imdb.user').replace('ur', '') self.tmdb_key = control.setting('tmdb.api.key') if not self.tmdb_key: self.tmdb_key = '3320855e65a9758297fec4f7c9717698' self.tvdb_key = control.setting('tvdb.api.key') if self.media_type == 'episode': self.user = str(self.imdb_user) + str(self.tvdb_key) else: self.user = str(self.tmdb_key) self.lang = control.apiLanguage()['tvdb'] meta1 = meta meta2 = metacache.fetch([{ 'imdb': self.imdb, 'tmdb': self.tmdb, 'tvdb': self.tvdb }], self.lang, self.user)[0] if meta2 != self.ids: meta2 = dict((k, v) for k, v in control.iteritems(meta2) if v is not None and v != '') if meta1 is not None: try: if len(meta2) > len(meta1): meta2.update(meta1) meta = meta2 else: meta = meta1 except: log_utils.error() else: meta = meta2 if meta2 != self.ids else meta1 ################## self.meta = meta poster, thumb, season_poster, fanart, banner, clearart, clearlogo, discart, meta = self.getMeta( meta) runtime = meta.get('duration') if meta else 0 self.offset = Bookmarks().get(name=self.name, imdb=imdb, tmdb=tmdb, tvdb=tvdb, season=season, episode=episode, year=self.year, runtime=runtime) item = control.item(path=url) item.setUniqueIDs(self.ids) if control.setting('disable.player.art') == 'true': for k in ('clearart', 'clearlogo', 'discart'): meta.pop(k, None) if self.media_type == 'episode': if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: item.setArt({ 'tvshow.clearart': clearart, 'tvshow.clearlogo': clearlogo, 'tvshow.discart': discart, 'thumb': thumb, 'tvshow.poster': season_poster, 'season.poster': season_poster, 'tvshow.fanart': fanart }) else: if control.setting('disable.player.art') == 'true': item.setArt({ 'thumb': thumb, 'poster': poster, 'fanart': fanart }) else: item.setArt({ 'clearart': clearart, 'clearlogo': clearlogo, 'discart': discart, 'thumb': thumb, 'poster': poster, 'fanart': fanart }) if 'castandart' in meta: item.setCast(meta.get('castandart', '')) item.setInfo(type='video', infoLabels=control.metadataClean(meta)) if 'plugin' not in control.infoLabel( 'Container.PluginName') or select != '1': control.busy() control.resolve(int(argv[1]), True, item) elif select == '1': control.busy() control.player.play(url, item) control.homeWindow.setProperty('script.trakt.ids', jsdumps(self.ids)) self.keepAlive() control.homeWindow.clearProperty('script.trakt.ids') except: log_utils.error() return control.cancelPlayback()
def tvshowDirectory(self, items): if items == None or len(items) == 0: control.idle() sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) addonPoster, addonBanner = control.addonPoster(), control.addonBanner() addonFanart, settingFanart = control.addonFanart(), control.setting( 'fanart') traktCredentials = trakt.getTraktCredentialsInfo() try: isOld = False control.item().getArt('type') except: isOld = True indicators = playcount.getTVShowIndicators( refresh=True ) if action == 'tvshows' else playcount.getTVShowIndicators() flatten = True if control.setting( 'flatten.tvshows') == 'true' else False watchedMenu = control.lang(32068).encode( 'utf-8') if trakt.getTraktIndicatorsInfo( ) == True else control.lang(32066).encode('utf-8') unwatchedMenu = control.lang(32069).encode( 'utf-8') if trakt.getTraktIndicatorsInfo( ) == True else control.lang(32067).encode('utf-8') queueMenu = control.lang(32065).encode('utf-8') traktManagerMenu = control.lang(32070).encode('utf-8') nextMenu = control.lang(32053).encode('utf-8') playRandom = control.lang(32535).encode('utf-8') addToLibrary = control.lang(32551).encode('utf-8') for i in items: try: label = i['title'] systitle = sysname = urllib.quote_plus(i['originaltitle']) sysimage = urllib.quote_plus(i['poster']) imdb, tvdb, year = i['imdb'], i['tvdb'], i['year'] meta = dict((k, v) for k, v in i.iteritems() if not v == '0') meta.update({ 'code': imdb, 'imdbnumber': imdb, 'imdb_id': imdb }) meta.update({'tvdb_id': tvdb}) meta.update({'mediatype': 'tvshow'}) meta.update({ 'trailer': '%s?action=trailer&name=%s' % (sysaddon, urllib.quote_plus(label)) }) if not 'duration' in i: meta.update({'duration': '60'}) elif i['duration'] == '0': meta.update({'duration': '60'}) try: meta.update({'duration': str(int(meta['duration']) * 60)}) except: pass try: meta.update( {'genre': cleangenre.lang(meta['genre'], self.lang)}) except: pass try: overlay = int(playcount.getTVShowOverlay(indicators, tvdb)) if overlay == 7: meta.update({'playcount': 1, 'overlay': 7}) else: meta.update({'playcount': 0, 'overlay': 6}) except: pass if flatten == True: url = '%s?action=episodes&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s' % ( sysaddon, systitle, year, imdb, tvdb) else: url = '%s?action=seasons&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s' % ( sysaddon, systitle, year, imdb, tvdb) cm = [] cm.append(( 'Find similar', 'ActivateWindow(10025,%s?action=tvshows&url=https://api.trakt.tv/shows/%s/related,return)' % (sysaddon, imdb))) cm.append(( playRandom, 'RunPlugin(%s?action=random&rtype=season&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s)' % (sysaddon, urllib.quote_plus(systitle), urllib.quote_plus(year), urllib.quote_plus(imdb), urllib.quote_plus(tvdb)))) cm.append( (queueMenu, 'RunPlugin(%s?action=queueItem)' % sysaddon)) cm.append(( watchedMenu, 'RunPlugin(%s?action=tvPlaycount&name=%s&imdb=%s&tvdb=%s&query=7)' % (sysaddon, systitle, imdb, tvdb))) cm.append(( unwatchedMenu, 'RunPlugin(%s?action=tvPlaycount&name=%s&imdb=%s&tvdb=%s&query=6)' % (sysaddon, systitle, imdb, tvdb))) if traktCredentials == True: cm.append(( traktManagerMenu, 'RunPlugin(%s?action=traktManager&name=%s&tvdb=%s&content=tvshow)' % (sysaddon, sysname, tvdb))) if isOld == True: cm.append( (control.lang2(19033).encode('utf-8'), 'Action(Info)')) cm.append(( addToLibrary, 'RunPlugin(%s?action=tvshowToLibrary&tvshowtitle=%s&year=%s&imdb=%s&tvdb=%s)' % (sysaddon, systitle, year, imdb, tvdb))) item = control.item(label=label) art = {} if 'poster' in i and not i['poster'] == '0': art.update({ 'icon': i['poster'], 'thumb': i['poster'], 'poster': i['poster'] }) # elif 'poster2' in i and not i['poster2'] == '0': # art.update({'icon': i['poster2'], 'thumb': i['poster2'], 'poster': i['poster2']}) else: art.update({ 'icon': addonPoster, 'thumb': addonPoster, 'poster': addonPoster }) if 'banner' in i and not i['banner'] == '0': art.update({'banner': i['banner']}) # elif 'banner2' in i and not i['banner2'] == '0': # art.update({'banner': i['banner2']}) elif 'fanart' in i and not i['fanart'] == '0': art.update({'banner': i['fanart']}) else: art.update({'banner': addonBanner}) if 'clearlogo' in i and not i['clearlogo'] == '0': art.update({'clearlogo': i['clearlogo']}) if 'clearart' in i and not i['clearart'] == '0': art.update({'clearart': i['clearart']}) if settingFanart == 'true' and 'fanart' in i and not i[ 'fanart'] == '0': item.setProperty('Fanart_Image', i['fanart']) # elif settingFanart == 'true' and 'fanart2' in i and not i['fanart2'] == '0': # item.setProperty('Fanart_Image', i['fanart2']) elif not addonFanart == None: item.setProperty('Fanart_Image', addonFanart) item.setArt(art) item.addContextMenuItems(cm) item.setInfo(type='Video', infoLabels=control.metadataClean(meta)) #item.setInfo(type='Video', infoLabels=meta) # old code video_streaminfo = {'codec': 'h264'} item.addStreamInfo('video', video_streaminfo) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: pass try: url = items[0]['next'] if url == '': raise Exception() icon = control.addonNext() url = '%s?action=tvshowPage&url=%s' % (sysaddon, urllib.quote_plus(url)) item = control.item(label=nextMenu) item.setArt({ 'icon': icon, 'thumb': icon, 'poster': icon, 'banner': icon }) if not addonFanart == None: item.setProperty('Fanart_Image', addonFanart) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) except: pass control.content(syshandle, 'tvshows') control.directory(syshandle, cacheToDisc=True) views.setView('tvshows', {'skin.estuary': 55, 'skin.confluence': 500})