def play_channel(category_id, channel_id): """ Plays selected song :param category_id: Selected category ID :param channel_id: Selected channel ID :return: """ api = API() user = User() is_authenticated = user.authenticate() recent_tracks_url = '' channel = [ item for item in api.get_channels(int(category_id)) if item['id'] == int(channel_id) ][0] url = api.get_streaming_url(channel['streams'], user.username, user.token, user.is_authenticated()) if is_authenticated: recent_tracks_url = channel['recent_tracks']['vip'] elif 'free' in channel['recent_tracks']: recent_tracks_url = channel['recent_tracks']['free'] # is there a valid URL for channel? if url: url = quote(url, safe=':/?=@') li = ListItem(channel['title'], channel['description'], channel['image']) li.setArt({ 'thumb': '{0}/{1}'.format(config['urls']['calm_arts_host'], channel['image']), 'fanart': '{0}{1}'.format(config['urls']['calm_blurred_arts_host'], channel['image']) }) li.setInfo( 'music', { 'Title': channel['title'].replace('CALM RADIO -', '').title(), 'Artist': channel['description'] }) li.setProperty('mimetype', 'audio/mpeg') li.setProperty('IsPlayable', 'true') li.setInfo( 'music', {'Title': channel['title'].replace('CALM RADIO -', '').title()}) Player().play(item=url, listitem=li) log('Playing url: {0}'.format(url)) update_artwork(channel, recent_tracks_url) else: # members only access dialog = Dialog() ret = dialog.yesno(ADDON.getLocalizedString(32200), ADDON.getLocalizedString(32201)) if ret == 1: ADDON.openSettings()
def play_channel(category_id, channel_id): """ Plays selected song :param category_id: Selected category ID :param channel_id: Selected channel ID :return: """ api = API() user = User() is_authenticated = user.authenticate() recent_tracks_url = '' channel = [item for item in api.get_channels(int(category_id)) if item['id'] == int(channel_id)][0] url = api.get_streaming_url(channel['streams'], user.username, user.token, user.is_authenticated()) if is_authenticated: recent_tracks_url = channel['recent_tracks']['vip'] elif 'free' in channel['recent_tracks']: recent_tracks_url = channel['recent_tracks']['free'] # is there a valid URL for channel? if url: url = quote(url, safe=':/?=@') li = ListItem(channel['title'], channel['description'], channel['image']) li.setArt({'thumb': '{0}/{1}'.format(config['urls']['calm_arts_host'], channel['image']), 'fanart': '{0}{1}'.format(config['urls']['calm_blurred_arts_host'], channel['image'])}) li.setInfo('music', {'Title': channel['title'].replace('CALM RADIO -', '').title(), 'Artist': channel['description']}) li.setProperty('mimetype', 'audio/mpeg') li.setProperty('IsPlayable', 'true') li.setInfo('music', { 'Title': channel['title'].replace('CALM RADIO -', '').title() }) Player().play(item=url, listitem=li) log('Playing url: {0}'.format(url)) update_artwork(channel, recent_tracks_url) else: # members only access dialog = Dialog() ret = dialog.yesno(ADDON.getLocalizedString(32200), ADDON.getLocalizedString(32201)) if ret == 1: ADDON.openSettings()
def yes_no_dialog(cls, title, message): dialog = Dialog() result = dialog.yesno(title, message) return result
def setup_player(playable_obj): timeout = 30 failure = False if hasattr(playable_obj, 'streams') and hasattr(playable_obj, 'get_play_head'): dialog = Dialog() stream = session.get_cms(playable_obj.streams) playhead = playable_obj.get_play_head(session) if playhead and not playhead.completion_status: timestamp = format_time(playhead.position) res = dialog.yesno('Resume Playback', 'Do you want to resume playback at {}?'.format(timestamp)) if res: last_pos = playhead.position else: last_pos = -1 else: last_pos = -1 if not adaptive: # notify the user because the adaptive stream workaround takes a few seconds dialog.notification("VRV", "Starting stream...", time=1000, sound=False) li = ListItem(playable_obj.title) if playable_obj.media_type == "episode": li.setLabel2(str(playable_obj.episode_number)) art_cache = cache_art(playable_obj.images.kodi_setart_dict()) try: parent_ac = get_parent_art(playable_obj) except: parent_ac = None li.setArt(art_cache) if parent_ac: li.setArt({'fanart': parent_ac.get('fanart')}) li.setInfo('video', playable_obj.kodi_info()) if adaptive: # set properties required for inputstream adaptive li.setProperty('inputstreamaddon', 'inputstream.adaptive') li.setProperty('inputstream.adaptive.manifest_type', 'hls') li.setMimeType('application/dash+xml') li.setContentLookup(False) player = xbmc.Player() my_log("Setting up player object. PlayHead position is %s." % (last_pos), xbmc.LOGDEBUG) if stream.en_subtitle: li.setSubtitles([stream.en_subtitle.url]) player.play(prepstream(stream.hls), li, False, last_pos) tried_seek = False my_log("Told Kodi to play stream URL. Now we wait...", xbmc.LOGDEBUG) loops = 0 # wait for kodi to start playing while not player.isPlaying(): xbmc.sleep(1000) loops += 1 if loops > timeout: dialog.notification("VRV", "Failed to play stream. Check config?", icon=xbmcgui.NOTIFICATION_ERROR, time=5000) failure = True break current_pos = 0 # main polling loop. it's probably not the most elegant/efficient way, but it works while player.isPlaying(): """ if user chose to resume, tell the player to seek it's supposed to, per the docs, to do this in the player.play call, but due to a bug or my ignorance, it doesn't. so we force its hand here TODO: this seems to break sync with subtitles. """ if not tried_seek and last_pos > 0: my_log("Trying to get Kodi to seek to %s." % (last_pos), xbmc.LOGDEBUG) player.seekTime(float(last_pos)) xbmc.sleep(1000) # wait for kodi to response current_pos = int(player.getTime()) tried_seek = (current_pos >= last_pos) current_pos = int(player.getTime()) # just get the current playback position and sleep xbmc.sleep(2000) # stopped playback (hopefully), so update our position on the server if not failure: playable_obj.post_play_head(session, current_pos) my_log("Done playing.", xbmc.LOGDEBUG) else: my_log("Error(s) encountered while trying to play stream.", xbmc.LOGERROR) if adaptive: my_log("InputStream Adaptive is possibly not installed or configured?", xbmc.LOGERROR)