def get_extras(self): from resources.lib.modules.globosat import scraper_vod tracks = cache.get(scraper_vod.get_tracks, 1) sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) provider = 'globosat' url = '%s?action=openfeatured&provider=%s' % (sysaddon, provider) label = 'Destaques' item = control.item(label=label) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels={'title': label}) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) for track in tracks: url = '%s?action=openextra&provider=%s&id=%s&kind=%s' % (sysaddon, provider, track['id'], track['kind']) label = track['title'] item = control.item(label=label) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels={'title': label}) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_LABEL_IGNORE_FOLDERS) control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=False)
def get_events_by_categories(self, category): sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) if category == 'lutadores': import string letters = list(string.ascii_uppercase) for letter in letters: url = '%s?action=openfighters&letter=%s' % (sysaddon, letter) item = control.item(label=letter) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels={'title': letter}) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_LABEL_IGNORE_FOLDERS) control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=False) return if category == 'ufc': events = scraper_combate.get_ufc_submenu() else: events = cache.get(scraper_combate.get_all_events, 1, category) for event in events: label = event['title'] event_url = urllib.quote_plus( event['url']) if event['url'] else None slug = event['slug'] if 'slug' in event else category meta = {'mediatype': 'video', 'overlay': 6, 'title': label} url = '%s?action=openevent&url=%s&provider=%s&category=%s' % ( sysaddon, event_url, 'combate', slug) item = control.item(label=label) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels=meta) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=False)
def get_fighters(self, letter): fighters = cache.get(globosat.Indexer().get_fighters, 1, letter) sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) for fighter in fighters: label = fighter['title'] slug = fighter['slug'] thumb = fighter['thumb'] if 'thumb' in fighter else None meta = { 'mediatype': 'episode', 'overlay': 6, 'title': label, 'slug': slug, 'url': fighter['url'] } url = '%s?action=openfighter&slug=%s' % (sysaddon, slug) item = control.item(label=label) art = { 'icon': thumb, 'thumb': thumb, 'fanart': thumb, 'poster': thumb, 'banner': thumb, 'landscape': thumb } item.setProperty('Fanart_Image', thumb) item.setArt(art) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels=meta) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_LABEL_IGNORE_FOLDERS) control.content(syshandle, 'episodes') control.directory(syshandle, cacheToDisc=False)
def get_program_dates(self, program_id, poster=None, provider='globoplay'): days = globoplay.Indexer().get_program_dates(program_id) if days is None or len(days) == 0: control.idle() sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) for day in days: label = day meta = {} meta.update({'mediatype': 'video'}) meta.update({'overlay': 6}) meta.update({'title': label}) meta.update({'date': day}) url = '%s?action=openvideos&provider=%s&program_id=%s&date=%s' % ( sysaddon, provider, program_id, day) item = control.item(label=label) art = {'poster': poster} item.setArt(art) # item.setProperty('Fanart_Image', GLOBO_FANART) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels=meta) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_DATE) control.content(syshandle, 'episodes') control.directory(syshandle, cacheToDisc=False)
def channel_directory(self, items): if items is None or len(items) == 0: control.idle() sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) try: isOld = False control.item().getArt('type') except: isOld = True refreshMenu = control.lang(32072).encode('utf-8') list_items = [] for order, channel in enumerate(items): label = channel['name'] meta = channel meta.update({'mediatype': channel['mediatype'] if 'mediatype' in channel else 'tvshow'}) # string - "video", "movie", "tvshow", "season", "episode" or "musicvideo" meta.update({'playcount': 0, 'overlay': 6}) meta.update({'duration': channel['duration']}) if 'duration' in channel else None meta.update({'title': channel['title']}) if 'title' in channel else None meta.update({'tagline': channel['tagline']}) if 'tagline' in channel else None meta.update({'year': channel['year']}) if 'year' in channel else None meta.update({'sorttitle': meta['title']}) meta.update({'title': meta['name']}) sysmeta = urllib.quote_plus(json.dumps(meta)) id_globo_videos = channel['id'] brplayprovider = channel['brplayprovider'] if 'brplayprovider' in channel else None isFolder = channel['isFolder'] == 'true' if 'isFolder' in channel else False isPlayable = channel['playable'] == 'true' if 'playable' in channel else False url = channel['url'] if 'url' in channel else '%s?action=playlive&provider=%s&id_globo_videos=%s&isFolder=%s&meta=%s&t=%s' % (sysaddon, brplayprovider, id_globo_videos, isFolder, sysmeta, self.systime) cm = [(refreshMenu, 'RunPlugin(%s?action=refresh)' % sysaddon)] if isOld is True: cm.append((control.lang2(19033).encode('utf-8'), 'Action(Info)')) item = control.item(label=label) fanart = channel['fanart'] art = {'icon': channel['logo'], 'fanart': fanart} if 'poster' in channel: art.update({'poster': channel['poster']}) if 'banner' in channel: art.update({'banner': channel['banner']}) if 'clearart' in channel: art.update({'clearart': channel['clearart']}) if 'clearlogo' in channel: art.update({'clearlogo': channel['clearlogo']}) if 'landscape' in channel: art.update({'landscape': channel['landscape']}) if 'thumb' in channel: art.update({'thumb': channel['thumb']}) item.setArt(art) if 'logo' in channel and 'logo2' in channel: item.setProperty('Logo1', channel['logo']) item.setProperty('Logo2', channel['logo2']) item.setProperty('Initials1', channel['initials1']) item.setProperty('Initials2', channel['initials2']) if 'live' in channel: item.setProperty('Live', str(channel['live'])) if 'gamedetails' in channel: item.setProperty('GameDetails', channel['gamedetails']) item.setProperty('Fanart_Image', fanart) if 'hd' not in channel or channel['hd'] is True: video_info = {'aspect': '1.78', 'width': '1280', 'height': '720'} else: video_info = {'aspect': '1.78', 'width': '720', 'height': '480'} item.addStreamInfo('video', video_info) item.addContextMenuItems(cm) item.setProperty('IsPlayable', 'false' if isFolder or not isPlayable else 'true') item.setInfo(type='video', infoLabels=control.filter_info_labels(meta)) item.setContentLookup(False) if 'duration' in channel and channel['duration'] is not None: duration = float(meta['duration']) startdate = util.strptime_workaround(channel['dateadded'], '%Y-%m-%d %H:%M:%S') if 'dateadded' in channel and channel['dateadded'] else None offset = float(util.get_total_seconds(datetime.datetime.now() - startdate)) if startdate else 0 item.setProperty('Progress', str((offset / duration) * 100) if duration else str(0)) item.setProperty('totaltime', str(duration)) # if not isFolder: # item.setMimeType("application/vnd.apple.mpegurl") list_items.append((url, item, isFolder)) control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_DATEADDED) control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_VIDEO_SORT_TITLE) control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_LABEL_IGNORE_FOLDERS) control.addItems(syshandle, list_items) control.category(handle=syshandle, category=control.lang(32001).encode('utf-8')) content = 'LiveTV' if control.isJarvis else 'tvshows' control.content(syshandle, content) control.directory(syshandle, cacheToDisc=False)
def channel_directory(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).encode('utf-8') if control.setting('hosts.mode') == '2' else control.lang(32064).encode('utf-8') #queueMenu = control.lang(32065).encode('utf-8') refreshMenu = control.lang(32072).encode('utf-8') for i in items: # try: label = i['name'] meta = dict((k, v) for k, v in i.iteritems() if not v == '0') meta.update( {'mediatype': 'video'} ) #string - "video", "movie", "tvshow", "season", "episode" or "musicvideo" meta.update({'playcount': 0, 'overlay': 6}) meta.update({'duration': i['duration'] }) if 'duration' in i else None meta.update({'title': i['title']}) if 'title' in i else None meta.update({'tagline': i['tagline']}) if 'tagline' in i else None # meta.update({'aired': i['datetime']}) if 'datetime' in i else None # meta.update({'dateadded': i['datetime']}) if 'datetime' in i else None #"StartTime", "EndTime", "ChannelNumber" and "ChannelName" sysmeta = urllib.quote_plus(json.dumps(meta)) id_globo_videos = i['id'] id_cms = i['id_cms'] if 'id_cms' in i else None slug = i['slug'] if 'slug' in i else None brplayprovider = i['brplayprovider'] url = '%s?action=openchannel&provider=%s&id_globo_videos=%s&id_cms=%s&slug=%s&meta=%s&t=%s' % ( sysaddon, brplayprovider, id_globo_videos, id_cms, slug, sysmeta, self.systime) cm = [] #cm.append((queueMenu, 'RunPlugin(%s?action=queueItem)' % sysaddon)) cm.append((refreshMenu, 'RunPlugin(%s?action=refresh)' % sysaddon)) if isOld == True: cm.append( (control.lang2(19033).encode('utf-8'), '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({ 'icon': i['logo'], 'thumb': i['logo'], 'poster': i['logo'] }) #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) if 'fanart' in i: item.setProperty('Fanart_Image', i['fanart']) else: item.setProperty('Fanart_Image', control.addonFanart()) item.setArt(art) item.addContextMenuItems(cm) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels=meta) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) # except: # pass control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_LABEL_IGNORE_FOLDERS) control.content(syshandle, 'files') control.directory(syshandle, cacheToDisc=False)
def episodes_directory(self, items, program_id=None, next_page=None, total_pages=None, next_action='openvideos', days=[], poster=None, provider=None, is_favorite=False, is_watchlater=False): if items is None or len(items) == 0: control.idle() sys.exit() sysaddon = sys.argv[0] syshandle = int(sys.argv[1]) # 32072 = "Refresh" refreshMenu = control.lang(32072).encode('utf-8') addFavorite = control.lang(32073).encode('utf-8') removeFavorite = control.lang(32074).encode('utf-8') addWatchLater = control.lang(32075).encode('utf-8') removeWatchLater = control.lang(32076).encode('utf-8') content = 'episodes' sort = True if days: # 34005 = "By Date" label = control.lang(34005).encode('utf-8') meta = {} meta.update({'mediatype': 'video'}) meta.update({'overlay': 6}) meta.update({'title': label}) url = '%s?action=showdates&provider=%s&program_id=%s&category=%s' % ( sysaddon, provider, program_id, program_id) item = control.item(label=label) art = {'icon': CALENDAR_ICON, 'thumb': CALENDAR_ICON} if poster: art.update({'poster': poster}) # item.setProperty('Fanart_Image', GLOBO_FANART) item.setArt(art) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels=meta) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) for video in items: if 'url' in video: content = 'files' sort = False label = video['title'] event_url = urllib.quote_plus( video['url']) if video['url'] else None slug = video['slug'] if 'slug' in video else program_id meta = {'mediatype': 'video', 'overlay': 6, 'title': label} meta.update(video) url = '%s?action=openevent&url=%s&provider=%s&category=%s' % ( sysaddon, event_url, 'combate', slug) item = control.item(label=label) if 'thumb' in meta and 'fanart' in meta: art = {'thumb': meta['thumb'], 'fanart': meta['fanart']} item.setArt(art) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels=meta) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) else: # label = video['label'] if 'label' in video else video['title'] label = video['title'] meta = video meta.update({'overlay': 6}) if 'live' not in meta: meta.update({'live': False}) sysmeta = urllib.quote_plus(json.dumps(meta)) provider = provider or video[ 'brplayprovider'] if 'brplayprovider' in video else provider action = 'playvod' if not meta['live'] else 'playlive' url = '%s?action=%s&provider=%s&id_globo_videos=%s&meta=%s' % ( sysaddon, action, provider, video['id'], sysmeta) item = control.item(label=label) fanart = meta['fanart'] if 'fanart' in meta else GLOBO_FANART clearlogo = meta['clearlogo'] if 'clearlogo' in meta else None poster = meta['poster'] if 'poster' in meta else poster art = { 'thumb': meta['thumb'], 'poster': poster, 'fanart': fanart, 'clearlogo': clearlogo } item.setProperty('Fanart_Image', fanart) offset = float( meta['milliseconds_watched'] ) / 1000.0 if 'milliseconds_watched' in meta else 0 if 'duration' in meta: duration = float( meta['duration']) if 'duration' in meta else offset duration = duration * 1000.0 item.setProperty('totaltime', str(duration)) if offset > 0: item.setProperty('resumetime', str(offset)) meta.update({'playcount': 1}) else: item.setProperty('resumetime', str(0)) meta.update({'playcount': 0}) if 'date' not in meta: sort = False item.setArt(art) item.setProperty('IsPlayable', "true") item.setInfo(type='video', infoLabels=meta) cm = [(refreshMenu, 'RunPlugin(%s?action=refresh)' % sysaddon)] if provider == 'globosat': if is_favorite: cm.append(( removeFavorite, 'RunPlugin(%s?action=delFavorites&id_globo_videos=%s)' % (sysaddon, video['id']))) else: cm.append(( addFavorite, 'RunPlugin(%s?action=addFavorites&id_globo_videos=%s)' % (sysaddon, video['id']))) if is_watchlater: cm.append(( removeWatchLater, 'RunPlugin(%s?action=delwatchlater&id_globo_videos=%s)' % (sysaddon, video['id']))) else: cm.append(( addWatchLater, 'RunPlugin(%s?action=addwatchlater&id_globo_videos=%s)' % (sysaddon, video['id']))) item.addContextMenuItems(cm) # item.setMimeType("application/vnd.apple.mpegurl") control.addItem(handle=syshandle, url=url, listitem=item, isFolder=False) if next_page: if 'bingewatch' in meta and meta['bingewatch']: label = control.lang(34007).encode('utf-8') else: # 34006 = "Older Videos" label = control.lang(34006).encode('utf-8') meta = {} meta.update({'mediatype': 'video'}) meta.update({'overlay': 6}) meta.update({'title': label}) url = '%s?action=%s&provider=%s&program_id=%s&category=%s&page=%s' % ( sysaddon, next_action, provider, program_id, program_id, next_page) item = control.item(label=label) art = {'icon': NEXT_ICON, 'thumb': NEXT_ICON, 'poster': poster} # item.setProperty('Fanart_Image', GLOBO_FANART) item.setArt(art) item.setProperty('IsPlayable', "false") item.setInfo(type='video', infoLabels=meta) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=True) if not next_page and next_action == 'openvideos' and sort: control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_DATE) else: control.addSortMethod(int(sys.argv[1]), control.SORT_METHOD_UNSORTED) control.content(syshandle, content) control.directory(syshandle, cacheToDisc=False)
def create_directory(items, current=None, cache_to_disk=True): if current is None: current = {} succeeded = True custom_title = None try: media_types = {} content = None sort_methods = set() for data in items: label = data.get('label', '') if control.supports_offscreen: item = control.item(label=label, offscreen=True) else: item = control.item(label=label) art = data.get('art', {}) or {} item.setArt(art) properties = data.get('properties', {}) or {} item.setProperties(properties) item.setInfo(type='video', infoLabels=control.filter_info_labels(data)) cm = [(control.lang(32072).encode('utf-8'), 'RunPlugin(%s?action=refresh)' % sysaddon), (control.lang(33501).encode('utf-8'), 'RunPlugin(%s?action=clear)' % sysaddon)] for menu in data.get('context_menu', []) or []: cm.append(menu) item.addContextMenuItems(cm) meta_string = urllib.quote_plus(json.dumps(data)) url = data.get( 'url', None) or '%s?action=generic&meta=%s' % (sysaddon, meta_string) is_playable = data.get('IsPlayable', False) is_folder = data.get('IsFolder', not is_playable) if is_playable: item.setProperty('IsPlayable', 'true') else: item.setProperty('IsPlayable', 'false') media_type = data.get('mediatype', 'None') or 'None' if media_type not in media_types: media_types[media_type] = 1 else: media_types[media_type] = media_types[media_type] + 1 sorts = data.get('sort', []) if sorts: try: for sort in sorts: sort_methods.add(sort) except TypeError: sort_methods.add(sorts) if not content and data.get('content', None): content = data.get('content', None) if not custom_title: custom_title = data.get('custom_title', None) if data.get('setCast', None): item.setCast(data.get('setCast', None)) control.addItem(handle=syshandle, url=url, listitem=item, isFolder=is_folder) for sort in sort_methods: if isinstance(sort, tuple): control.addSortMethod(syshandle, sort[0], sort[1]) else: control.addSortMethod(syshandle, sort) category = custom_title or current.get('label', None) if category: control.category(handle=syshandle, category=category) # content: files, songs, artists, albums, movies, tvshows, episodes, musicvideos if not content and media_types: media_type = max(media_types.iteritems(), key=operator.itemgetter(1))[0] if media_type == 'movie': content = 'movies' elif media_type == 'tvshow': content = 'tvshows' elif media_type == 'episode': content = 'episodes' elif media_type == 'season': content = 'tvshows' elif media_type == 'musicvideo': content = 'musicvideos' if content and content != 'default': control.content(syshandle, content) except: control.log(traceback.format_exc(), control.LOGERROR) succeeded = False finally: control.directory(syshandle, succeeded=succeeded, updateListing=False, cacheToDisc=cache_to_disk)