def addProgram(self, program): pitem = {'channel' : program['Channel'], # 'credits' : {'director': [program.get('Directors',[])], 'cast': [program.get('Cast',[])]}, 'category' : [(genre,LANG) for genre in program.get('Categories',['Undefined'])], 'title' : [(program['Title'], LANG)], 'desc' : [((program['Summary'] or xbmc.getLocalizedString(161)), LANG)], 'stop' : (strpTime(program['Raw']['endTime']).strftime(xmltv.date_format)), 'start' : (strpTime(program['Raw']['startTime']).strftime(xmltv.date_format)), 'icon' : [{'src': program.get('Image',FANART)}]} if program.get('EpisodeTitle',''): pitem['sub-title'] = [(program['EpisodeTitle'], LANG)] if program.get('OriginalDate',''): try: pitem['date'] = (strpTime(program['OriginalDate'], '%Y-%m-%d')).strftime('%Y%m%d') except: pass if program.get('Tags',None): if 'New' in program.get('Tags',[]): pitem['new'] = '' #write blank tag, tag == True if program['Raw'].get('ratings',None): rating = program['Raw'].get('ratings',[{}])[0].get('code','') if rating.startswith('TV'): pitem['rating'] = [{'system': 'VCHIP', 'value': rating}] else: pitem['rating'] = [{'system': 'MPAA', 'value': rating}] if program.get('EpisodeNumber',''): SElabel = 'S%sE%s'%(str(program.get("SeasonNumber",0)).zfill(2),str(program.get("EpisodeNumber",0)).zfill(2)) pitem['episode-num'] = [(SElabel, 'onscreen')] log('addProgram = %s'%(pitem)) self.xmltvList['programmes'].append(pitem) return True
def translate(string): ''' Get add-on string. Returns in unicode. ''' if type(string) != int: string = STRINGS[string] result = xbmcaddon.Addon('plugin.video.jellyfin').getLocalizedString( string) if not result: result = xbmc.getLocalizedString(string) return result
def addon_string(id): if id >= 32000: string = COMMON_ADDON.getLocalizedString(id) elif id >= 30000: string = ADDON.getLocalizedString(id) else: string = xbmc.getLocalizedString(id) if not string: log.warning( "LANGUAGE: Addon didn't return a string for id: {}".format(id)) string = str(id) return string
def i18n(string_id): mapped_string_id = STRINGS.get(string_id) if mapped_string_id: string_id = mapped_string_id try: core = int(string_id) < 30000 except ValueError: __LOG.debug('Failed to map translation, returning id ...') return string_id if core: return encode_utf8(xbmc.getLocalizedString(string_id)) return encode_utf8(CONFIG['addon'].getLocalizedString(string_id))
def buildStation(self, data): station, opt = data chan = self.getChannelInfo(station) if chan is None: return None elif chan.getDRM(): return None stnum = station stname = (chan.getAffiliate() or chan.getGuideName() or chan.getGuideNumber() or str(stnum)) if not stname: return None favorite = chan.getFavorite() == 1 channel = {"name" :stname, "stream":"plugin://%s/play/pvr/%s"%(ADDON_ID,stnum), "id" :"%s.%s@%s"%(stnum,slugify(stname),slugify(ADDON_NAME)), "logo" :(chan.getImageURL() or LOGO), "preset":str(stnum), "group" :ADDON_NAME, "radio" :False} if favorite: channel['group'] = ';'.join([LANGUAGE(49012),ADDON_NAME]) if REAL_SETTINGS.getSettingBool('Build_Favorites') and not favorite: return None elif opt == 'channel': return channel else: programmes = {channel['id']:[]} listings = chan.getProgramInfos() for item in listings: starttime = datetime.datetime.fromtimestamp(float(item.getStartTime())) + UTC_OFFSET endtime = datetime.datetime.fromtimestamp(float(item.getEndTime())) + UTC_OFFSET try: aired = datetime.datetime.fromtimestamp(float(item.getOriginalAirdate())) except: aired = starttime program = {"start" :starttime.strftime(DTFORMAT), "stop" :endtime.strftime(DTFORMAT), "title" :(item.getTitle() or channel['name']), "description":(item.getSynopsis() or xbmc.getLocalizedString(161)), "subtitle" :(item.getEpisodeTitle() or ""), "episode" :"", "genre" :"", "image" :(item.getImageURL() or channel['logo']), "date" :aired.strftime('%Y-%m-%d'), "credits" :"", "stream" :""} programmes[channel['id']].append(program) return programmes
def special_listener(): ''' Corner cases that needs to be listened to. This is run in a loop within monitor.py ''' player = xbmc.Player() isPlaying = player.isPlaying() count = int(window('jellyfin.external_count') or 0) if (not isPlaying and xbmc.getCondVisibility('Window.IsVisible(DialogContextMenu.xml)') and xbmc.getInfoLabel('Control.GetLabel(1002)') == xbmc.getLocalizedString(12021)): control = int(xbmcgui.Window(10106).getFocusId()) if control == 1002: # Start from beginning LOG.info("Resume dialog: Start from beginning selected.") window('jellyfin.resume.bool', False) else: LOG.info("Resume dialog: Resume selected.") window('jellyfin.resume.bool', True) elif isPlaying and not window('jellyfin.external_check'): time = player.getTime() if time > 1: # Not external player. window('jellyfin.external_check', value="true") window('jellyfin.external_count', value="0") elif count == 120: LOG.info("External player detected.") window('jellyfin.external.bool', True) window('jellyfin.external_check.bool', True) window('jellyfin.external_count', value="0") elif time == 0: window('jellyfin.external_count', value=str(count + 1))
def buildStation(self, data): station, opt = data stnum = station['number'] stname = station.get('name', '') images = station.get('images', []) if REAL_SETTINGS.getSettingBool('Use_Color_Logos'): try: chlogo = list( filter(lambda k: k.get('type', '') == 'colorLogoPNG', images))[0].get('url', LOGO) except: chlogo = LOGO else: try: chlogo = list( filter(lambda k: k.get('type', '') == 'logo', images))[0].get('url', LOGO) except: chlogo = LOGO try: chfanart = list( filter(lambda k: k.get('type', '') == 'logofeaturedImage', images))[0].get('url', FANART) except: chfanart = FANART category = self.getCatbyID(station.get('categoryID', '')) if category == 'Pluto TV': chlogo = LOGO chfanart = FANART favorite = isFavorite(stnum) channel = { "name": stname, "stream": "plugin://%s/play/pvr/%s" % (ADDON_ID, station.get('id', '')), "id": "%s.%s@%s" % (stnum, slugify(stname), slugify(ADDON_NAME)), "logo": (chlogo or LOGO), "preset": stnum, "group": [category, ADDON_NAME], "radio": False } if favorite: channel['group'].append(LANGUAGE(49012)) channel['group'] = ';'.join(channel['group']) if REAL_SETTINGS.getSettingBool('Build_Favorites') and not favorite: return None elif opt == 'channel': return channel else: programmes = {channel['id']: []} listings = station.get('timelines', []) for listing in listings: episode = listing.get('episode', {}) series = episode.get('series', {}) uri = episode.get('_id', '') try: starttime = strpTime(listing['start'], '%Y-%m-%dT%H:%M:%S.%fZ') except: continue try: aired = strpTime(episode['clip']['originalReleaseDate']) except: aired = starttime program = { "start": starttime.strftime(DTFORMAT), "stop": (starttime + datetime.timedelta(seconds=(int(episode['duration']) // 1000))).strftime(DTFORMAT), "title": self.cleanString(listing.get('title', channel['name'])), "description": self.cleanString( episode.get('description', '') or xbmc.getLocalizedString(161)), "subtitle": self.cleanString(episode.get('name', '')), "genre": episode.get('genres', ""), "image": (episode.get('poster', '') or episode.get('thumbnail', '') or episode.get('featuredImage', {})).get( 'path', chfanart), "date": aired.strftime('%Y-%m-%d'), "credits": "", "stream": 'plugin://%s/play/vod/%s' % (ADDON_ID, uri) } programmes[channel['id']].append(program) return programmes
def localizedString(id): if id < 30000: return xbmc.getLocalizedString(id) return _addon_.getLocalizedString(id)
def buildChannel(self, data): item, opt = data if not item.get('live', False) and opt in ['now']: return None chid = item['id'] chname = item['name'] chdesc = (item.get('description', '') or xbmc.getLocalizedString(161)) chlogo = (item.get('icon', '') or ICON) configValue = item.get('configValue', {}) latest = item.get('latest', {} or item) name = (latest.get('name', '' or chname)) if chname != name: label = '%s: [B]%s[/B]' % (chname, name) else: label = chname plot = (latest.get('description', '') or chdesc) url = (latest.get('streamUrl', '') or chid) thumb = (latest.get('thumbnailUrl', '') or chlogo) try: starttime = datetime.datetime.fromtimestamp( float(latest['startTime'])) endtime = datetime.datetime.fromtimestamp(float(latest['endTime'])) duration = (endtime - starttime).seconds except: duration = 0 infoLabel = { "mediatype": "video", "label": label, "title": label, "plot": plot, "duration": duration, "genre": ['News'] } infoArt = { "thumb": thumb, "poster": thumb, "fanart": self.getMAP((configValue.get('latitude', 'undefined'), configValue.get('longitude', 'undefined'))), "icon": chlogo, "logo": chlogo } if opt == 'local': infoArt['fanart'] = thumb if opt == 'channels': self.addDir(chname, (buildStation, chid), infoArt={ "thumb": chlogo, "poster": chlogo, "fanart": FANART, "icon": ICON, "logo": ICON }) return True else: self.addLink(label, (playURL, encodeString(url)), infoList=infoLabel, infoArt=infoArt) return True
def onInit(self): self.getControl(RESUME).setLabel(self._resume_point) self.getControl(START_BEGINNING).setLabel( xbmc.getLocalizedString(12021))
def buildStation(self, data): station, opt = data if station['active'] == False: return None label = (station.get('affiliateName', '') or station.get('affiliate', '') or station.get('callSign', '') or station.get('name', '')) stnum = re.sub('[^\d\.]+', '', label) stname = re.compile('[^a-zA-Z]').sub('', label) favorite = isFavorite(stnum) channel = { "name": stname, "stream": "plugin://%s/play/pvr/%s" % (ADDON_ID, station['id']), "id": "%s.%s@%s" % (stnum, slugify(stname), slugify(ADDON_NAME)), "logo": (station.get('logoUrl', '') or station.get('logo226Url', '') or ICON), "preset": stnum, "group": ADDON_NAME, "radio": False } #, # "kodiprops":{"inputstream":"inputstream.adaptive", # "inputstream.adaptive.manifest_type":"hls", # "inputstream.adaptive.media_renewal_url":"plugin://%s/play/pvr/%s"%(ADDON_ID,station['id']), # "inputstream.adaptive.media_renewal_time":"900"}} if favorite: channel['group'] = ';'.join([LANGUAGE(49012), ADDON_NAME]) if REAL_SETTINGS.getSettingBool('Build_Favorites') and not favorite: return None elif opt == 'channel': return channel else: programmes = {channel['id']: []} listings = station.get('listings', []) for listing in listings: try: starttime = datetime.datetime.fromtimestamp( int(str(listing['startTime'])[:-3])) + UTC_OFFSET except: continue try: aired = datetime.datetime.fromtimestamp( int(str(listing['airdate'])[:-3])) except: aired = starttime program = { "start": starttime.strftime(DTFORMAT), "stop": (starttime + datetime.timedelta(seconds=listing.get('duration', 0)) ).strftime(DTFORMAT), "title": listing.get('title', channel['name']), "description": (listing.get('description', '') or listing.get('shortDescription', '') or xbmc.getLocalizedString(161)), "subtitle": listing.get('episodeTitle', ''), "episode": "S%sE%s" % (str(listing.get('seasonNumber', 0)).zfill(2), str(listing.get('episodeNumber', 0)).zfill(2)), "genre": listing.get('genres', ""), "image": (listing.get('preferredImage', '') or channel['logo']), "date": aired.strftime('%Y-%m-%d'), "credits": "", "stream": "" } programmes[channel['id']].append(program) return programmes
def get_string(_id, kodi=False): if kodi: return six.text_type(xbmc.getLocalizedString(_id)) return six.text_type(_addon.getLocalizedString(_id))
def localized_string(id): if id < 30000: return xbmc.getLocalizedString(id) return addon.getLocalizedString(id)
def localizedString(id): if id < 30000: return xbmc.getLocalizedString(id) return xbmcaddon.Addon().getLocalizedString(id)
def buildPlayItem(self, data): content, opt = data channel = content['Channel'] programmes = content['Airings'] liveMatch = False if channel['Hidden'] == True: return tz = (timezone()//100)*60*60 now = (datetime.datetime.fromtimestamp(float(getLocalTime()))) + datetime.timedelta(seconds=tz) url = self.getLiveURL(channel['Number'], self.channels) for program in programmes: label = program.get('Title','') path = program.get('Path','') stop = (strpTime(program['Raw']['endTime'])) + datetime.timedelta(seconds=tz) start = (strpTime(program['Raw']['startTime']))+ datetime.timedelta(seconds=tz) if now > stop: continue elif now >= start and now < stop: if opt == 'live': if label: label = '%s| %s: [B]%s[/B]'%(channel['Number'],channel['Name'],program.get('Title','')) else: label = '%s| %s'%(channel['Number'],channel['Name']) liveMatch = True elif opt == 'lineup': label = '%s - [B]%s[/B]'%(start.strftime('%I:%M %p').lstrip('0'),program.get('Title','')) elif opt == 'live': continue elif opt == 'lineup': url = 'next_show' label = '%s - %s'%(start.strftime('%I:%M %p').lstrip('0'),program.get('Title','')) icon = channel.get('Image',ICON) thumb = program.get('Image',icon) info = {'label':label,'title':label,'duration':program.get('Duration',0),'genre':program.get('Genres',[]),'plot':program.get('Summary',xbmc.getLocalizedString(161)),'aired':program.get('OriginalDate','')} art = {'icon':icon, 'thumb':thumb} self.addLink(channel['Name'], url, '9', liz=self.buildItemListItem(label, url, info, art)) if liveMatch: break
def buildPlayItem(self, data): content, opt = data opt, favorites = opt channel = content['Channel'] programmes = content['Airings'] liveMatch = False if channel['Hidden'] == True: return elif favorites and not channel.get('Favorite', False): return tz = (timezone() // 100) * 60 * 60 now = (datetime.datetime.fromtimestamp(float( getLocalTime()))) + datetime.timedelta(seconds=tz) url = channel['Number'] for program in programmes: try: label = program.get('Title', '') path = program.get('Path', '') stop = (strpTime(program['Raw']['endTime']) ) + datetime.timedelta(seconds=tz) start = (strpTime(program['Raw']['startTime']) ) + datetime.timedelta(seconds=tz) if now > stop: continue elif now >= start and now < stop: if opt == 'live': if label: label = '%s| %s: [B]%s[/B]' % ( channel['Number'], channel['Name'], program.get('Title', '')) else: label = '%s| %s' % (channel['Number'], channel['Name']) liveMatch = True elif opt == 'lineup': label = '%s - [B]%s[/B]' % (start.strftime( '%I:%M %p').lstrip('0'), program.get('Title', '')) elif opt == 'live': continue elif opt == 'lineup': url = 'NEXT_SHOW' label = '%s - %s' % (start.strftime('%I:%M %p').lstrip( '0'), program.get('Title', '')) icon = channel.get('Image', ICON) thumb = program.get('Image', icon) info = { 'label': label, 'title': label, 'duration': program.get('Duration', 0), 'genre': program.get('Genres', []), 'plot': program.get('Summary', xbmc.getLocalizedString(161)), 'aired': program.get('OriginalDate', '') } art = { "thumb": thumb, "poster": thumb, "fanart": thumb, "icon": icon, "logo": icon } if opt == 'play': if start <= now and stop > now: info['duration'] = ((stop) - now).seconds self.addPlaylist(label, url, info, art) else: self.addLink(label, (playChannel, url), info, art, total=len(programmes)) if liveMatch: break except: pass
def buildStation(self, data): content, data = data channels, opt = data station = content['Channel'] cdata = list( filter(lambda c: c['number'] == station['Number'], channels))[0] favorite = 'Favorites' in cdata['groups'] cdata['groups'].append(ADDON_NAME) channel = { "name": station['Name'], "stream": "plugin://%s/play/pvr/%s" % (ADDON_ID, station['Number']), "id": "%s.%s@%s" % (station['Number'], slugify(station['Name']), slugify(ADDON_NAME)), "logo": (station.get('Image', '') or LOGO), "preset": station['Number'], "group": ';'.join(cdata['groups']), "radio": False } if REAL_SETTINGS.getSettingBool('Build_Favorites') and not favorite: return None elif opt == 'channel': return channel else: programmes = {channel['id']: []} listings = content.get('Airings', []) for listing in listings: try: starttime = strpTime(listing['Raw']['startTime']) except: continue try: aired = strpTime(listing['OriginalDate'], '%Y-%m-%d') except: aired = starttime program = { "start": starttime.strftime(DTFORMAT), "stop": (starttime + datetime.timedelta(seconds=listing.get('Duration', 0)) ).strftime(DTFORMAT), "title": listing.get('Title', channel['name']), "description": (listing.get('Summary', '') or xbmc.getLocalizedString(161)), "subtitle": listing.get('EpisodeTitle', ''), "genre": listing.get('Categories', []), "image": (listing.get('Image', '') or channel['logo']), "date": aired.strftime('%Y-%m-%d'), "credits": "", "stream": "" } if listing.get('SeasonNumber', 0) > 0 and listing.get( 'EpisodeNumber', 0) > 0: program["episode"] = "S%sE%s" % ( str(listing.get('SeasonNumber', 0)).zfill(2), str(listing.get('EpisodeNumber', 0)).zfill(2)) programmes[channel['id']].append(program) return programmes
def buildPlayItem(self, data): content, opt = data opt, favorites = opt channel = content['Channel'] programmes = content['Airings'] liveMatch = False if channel.get('Hidden', False) == True: return elif favorites and not channel.get('Favorite', False): return tz = (timezone() // 100) * 60 * 60 now = (datetime.datetime.fromtimestamp(float( getLocalTime()))) + datetime.timedelta(seconds=tz) url = channel['Number'] for program in programmes: #todo add support for custom and virtual channels, no starttimes create on the fly # [{ # 'Airings': [{ # 'Source': 'virtual/file/16870', # 'Channel': '10001', # 'OriginalDate': '2009-11-13', # 'Time': 1627070757, # 'Duration': 2556, # 'Title': 'Monk', # 'EpisodeTitle': 'Mr. Monk Is the Best Man', # 'Summary': 'Monk attempts to save the wedding of someone close to him by learning who is trying to sabotage it.', # 'FullSummary': 'Monk attempts to save the wedding of someone close to him by finding out who is trying to sabotage it and why.', # 'Image': 'http://tmsimg.fancybits.co/assets/p184807_b_h6_ag.jpg', # 'Categories': ['Episode', 'Series'], # 'Genres': ['Crime drama', 'Comedy'], # 'Tags': ['Stereo'], # 'SeriesID': '184807', # 'ProgramID': 'EP005116510129', # 'SeasonNumber': 8, # 'EpisodeNumber': 13, # 'Directors': ['Michael Zinberg'], # 'Cast': ['Tony Shalhoub', 'Ted Levine', 'Traylor Howard'], # 'ReleaseYear': 2009, # 'Raw': None # }], # 'Channel': { # 'HD': True, # 'Hidden': False, # 'Image': 'https://upload.wikimedia.org/wikipedia/commons/thumb/9/91/Logo_Monk.svg/1200px-Logo_Monk.svg.png', # 'Name': 'Monk 24/7', # 'Number': '10001' # } # }] try: label = program.get('Title', '') path = program.get('Path', '') stop = (strpTime(program['Raw']['endTime']) ) + datetime.timedelta(seconds=tz) start = (strpTime(program['Raw']['startTime']) ) + datetime.timedelta(seconds=tz) if now > stop: continue elif now >= start and now < stop: if opt == 'live': if label: label = '%s| %s: [B]%s[/B]' % ( channel['Number'], channel.get('Name', channel.get('CallSign')), program.get('Title', '')) else: label = '%s| %s' % ( channel['Number'], channel.get('Name', channel.get('CallSign'))) liveMatch = True elif opt == 'lineup': label = '%s - [B]%s[/B]' % (start.strftime( '%I:%M %p').lstrip('0'), program.get('Title', '')) elif opt == 'live': continue elif opt == 'lineup': url = 'NEXT_SHOW' label = '%s - %s' % (start.strftime('%I:%M %p').lstrip( '0'), program.get('Title', '')) icon = channel.get('Image', LOGO) thumb = program.get('Image', icon) info = { 'label': label, 'title': label, 'duration': program.get('Duration', 0), 'genre': program.get('Genres', []), 'plot': program.get('Summary', xbmc.getLocalizedString(161)), 'aired': program.get('OriginalDate', '') } art = { "thumb": thumb, "poster": thumb, "fanart": thumb, "icon": icon, "logo": icon } if opt == 'play': if start <= now and stop > now: info['duration'] = ((stop) - now).seconds self.addPlaylist(label, url, info, art) else: self.addLink(label, (playChannel, url), info, art, total=len(programmes)) if liveMatch: break except: pass
def buildChannelListItem(self, tunerkey, channel, item=None, opt='live'): self.setDevice(tunerkey) info = self.getChannelInfo(channel) if info is None: return None elif info.getDRM(): return None elif info.getTuner().getDeviceID() != tunerkey: return None favorite = info.getFavorite() == 1 chname = (info.getAffiliate() or info.getGuideName() or info.getGuideNumber() or 'N/A') tuner = info.getTuner() if opt == 'favorites' and not favorite: return None video = {'codec':''} audio = {'codec':''} if tuner.getModelNumber() == "HDTC-2US": if self.transcode == 'default': tranOPT = (tuner.getTranscodeOption() or 'none') else: tranOPT = self.transcode if tranOPT != "none": video['codec'] = 'h264' else: if info.getVideoCodec() == "H264": video['codec'] = 'h264' if info.getAudioCodec() == "AAC": if tuner.getModelNumber() == "HDHR4-2DT": audio['codec'] = 'aac_latm' else: audio['codec'] = 'aac' elif info.getAudioCodec() == "MPEG": audio['codec'] = 'mp2' if info.getHD() == 1: video['width'] = 1080 video['aspect'] = "1.78" if video['codec'] == 'mpeg2video' or video['codec'] == 'mpeg1video': audio['bitrate'] = 13000 else: audio['bitrate'] = 4000 else: if video['codec'] == 'mpeg2video' or video['codec'] == 'mpeg1video': audio['bitrate'] = 4000 else:audio['bitrate'] = 1500 chlogo = (info.getImageURL() or ICON) chnum = channel path = chnum video = {"codec":'mpeg2video',"width":480,"aspect":"1.33"} audio = {"codec":'ac3',"bitrate":1500} label = '%s| %s'%(chnum,chname) if item is not None: if item.getEpisodeTitle(): title = '%s - %s'%(item.getTitle(), item.getEpisodeTitle()) else: title = (item.getTitle() or '') if item.getSynopsis(): plot = (item.getSynopsis() or xbmc.getLocalizedString(161)) else: plot = xbmc.getLocalizedString(161) if opt == 'searchRecorded': title = '%s (%s)'%(title,LANGUAGE(30116)) elif opt == 'searchWhatsOn': title = '%s (%s)'%(title,LANGUAGE(30117)) elif opt == 'search': title = '%s (%s)'%(title,LANGUAGE(30118)) thumb = (item.getImageURL() or chlogo) now = datetime.datetime.now() starttime = datetime.datetime.fromtimestamp(float(item.getStartTime())) endtime = datetime.datetime.fromtimestamp(float(item.getEndTime())) runtime = (endtime - starttime).seconds try: aired = datetime.datetime.fromtimestamp(float(item.getOriginalAirdate())) except: aired = starttime if opt in ['live','favorites']: chname = '%s| %s'%(channel,chname) label = '%s : [B] %s[/B]'%(chname, title) elif opt in ['lineup','vod']: if now >= starttime and now < endtime: label = '%s - [B]%s[/B]'%(starttime.strftime('%I:%M %p').lstrip('0'),title) else: path = 'NEXT_SHOW' label = '%s - %s'%(starttime.strftime('%I:%M %p').lstrip('0'),title) elif opt == 'show': label = title else: label = '%s: %s - [B]%s[/B]'%(starttime.strftime('%I:%M %p').lstrip('0'),chname,title) try: mtype = MTYPES[item.getEpisodeNumber()[:2]] except: mtype = 'episode' infoLabels = {"favorite":favorite,"chnum":chnum,"chname":chname,"mediatype":mtype,"label":label,"title":label,'duration':runtime,'plot':plot,"aired":aired.strftime('%Y-%m-%d')} infoArt = {"thumb":thumb,"poster":thumb,"fanart":FANART,"icon":chlogo,"logo":chlogo} else: label = '%s| %s'%(chnum,chname) infoLabels = {"mediatype":"episode" ,"label":label,"title":label} infoArt = {"thumb":chlogo,"poster":chlogo,"fanart":FANART,"icon":chlogo,"logo":chlogo} if opt in ['live','favorites','lineup']: self.addLink(label, (playChannel,tunerkey,path), infoList=infoLabels, infoArt=infoArt, infoVideo=video, infoAudio=audio) elif opt == 'play': if starttime <= now and endtime > now: infoLabels['duration'] = ((endtime) - now).seconds self.addPlaylist(label, path, infoLabels, infoArt, video, audio) elif opt in ['channels']: self.addDir(label,(getLineup,tunerkey,chnum), infoList=infoLabels, infoArt=infoArt, infoType='video') elif opt == 'show': self.addDir(label,(getSeries,tunerkey,item.getSeriesID()), infoList=infoLabels, infoArt=infoArt, infoVideo=video, infoAudio=audio) elif opt == 'vod': self.addLink(label,(playVOD,tunerkey,prog.getPlayURL()), infoList=infoLabels, infoArt=infoArt, infoVideo=video, infoAudio=audio) else: self.addLink(label,(playChannel,tunerkey,path), infoList=infoLabels, infoArt=infoArt, infoVideo=video, infoAudio=audio)
def buildBroadcasts(self, channel, broadcasts, opt=''): log('buildBroadcasts, channel = %s, opt = %s' % (channel.get('id'), opt)) id = channel.get('id') hls = channel.get('hls', False) name = channel.get('name') number = channel.get('number') category = channel.get('category') favorite = isFavorite(number) programmes = {id: []} now = datetime.datetime.now().astimezone().replace(microsecond=0) for idx, broadcast in enumerate(broadcasts): """{ 'id': 3092301, 'title': 'Mankind From Space', 'parts': [{ 'duration': 2617, 'source_url': 'https://ia801605.us.archive.org/12/items/National.GeographicAlien.Earths2009.720p.AC3_201702/National.Geographic%20-%20Mankind.From.Space%20-%202015.720p.AAC.mp4', 'start_at_iso': '2021-03-18T14:35:24-04:00' }], 'description': "Trace humankind's long journey from hunter-gatherer to dominant global species. From the perspective of space, this two-hour special uses mind-boggling data and CGI to disclose the breathtaking extent of humanity's influence, revealing how we've transformed our planet and produced an interconnected world of extraordinary complexity. A trip through 12,000 years of development, the documentary shows how seemingly small flashes of innovation - innovations that touch all of us in ways unimaginable to our ancestors - have changed the course of civilization. As our global population soars, the program considers the challenges humanity will face in order to survive.", 'view_duration': 1141, 'stream_duration': 2617, 'view_start_at_iso': '2021-03-18T15:00:00-04:00', 'stream_start_at_iso': '2021-03-18T14:35:24-04:00' }""" """{ 'id': 3121442, 'title': 'Fishing Offshore', 'description': 'Fishing Offshore', 'view_duration': 1391, 'stream_duration': 2700, 'view_start_at_iso': '2021-03-24T18:00:00-04:00', 'stream_start_at_iso': '2021-03-24T17:38:11-04:00' }""" try: starttime = strpTime(broadcast['stream_start_at_iso']) except: continue offsettime = strpTime(broadcast.get('view_start_at_iso')) remaining = (broadcast.get('view_duration', 0)) duration = (broadcast.get('stream_duration', '') or remaining) stoptime = (starttime + datetime.timedelta(seconds=duration)) epid = (broadcast.get('id')) title = (broadcast.get('title') or name) plot = (broadcast.get('description') or xbmc.getLocalizedString(161)) parts = (broadcast.get('parts', [])) for part in parts: runtime = (part.get('duration', 0)) stream = (part.get('source_url')) start = strpTime(part.get('start_at_iso')) if hls: uri = (playLive, id) else: uri = (playVOD, id, epid) if opt == 'iptv_broadcasts': program = { "start": starttime.strftime(DTFORMAT), "stop": stoptime.strftime(DTFORMAT), "title": title, "description": plot, "subtitle": "", "episode": "", "genre": category, "image": FANART, "date": starttime.strftime('%Y-%m-%d'), "credits": "", "stream": "plugin://%s/play/vod/%s/%s" % (ADDON_ID, id, epid) } programmes[id].append(program) elif opt in ['live', 'favorites', 'broadcast']: chname = '%s| %s' % (number, name) label = '%s : [B] %s[/B]' % (chname, title) if opt == 'favorites' and not favorite: return None if now >= starttime and now < stoptime: if opt == 'broadcast': return broadcast return self.addLink(label, uri, infoList={ "favorite": favorite, "chnum": number, "chname": name, "mediatype": "video", "label": label, "title": label }, infoArt={ 'thumb': LOGO_URL % (name), 'fanart': FANART }) elif opt == 'lineup': if stoptime < now: continue elif now >= starttime and now < stoptime: label = '%s - [B]%s[/B]' % ( starttime.strftime('%I:%M %p').lstrip('0'), title) else: label = '%s - %s' % ( starttime.strftime('%I:%M %p').lstrip('0'), title) uri = list(uri) if hls: uri[1] = 'NEXT_SHOW' uri = tuple(uri) self.addLink(label, uri, infoList={ "favorite": favorite, "chnum": number, "chname": name, "mediatype": "video", "label": label, "title": label }, infoArt={ 'thumb': LOGO_URL % (name), 'fanart': FANART }) return programmes
def buildListings(self, listings, chname, chlogo, path, opt=''): log('buildListings, chname = %s, opt = %s' % (chname, opt)) now = self.now listings = sorted(listings, key=lambda k: k['startTime']) for listing in listings: try: starttime = self.getDateTime( int(str(listing['startTime'])[:-3])) except: continue duration = listing.get('duration', 0) endtime = starttime + datetime.timedelta(seconds=duration) title = listing['title'] favorite = None chnum = -1 # if listing['isNew']: label = '*%s'%label try: aired = self.getDateTime(int(str(listing['airdate'])[:-3])) except: aired = starttime try: type = {'Series': 'episode'}[listing.get('showType', 'Series')] except: type = 'video' plot = (listing.get('description', '') or listing.get('shortDescription', '') or xbmc.getLocalizedString(161)) if now > endtime: continue chlabel = chname chnum = re.compile('[^\d\.]+').sub('', chname) if chnum: favorite = isFavorite(self.dma, chnum) chname = re.compile('[^a-zA-Z]').sub('', chname) chlabel = '%s| %s' % (chnum, chname) if opt == 'favorites' and not favorite: continue elif opt in ['live', 'favorites']: label = '%s : [B] %s[/B]' % (chlabel, title) elif opt in ['lineup', 'play']: if now >= starttime and now < endtime: label = '%s - [B]%s[/B]' % (self.getDateTimeUTC( int(str(listing['startTime'])[:-3])).strftime( '%I:%M %p').lstrip('0'), title) else: label = '%s - %s' % (self.getDateTimeUTC( int(str(listing['startTime'])[:-3])).strftime( '%I:%M %p').lstrip('0'), title) path = 'NEXT_SHOW' else: label = chlabel thumb = (listing.get('preferredImage', '') or chlogo) infoLabels = { "favorite": favorite, "chnum": chnum, "chname": chname, "mediatype": type, "label": label, "title": label, 'duration': duration, 'plot': plot, 'genre': listing.get('genres', []), "aired": aired.strftime('%Y-%m-%d') } infoArt = { "thumb": thumb, "poster": thumb, "fanart": FANART, "icon": chlogo, "logo": chlogo } infoVideo = { } #todo added more meta from listings, ie mpaa, isNew, video/audio codec infoAudio = { } #todo added more meta from listings, ie mpaa, isNew, video/audio codec if type == 'episode' and opt != 'play': infoLabels['tvshowtitle'] = listing.get('title', '') if listing.get('seasonNumber', None): infoLabels['season'] = listing.get('seasonNumber', 0) infoLabels['episode'] = listing.get('episodeNumber', 0) seaep = '%sx%s' % ( str(listing.get('seasonNumber', '')).zfill(2), str(listing.get('episodeNumber', '')).zfill(2)) label = '%s - %s %s' % (label, seaep, listing.get('episodeTitle', '')) else: label = '%s %s' % (label, listing.get('episodeTitle', '')) infoLabels['title'] = label infoLabels['label'] = label if opt in ['live', 'favorites']: if now >= starttime and now < endtime: return self.addLink(label, (playChannel, path), infoLabels, infoArt, infoVideo, infoAudio, total=len(listings)) else: continue elif opt == 'play': if starttime <= now and endtime > now: infoLabels['duration'] = ((endtime) - now).seconds self.addPlaylist(label, path, infoLabels, infoArt, infoVideo, infoAudio) else: self.addLink(label, (playChannel, path), infoLabels, infoArt, infoVideo, infoAudio, total=len(listings))