def getChannels(self, _url, channel_url, fetched_channels): response = urllib2.urlopen(channel_url) data = json.load(response) channels = [] if 'entries' in data: for entry in data['entries']: if any( d.get('title', None) == entry['title'] for d in fetched_channels): #fetched_channel = [item for item in fetched_channels if item.get('title', None) == entry['title']] fetched_channel = next( (x for x in fetched_channels if x.get('title', None) == entry['title']), None) if 'channel_logo-100x100' in entry['thumbnails']: icon = entry['thumbnails']['channel_logo-100x100'][ 'url'] else: icon = 'DefaultVideo.png' title = entry['title'] url = utils.get_url(_url, action='play', type='live', channel=self.__class__.__name__, callSign=entry['callSign']) epg = fetched_channel.get('epg', None) lcn = fetched_channel.get('lcn', None) channel = Channel(icon, title, url, lcn, epg) channels.append(channel) return channels
def list_livestreams(): xbmcplugin.setPluginCategory(PLUGIN_HANDLE, 'Livestreams') xbmcplugin.setContent(PLUGIN_HANDLE, 'videos') parser = ChannelParser() for video in parser.parse_all_current_live(): duration = (int(video.end_date) - int(video.start_date)) / 1000 premiered = time.strftime('%Y-%m-%d', time.localtime(int(video.start_date) / 1000)) channel = Channel.get_by_id(video.channel_id) list_item = xbmcgui.ListItem(label=channel['name']) list_item.setInfo( 'video', { 'title': channel['name'], 'genre': 'Livestream', 'duration': duration, 'premiered': premiered, 'plotoutline': video.title, 'plot': video.title, 'mediatype': 'movie' }) poster_file = "poster_cgtn_{}.png".format(channel['prefix']) poster = os.path.join(Config.mediaDir, poster_file) list_item.setArt({'poster': poster, 'fanart': Config.fanart}) list_item.setProperty('IsPlayable', 'true') # plugin://plugin.video.cgtn/?action=play&video=httpx://example.com/dummy.m3u8 url = get_url(action='play', video=video.video_url) xbmcplugin.addDirectoryItem(handle=PLUGIN_HANDLE, url=url, listitem=list_item, isFolder=False) xbmcplugin.addSortMethod(PLUGIN_HANDLE, xbmcplugin.SORT_METHOD_NONE) xbmcplugin.endOfDirectory(PLUGIN_HANDLE)
def list_newscategories_en(channel_key): xbmcplugin.setPluginCategory(PLUGIN_HANDLE, 'News Categories') xbmcplugin.setContent(PLUGIN_HANDLE, 'videos') parser = NewsCategoryParser categories = parser.parse_categories() for category in categories: list_item = xbmcgui.ListItem(label=category.name, iconImage='DefaultFolder.png') list_item.setInfo('video', { 'title': category.name, 'genre': category.name, 'mediatype': 'video' }) poster_file = "poster_cgtn_{}.png".format( Channel.get_by_key(channel_key)['prefix']) poster = os.path.join(Config.mediaDir, poster_file) list_item.setArt({'poster': poster, 'fanart': Config.fanart}) # plugin://plugin.video.cgtn/?action=listing&newschannel=en& # newscategory=https://www.cgtn.com/nature&hassubs=True url = get_url(action='listing', newschannel=channel_key, newscategory=category.url, hassubs=category.has_subcatagories) xbmcplugin.addDirectoryItem(handle=PLUGIN_HANDLE, url=url, listitem=list_item, isFolder=True) xbmcplugin.addSortMethod(PLUGIN_HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.endOfDirectory(PLUGIN_HANDLE)
def list_news_channels(): xbmcplugin.setPluginCategory(PLUGIN_HANDLE, 'News') xbmcplugin.setContent(PLUGIN_HANDLE, 'videos') for channel in Channel.get_all()[:-1]: list_item = xbmcgui.ListItem(label=channel['name'], iconImage='DefaultFolder.png') list_item.setInfo( 'video', { 'title': channel['name'], 'genre': channel['name'], 'mediatype': 'video' }) poster_file = "poster_cgtn_{}.png".format(channel['prefix']) poster = os.path.join(Config.mediaDir, poster_file) list_item.setArt({'poster': poster, 'fanart': Config.fanart}) # plugin://plugin.video.cgtn/?action=listing&newschannel=en|sp|fr|ar|ru url = get_url(action='listing', newschannel=channel['key']) xbmcplugin.addDirectoryItem(handle=PLUGIN_HANDLE, url=url, listitem=list_item, isFolder=True) xbmcplugin.addSortMethod(PLUGIN_HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.endOfDirectory(PLUGIN_HANDLE)
def select_channel(self): for ch in Channel().getList(): name = ch['name'] id = ch['id'] if self.args.get('g0') is None: mode = 'selectGenre' elif self.args.get('sdate') is None: mode = 'selectDate' else: mode = 'search' query = '%s&%s' % (self.query, urlencode({'ch': id})) self.add_directory_item(name, query, mode, iconimage=Common.RADIO_TOWER) # end of directory xbmcplugin.endOfDirectory(int(sys.argv[1]))
def beginEdit(self, name, ch, g0, g1): if ch: # keyword Common.SET('keyword', name) # channel channel = Channel().search(ch) Common.SET('channel', channel['name']) # genre genre = Genre().search(g0, g1) Common.SET('g0', genre['name0']) Common.SET(genre['id'], genre['name1']) else: # スマートリストでtitleが一致するものをダイアログに設定 for item in filter(lambda x: x['title'] == name, self.getList()): for key, val in item.items(): Common.SET(key, val)
def initializeChannel(): # リセット Common.SET('garapon_ch', '') # チャンネル情報を取得 response_body = Request().channel() if response_body: response_data = json.loads(response_body) if response_data['status'] == 1: # チャンネル情報をファイルに書き出す Common.write_json(Common.CHANNEL_FILE, response_data) # チャンネル数を設定 Common.SET('garapon_ch', '%d channels' % len(response_data['ch_list'].keys())) # 設定画面のテンプレートを読み込む template = Common.read_file(Common.TEMPLATE_FILE) # テンプレートに書き出すジャンル情報 genre = Genre().getLabel() # チャンネル情報とあわせてテンプレートに適用 source = template.format( channel=Channel().getLabel(), g0=genre['g0'], g00=genre['g00'], g01=genre['g01'], g02=genre['g02'], g03=genre['g03'], g04=genre['g04'], g05=genre['g05'], g06=genre['g06'], g07=genre['g07'], g08=genre['g08'], g09=genre['g09'], g10=genre['g10'], g11=genre['g11'] ) # 設定画面をファイルに書き出す Common.write_file(Common.SETTINGS_FILE, source) # 完了 Common.notify('Channel initialized successfully') return True else: Common.log('channel failed', response_body, error=True) Common.notify('Channel initialization failed') return False else: Common.log('empty response', error=True) Common.notify('Channel initialization failed') return False
def list_newssections_other(channel_key): xbmcplugin.setPluginCategory(PLUGIN_HANDLE, 'News Sections') xbmcplugin.setContent(PLUGIN_HANDLE, 'videos') sections = [] if channel_key == "sp": sections = SectionSP.get_all() elif channel_key == "fr": sections = SectionFR.get_all() elif channel_key == "ar": sections = SectionAR.get_all() elif channel_key == "ru": sections = SectionRU.get_all() for section in sections: list_item = xbmcgui.ListItem(label=section['name'], iconImage='DefaultFolder.png') list_item.setInfo( 'video', { 'title': section['name'], 'genre': section['name_en'], 'mediatype': 'video' }) poster_file = "poster_cgtn_{}.png".format( Channel.get_by_key(channel_key)['prefix']) poster = os.path.join(Config.mediaDir, poster_file) list_item.setArt({'poster': poster, 'fanart': Config.fanart}) # plugin://plugin.video.cgtn/?action=listing&newschannel=en|sp|fr|ar|ru url = get_url(action='listing', newschannel=channel_key, section=section['id']) xbmcplugin.addDirectoryItem(handle=PLUGIN_HANDLE, url=url, listitem=list_item, isFolder=True) xbmcplugin.addSortMethod(PLUGIN_HANDLE, xbmcplugin.SORT_METHOD_LABEL_IGNORE_THE) xbmcplugin.endOfDirectory(PLUGIN_HANDLE)
def getChannels(self, _url, channel_url, fetched_channels): channels = [] fetched_channel = next( (x for x in fetched_channels if x.get('title', None) == 'DMAX'), None) title = 'DMAX' icon = self.noThumbUrl url = utils.get_url(_url, action='play', type='live', channel=self.__class__.__name__, callSign=channel_url) epg = fetched_channel.get('epg', None) lcn = fetched_channel.get('lcn', None) channel = Channel(icon, title, url, lcn, epg) channels.append(channel) return channels
def getChannels(self, _url, channel_url, fetched_channels): data = json.load(urllib2.urlopen(channel_url)) channels = [] if 'streaming_url' in data: if any(d.get('title', None) == 'Cielo' for d in fetched_channels): fetched_channel = next((x for x in fetched_channels if x.get('title', None) == 'Cielo'), None) title = 'Cielo' url = utils.get_url(_url, action='play', type='live', channel=self.__class__.__name__, callSign=data["streaming_url"]) epg = fetched_channel.get('epg', None) lcn = fetched_channel.get('lcn', None) icon = fetched_channel.get('icon', None) channel = Channel(icon, title, url, lcn, epg) channels.append(channel) return channels
def endEdit(self): # 既存のスマートリストからqueryが一致するものを削除 query = self.settings.get('query') smartlist = list(filter(lambda x: x['query'] != query, self.getList())) # ダイアログの設定を取得 source = self.settings.get('source') keyword = self.settings.get('keyword') # channel str2 = self.settings.get('channel') channel = Channel().search(str2) # genre str0 = self.settings.get('g00') genre = Genre().search(str0) str1 = self.settings.get(genre['id']) genre = Genre().search(str0, str1) # query args = { 'n': Common.ITEMS, 'p': 1, 'video': 'all', 'key': keyword, 's': ['e', 'c'][int(source)], 'ch': channel['id'], 'g0': genre['id0'], 'g1': genre['id1'] } # データを追加 data = { 'title': keyword, 'query': urlencode(args), 'channel': str2, 'source': source, 'keyword': keyword } if genre['id0']: data['g0'] = str0 if genre['id1']: data[genre['id']] = str1 smartlist.append(data) # ファイルに書き込む self.setList(smartlist)
def getChannels(self, _url, channel_url, fetched_channels): data = json.load(urllib2.urlopen(channel_url)) channels = [] if 'dirette' in data: for entry in data['dirette']: if any( d.get('title', None) == entry['channel'] for d in fetched_channels): fetched_channel = next( (x for x in fetched_channels if x.get('title', None) == entry['channel']), None) icon = self.getThumbnailUrl(entry["transparent-icon"]) title = entry["channel"] url = utils.get_url(_url, action='play', type='live', channel=self.__class__.__name__, callSign=entry["video"]["contentUrl"]) epg = fetched_channel.get('epg', None) lcn = fetched_channel.get('lcn', None) channel = Channel(icon, title, url, lcn, epg) channels.append(channel) return channels
# アドオン設定をコピー settings = {} if not os.path.isfile(Common.SETTINGS_FILE): # settings.xmlがない場合はテンプレートをコピーする shutil.copyfile(Common.TEMPLATE_FILE, Common.SETTINGS_FILE) else: for id in ['keyword', 'query']: settings[id] = Common.GET(id) Common.SET(id, '') for id in ['source']: settings[id] = Common.GET(id) Common.SET(id, '0') for id in ['channel']: settings[id] = Common.GET(id) Common.SET(id, Channel().getDefault()) for id in [ 'g0', 'g00', 'g01', 'g02', 'g03', 'g04', 'g05', 'g06', 'g07', 'g08', 'g09', 'g10', 'g11' ]: settings[id] = Common.GET(id) Common.SET(id, Genre().getDefault(id)) # キャッシュサイズが未設定の場合は設定 if Common.GET('cache') == '': Cache().update() # 各種処理 if mode == '': # 必須設定をチェック if checkSettings():