def category(group): promoGroup = {'rising': 'RISING', 'discovery': 'DISCOVERY', 'featured': 'NEWS'}.get(group, None) items = session.get_category_items(group) totalCount = 0 for item in items: totalCount += len(item.content_types) if totalCount == 1: # Show Single content directly (Movies and TV Shows) for item in items: content_types = item.content_types for content_type in content_types: category_content(group, item.path, content_type, offset=0) return xbmcplugin.setContent(plugin.handle, 'files') if promoGroup and totalCount > 10: # Add Promotions as Folder on the Top if more than 10 Promotions available add_directory(_T(30120), plugin.url_for(featured, group=promoGroup)) add_directory('Master %s (MQA)' % _T(30107), plugin.url_for(master_albums, offset=0)) add_directory('Master %s (MQA)' % _T(30108), plugin.url_for(master_playlists, offset=0)) # Add Category Items as Folders add_items(items, content=None, end=not(promoGroup and totalCount <= 10)) if promoGroup and totalCount <= 10: # Show up to 10 Promotions as single Items promoItems = session.get_featured(promoGroup, types=['ALBUM', 'PLAYLIST', 'VIDEO']) if promoItems: add_items(promoItems, end=True)
def login(): username = addon.getSetting('username') password = addon.getSetting('password') subscription_type = [SubscriptionType.hifi, SubscriptionType.premium][int('0' + addon.getSetting('subscription_type'))] if not username or not password: # Ask for username/password dialog = xbmcgui.Dialog() username = dialog.input(_T(30008), username) if not username: return password = dialog.input(_T(30009), option=xbmcgui.ALPHANUM_HIDE_INPUT) if not password: return selected = dialog.select(_T(30010), [SubscriptionType.hifi, SubscriptionType.premium]) if selected < 0: return subscription_type = [SubscriptionType.hifi, SubscriptionType.premium][selected] ok = session.login(username, password, subscription_type) if ok and (not addon.getSetting('username') or not addon.getSetting('password')): # Ask about remembering username/password dialog = xbmcgui.Dialog() if dialog.yesno(plugin.name, _T(30209)): addon.setSetting('username', username) addon.setSetting('password', password) else: addon.setSetting('password', '') if not ok: xbmcgui.Dialog().notification(plugin.name, _T(30253) , icon=xbmcgui.NOTIFICATION_ERROR) xbmc.executebuiltin('Container.Refresh()')
def user_playlist_toggle(): if not session.is_logged_in: return url = xbmc.getInfoLabel("ListItem.FilenameandPath") if not _addon_id in url: return if 'play_track/' in url: item_type = 'track' userpl_id = addon.getSetting('default_trackplaylist_id').decode( 'utf-8') userpl_name = addon.getSetting('default_trackplaylist_title').decode( 'utf-8') item_id = url.split('play_track/')[1] item_id = item_id.split('/')[0] item = session.get_track(item_id) elif 'play_video/' in url: item_type = 'video' userpl_id = addon.getSetting('default_videoplaylist_id').decode( 'utf-8') userpl_name = addon.getSetting('default_videoplaylist_title').decode( 'utf-8') item_id = url.split('play_video/')[1] item_id = item_id.split('/')[0] item = session.get_video(item_id) elif 'album/' in url: item_type = 'album' userpl_id = addon.getSetting('default_albumplaylist_id').decode( 'utf-8') userpl_name = addon.getSetting('default_albumplaylist_title').decode( 'utf-8') item_id = url.split('album/')[1] item_id = int('0%s' % item_id.split('/')[0]) item = session.get_album(item_id) if userpl_id: if item._userplaylists and userpl_id in item._userplaylists: user_playlist_remove_album(userpl_id, item.id, dialog=False) return tracks = session.get_album_items(item.id) for track in tracks: if track.available: item.id = track.id # Add First Track of Album break else: return try: if not userpl_id: # Dialog Mode if default Playlist not set user_playlist_add_item(item_type, '%s' % item_id) return if item._userplaylists and userpl_id in item._userplaylists: session.show_busydialog(_T(30264), userpl_name) session.user.remove_playlist_entry(playlist=userpl_id, item_id=item.id) else: session.show_busydialog(_T(30263), userpl_name) session.user.add_playlist_entries(playlist=userpl_id, item_ids=['%s' % item.id]) except Exception, e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc()
def search(): addon.setSetting('last_search_field', '') addon.setSetting('last_search_text', '') add_directory(_T(30106), plugin.url_for(search_type, field='artist')) add_directory(_T(30107), plugin.url_for(search_type, field='album')) add_directory(_T(30108), plugin.url_for(search_type, field='playlist')) add_directory(_T(30109), plugin.url_for(search_type, field='track')) add_directory(_T(30110), plugin.url_for(search_type, field='video'), end=True)
def favorites_remove(content_type, item_id): ok = session.user.favorites.remove(content_type, item_id) if ok: xbmcgui.Dialog().notification( heading=plugin.name, message=_T(30232).format(what=_T(content_type)), icon=xbmcgui.NOTIFICATION_INFO) xbmc.executebuiltin('Container.Refresh()')
def onSettingsChanged(self): xbmc.Monitor.onSettingsChanged(self) if self.reloginNeeded(): if xbmcgui.Dialog().yesno(heading=addon.getAddonInfo('name'), line1=_T(30256), line2=_T(30257)): xbmc.executebuiltin('XBMC.RunPlugin(plugin://%s/login)' % addon.getAddonInfo('id')) pass
def artist_bio(artist_id): artist = session.get_artist(artist_id) info = session.get_artist_info(artist_id) text = '' if info.get('summary', None): text += '%s:\n\n' % _T(30230) + info.get('summary') + '\n\n' if info.get('text', None): text += '%s:\n\n' % _T(30225) + info.get('text') if text: xbmcgui.Dialog().textviewer(artist.name, text)
def user_playlist_remove_id(playlist_id, item_id): playlist = session.get_playlist(playlist_id) ok = xbmcgui.Dialog().yesno(_T(30247).format(name=playlist.name), _T(30246)) if ok: session.show_busydialog(_T(30264), playlist.name) try: session.user.remove_playlist_entry(playlist, item_id=item_id) except Exception as e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() session.hide_busydialog() xbmc.executebuiltin('Container.Refresh()')
def user_playlist_delete(playlist_id): dialog = xbmcgui.Dialog() playlist = session.get_playlist(playlist_id) ok = dialog.yesno(_T(30235), _T(30236).format(name=playlist.title, count=playlist.numberOfItems)) if ok: session.show_busydialog(_T(30235), playlist.name) try: session.user.delete_playlist(playlist_id) except Exception as e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() session.hide_busydialog() xbmc.executebuiltin('Container.Refresh()')
def user_playlist_remove_item(playlist_id, entry_no): item_no = int('0%s' % entry_no) + 1 playlist = session.get_playlist(playlist_id) ok = xbmcgui.Dialog().yesno( _T(30247).format(name=playlist.name), _T(30241).format(entry=item_no)) if ok: session.show_busydialog(_T(30264), playlist.name) try: session.user.remove_playlist_entry(playlist, entry_no=entry_no) except Exception, e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() session.hide_busydialog() xbmc.executebuiltin('Container.Refresh()')
def user_playlist_add_item(item_type, item_id): if item_type == 'playlist': srcPlaylist = session.get_playlist(item_id) if not srcPlaylist: return items = session.get_playlist_items(playlist=srcPlaylist) # Sort Items by Artist, Title sortMode = 'ALBUM' if ALBUM_PLAYLIST_TAG in srcPlaylist.description else 'LABEL' items.sort(key=lambda line: line.getSortText(mode=sortMode).upper(), reverse=False) items = ['%s' % item.id for item in items if item.available] elif item_type.startswith('album'): # Add First Track of the Album tracks = session.get_album_items(item_id) for track in tracks: if track.available: item_id = track.id break items = ['%s' % item_id] else: items = [item_id] playlist = session.user.selectPlaylistDialog(allowNew=True) if playlist: session.show_busydialog(_T(30263), playlist.name) try: session.user.add_playlist_entries(playlist=playlist, item_ids=items) except Exception as e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() session.hide_busydialog() xbmc.executebuiltin('Container.Refresh()')
def user_playlist_move_entry(playlist_id, entry_no, item_id): dialog = xbmcgui.Dialog() playlist = session.user.selectPlaylistDialog(headline=_T(30248), allowNew=True) if playlist and playlist.id != playlist_id: session.show_busydialog(_T(30265), playlist.name) try: ok = session.user.add_playlist_entries(playlist=playlist, item_ids=[item_id]) if ok: ok = session.user.remove_playlist_entry(playlist_id, entry_no=entry_no) else: dialog.notification(plugin.name, _T('API Call Failed'), xbmcgui.NOTIFICATION_ERROR) except Exception as e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() session.hide_busydialog() xbmc.executebuiltin('Container.Refresh()')
def search_type(field): last_field = addon.getSetting('last_search_field') search_text = addon.getSetting('last_search_text') if last_field != field or not search_text: addon.setSetting('last_search_field', field) keyboard = xbmc.Keyboard('', _T(30206)) keyboard.doModal() if keyboard.isConfirmed(): search_text = keyboard.getText() else: search_text = '' addon.setSetting('last_search_text', search_text) if search_text: searchresults = session.search(field, search_text) add_items(searchresults.artists, content=CONTENT_FOR_TYPE.get('files'), end=False) add_items(searchresults.albums, end=False) add_items(searchresults.playlists, end=False) add_items(searchresults.tracks, end=False) add_items(searchresults.videos, end=True) else: #xbmcplugin.setContent(plugin.handle, content='files') xbmcplugin.endOfDirectory(plugin.handle, succeeded=False, updateListing=False)
def album_view(album_id): xbmcplugin.addSortMethod(plugin.handle, xbmcplugin.SORT_METHOD_TRACKNUM) album = session.get_album(album_id) if album and album.numberOfVideos > 0: add_directory(_T(30110), plugin.url_for(album_videos, album_id=album_id)) add_items(session.get_album_tracks(album_id), content=CONTENT_FOR_TYPE.get('tracks'))
def user_playlist_remove_album(playlist_id, item_id, dialog=True): playlist = session.get_playlist(playlist_id) ok = True if dialog: ok = xbmcgui.Dialog().yesno(_T(30247).format(name=playlist.name), _T(30246)) if ok: session.show_busydialog(_T(30264), playlist.name) try: items = session.get_playlist_tracks(playlist) for item in items: if '%s' % item.album.id == '%s' % item_id: session.user.remove_playlist_entry(playlist, entry_no=item._playlist_pos) break # Remove only one Item except Exception as e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() session.hide_busydialog() xbmc.executebuiltin('Container.Refresh()')
def root(): if session.is_logged_in: add_directory(_T(30201), my_music) add_directory(_T(30212), plugin.url_for(homepage_items)) add_directory(_T(30202), featured_playlists) if getattr(session._config, 'cache_albums', False): add_directory(_T(30509), plugin.url_for(albums_with_videos)) categories = Category.groups() for item in categories: add_directory(_T(item), plugin.url_for(category, group=item)) add_directory(_T(30206), search) add_directory(_T(30027), settings, isFolder=False) if session.is_logged_in: add_directory(_T(30207), logout, end=True, isFolder=False) else: add_directory(_T(30208), login, end=True, isFolder=False)
def artist_view(artist_id): if session.is_logged_in: session.user.favorites.load_all() artist = session.get_artist(artist_id) xbmcplugin.setContent(plugin.handle, 'albums') add_directory(_T(30225), plugin.url_for(artist_bio, artist_id), thumb=artist.image, fanart=artist.fanart, isFolder=False) add_directory(_T(30226), plugin.url_for(top_tracks, artist_id), thumb=artist.image, fanart=artist.fanart) add_directory(_T(30110), plugin.url_for(artist_videos, artist_id), thumb=artist.image, fanart=artist.fanart) add_directory(_T(30227), plugin.url_for(artist_radio, artist_id), thumb=artist.image, fanart=artist.fanart) add_directory(_T(30228), plugin.url_for(artist_playlists, artist_id), thumb=artist.image, fanart=artist.fanart) add_directory(_T(30229), plugin.url_for(similar_artists, artist_id), thumb=artist.image, fanart=artist.fanart) if session.is_logged_in: if session.user.favorites.isFavoriteArtist(artist_id): add_directory(_T(30220), plugin.url_for(favorites_remove, content_type='artists', item_id=artist_id), thumb=artist.image, fanart=artist.fanart, isFolder=False) else: add_directory(_T(30219), plugin.url_for(favorites_add, content_type='artists', item_id=artist_id), thumb=artist.image, fanart=artist.fanart, isFolder=False) albums = session.get_artist_albums(artist_id) + \ session.get_artist_albums_ep_singles(artist_id) + \ session.get_artist_albums_other(artist_id) add_items(albums, content=None)
def my_music(): add_directory(_T(30213), user_playlists) add_directory(_T(30214), plugin.url_for(favorites, content_type='artists')) add_directory(_T(30215), plugin.url_for(favorites, content_type='albums')) add_directory(_T(30216), plugin.url_for(favorites, content_type='playlists')) add_directory(_T(30217), plugin.url_for(favorites, content_type='tracks')) add_directory(_T(30218), plugin.url_for(favorites, content_type='videos'), end=True)
def root(): if session.is_logged_in: add_directory(_T(30201), my_music) add_directory(_T(30212), plugin.url_for(homepage_items)) add_directory(_T(30202), featured_playlists) categories = Category.groups() for item in categories: add_directory(_T(item), plugin.url_for(category, group=item)) add_directory(_T(30206), search) add_directory(_T(30027), settings, isFolder=False) if session.is_logged_in: add_directory(_T(30207), logout, end=True, isFolder=False) else: add_directory(_T(30208), login, end=True, isFolder=False)
def stream_locked(): xbmcgui.Dialog().notification(heading=plugin.name, message=_T(30242), icon=xbmcgui.NOTIFICATION_INFO)
if media: log("Playing: %s" % media.url) li = ListItem(path=media.url) li.setProperty('mimetype', 'video/mp4') xbmcplugin.setResolvedUrl(plugin.handle, True, li) @plugin.route('/stream_locked') def stream_locked(): xbmcgui.Dialog().notification(heading=plugin.name, message=_T(30242), icon=xbmcgui.NOTIFICATION_INFO) if __name__ == '__main__': try: # Remove last slash for folder paths newargv = sys.argv newargv[0] = newargv[0].rstrip('/') plugin.run(argv=newargv) except HTTPError as e: r = e.response if r.status_code in [401, 403]: msg = _T(30210) else: msg = r.reason try: msg = r.json().get('userMessage') except: pass xbmcgui.Dialog().notification('%s Error %s' % (plugin.name, r.status_code), msg, xbmcgui.NOTIFICATION_ERROR) traceback.print_exc()
def cache_reset_confirmed(): if xbmcgui.Dialog().yesno(_T(30507), _T(30508)): cache_reset()