def hourly(): # Clean up cache for network in addict.NETWORKS.keys(): utils.logd('Invalidating cache for {}'.format(network)) aa = addict.AudioAddict.get(PROFILE_DIR, network) aa.invalidate_cache() # Update user information (like premium status etc.) utils.logd('Updating user information') aa = addict.AudioAddict.get(PROFILE_DIR, main.TEST_LOGIN_NETWORK) aa.get_member_session()
def onSettingsChanged(self): addon = xbmcaddon.Addon() if addon.getSettingInt('aa.quality') != self._quality: utils.logd('Quality setting changed.') quality_id = utils.get_quality_id(main.TEST_LOGIN_NETWORK) for network in addict.NETWORKS.keys(): aa = addict.AudioAddict(PROFILE_DIR, network) if aa.is_premium: utils.logd('Updating preferred quality for:', network) aa.preferred_quality(quality_id) self._quality = addon.getSettingInt('aa.quality')
def run(): url = sys.argv[0] + sys.argv[2] utils.logd(HANDLE, url) aa = addict.AudioAddict.get(PROFILE_DIR, TEST_LOGIN_NETWORK) url_parsed = utils.parse_url(url) path_ = next(iter(url_parsed.path), '') if not aa.is_active and path_ not in ['setup', 'logout', 'clear_cache']: if not setup(True, True): sys.exit(0) MPR.call(url)
def update_networks(network=None): networks = None if network: networks = [network] else: networks = addict.NETWORKS.keys() diag = xbmcgui.DialogProgress() diag.create(utils.translate(30312)) quality_id = utils.get_quality_id(TEST_LOGIN_NETWORK) utils.logd('Got quality-id:', quality_id) for i, network in enumerate(networks): utils.logd('Updating network', network) aa = addict.AudioAddict.get(PROFILE_DIR, network) progress = i * 100 // len(networks) diag.update(progress, utils.translate(30313).format(aa.name)) aa.get_channels(refresh=True) aa.get_favorite_channels(refresh=True) if aa.is_premium: utils.logd('Setting preferred quality') aa.preferred_quality(quality_id) diag.update(100, utils.translate(30314)) diag.close()
def play_playlist(network, playlist_id, playlist_name=''): utils.logd('Fetching tracklist from server...') aa = addict.AudioAddict.get(PROFILE_DIR, network) with utils.busy_dialog(): track = aa.next_playlist_track(playlist_id, pop=False) item_url = utils.build_path('playlist', 'track', network, playlist_id, track.get('id'), playlist_name=playlist_name) item = utils.build_track_item(track, item_url) utils.logd('Managing playlist') playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) playlist.clear() playlist.add(item.getPath(), item) playlist.getposition xbmcplugin.setResolvedUrl(HANDLE, True, item) # Activated through UI, needs explicit play if HANDLE == -1: utils.logd('Triggering explicit play') xbmc.Player().play()
def resolve_playlist_track(network, playlist_id, track_id, playlist_name=''): utils.logd('Resolving track:', track_id) aa = addict.AudioAddict.get(PROFILE_DIR, network) track = aa.next_playlist_track(playlist_id, refresh=False, pop=True) utils.logd('Resolved track: {}'.format(track.get('id'))) if track_id != track.get('id'): utils.logw('Got unexpected track from cache! ' 'Expected {} but got {}'.format(track_id, track.get('id'))) album = '{} / {}'.format(aa.name, _enc(playlist_name)) item = utils.build_track_item(track, album=album) xbmcplugin.setResolvedUrl(HANDLE, True, item) # Queue another track if it's the last one playing playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) if playlist.getposition() + 2 < playlist.size(): return # e.g "Yatse" clears the playlist, removing this entry. # As such we wait a little before queuing another track time.sleep(1) utils.logd('Adding another track to the playlist...') track = aa.next_playlist_track(playlist_id, refresh=False, pop=False) item = utils.build_track_item(track, utils.build_path( 'playlist', 'track', network, playlist_id, track.get('id'), playlist_name=playlist_name), album=album) utils.logd('Queuing track: {}'.format(track.get('id'))) playlist.add(item.getPath(), item)
def play_channel(network, channel, live=False): utils.logd('Fetching tracklist from server...') aa = addict.AudioAddict.get(PROFILE_DIR, network) with utils.busy_dialog(): is_live, track = aa.next_channel_track(channel, tune_in=True, refresh=True, pop=False, live=live) utils.logd('Activating first track: {}, is-live: {}'.format( track.get('id'), is_live)) item_url = utils.build_path('channel', 'track', network, channel, track.get('id'), is_live=is_live) item = utils.build_track_item(track, item_url) utils.logd('Managing playlist') playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) playlist.clear() playlist.add(item.getPath(), item) xbmcplugin.setResolvedUrl(HANDLE, True, item) # Activated through UI, needs explicit play if HANDLE == -1: utils.logd('Triggering explicit play') xbmc.Player().play() # TODO: Set listitem active if possible xbmc.executebuiltin('Container.Refresh')
def resolve_channel_track(network, channel, track_id, is_live=False): utils.logd('Resolving track:', track_id) aa = addict.AudioAddict.get(PROFILE_DIR, network) current_is_live, track = aa.next_channel_track(channel, tune_in=False, refresh=False, pop=True, live=is_live) utils.logd('Resolved track: {}, is-live: {}'.format( track.get('id'), current_is_live)) if track_id != track.get('id'): utils.logw('Got unexpected track from cache! ' 'Expected {} but got {}'.format(track_id, track.get('id'))) album = '{} / {}'.format(aa.name, _enc(aa.get_channel_name(channel))) item = utils.build_track_item(track, album=album) xbmcplugin.setResolvedUrl(HANDLE, True, item) offset = track.get('content', {}).get('offset', 0) if ADDON.getSettingBool('addon.seek_offset') and offset: # Have at least 30 sec. left to prevent the track ending before # the next one has been queued length = track.get('length') offset = min(length - 30, offset) utils.logd('Seeking to:', offset) if not utils.seek_offset(offset): utils.logd('Seeking failed!') aa.add_listen_history(channel, track_id) # Queue another track if it's the last one playing playlist = xbmc.PlayList(xbmc.PLAYLIST_MUSIC) if playlist.getposition() + 2 < playlist.size(): return # e.g "Yatse" clears the playlist, removing this entry. # As such we wait a little before queuing another track time.sleep(1) utils.logd('Adding another track to the playlist...') is_live, track = aa.next_channel_track(channel, tune_in=False, refresh=False, pop=False, live=not current_is_live) item = utils.build_track_item(track, utils.build_path('channel', 'track', network, channel, track.get('id'), is_live=is_live), album=album) utils.logd('Queuing track: {}, is-live: {}'.format(track.get('id'), is_live)) playlist.add(item.getPath(), item)
def monitor_live(skip_shows=None): if not skip_shows: skip_shows = [] now = addict.datetime_now() addon = xbmcaddon.Addon() for network in addict.NETWORKS.keys(): aa = addict.AudioAddict.get(PROFILE_DIR, network) if not aa.is_active or not aa.network['has_shows']: continue followed = [s.get('slug') for s in aa.get_shows_followed()] shows = aa.get_live_shows() live_show_ids = [s.get('id') for s in shows] # Remove shows which are not live anymore skip_shows = [i for i in skip_shows if i in live_show_ids] for show in shows: if show.get('id') in skip_shows: continue end_at = addict.parse_datetime(show.get('end_at')) if end_at < now: continue skip_shows.append(show.get('id')) _show = show.get('show') if _show.get('slug') in followed and addon.getSettingBool( 'addon.notify_live'): utils.notify('[B]{}[/B] is live!'.format(_show.get('name'))) if addon.getSettingBool('addon.tune_in_live'): filename = xbmc.getInfoLabel('Player.Filenameandpath') if not filename: continue playing = utils.get_playing() if not playing: continue chan = _show.get('channels', [])[0] if (playing['network'] != network or playing['channel'] != chan.get('key')): utils.logd( 'Different network/channel playing, not tuning in.') continue if playing['live']: utils.logd('Live stream already playing.') break time_left = (end_at - now).seconds if time_left < 2: utils.log('Less than 2 minutes left, not tuning in.') break utils.log('Tuning in to live stream...') xbmc.executebuiltin('RunPlugin({})'.format( utils.build_path('play', network, playing['channel'], live=True))) return skip_shows