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') item_id = url.split('play_track/')[1] item = session.get_track(item_id) elif 'play_video/' in url: item_type = 'video' userpl_id = addon.getSetting('default_videoplaylist_id').decode('utf-8') item_id = url.split('play_video/')[1] item = session.get_video(item_id) else: return try: if not userpl_id: # Dialog Mode if default Playlist not set user_playlist_add_item(item_type, item_id) return xbmc.executebuiltin( "ActivateWindow(busydialog)" ) if item._userplaylists and userpl_id in item._userplaylists: session.user.remove_playlist_entry(playlist_id=userpl_id, item_id=item.id) else: 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 user_playlist_remove_id(playlist_id, item_id): playlist = session.get_playlist(playlist_id) ok = xbmcgui.Dialog().yesno(_T(30247) % playlist.title, _T(30246)) if ok: xbmc.executebuiltin('ActivateWindow(busydialog)') try: session.user.remove_playlist_entry(playlist_id, item_id=item_id) except Exception, e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() xbmc.executebuiltin('Dialog.Close(busydialog)') xbmc.executebuiltin('Container.Refresh()')
def play_track(track_id): media_url = session.get_media_url(track_id) log("Playing: %s" % media_url) if not media_url.startswith('http://') and not media_url.startswith('https://') and \ not 'app=' in media_url.lower() and not 'playpath=' in media_url.lower(): # Rebuild RTMP URL host, tail = media_url.split('/', 1) app, playpath = tail.split('/mp4:', 1) media_url = 'rtmp://%s app=%s playpath=mp4:%s' % (host, app, playpath) li = ListItem(path=media_url) mimetype = 'audio/flac' if session._config.quality == Quality.lossless and session.is_logged_in else 'audio/mpeg' li.setProperty('mimetype', mimetype) xbmcplugin.setResolvedUrl(plugin.handle, True, li)
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: xbmc.executebuiltin('ActivateWindow(busydialog)') try: session.user.delete_playlist(playlist_id) except Exception, e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() xbmc.executebuiltin('Dialog.Close(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: xbmc.executebuiltin( "ActivateWindow(busydialog)" ) 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, e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() xbmc.executebuiltin( "Dialog.Close(busydialog)" ) xbmc.executebuiltin('Container.Refresh()')
def user_playlist_add_item(item_type, item_id): if item_type == 'playlist': items = session.get_playlist_items(item_id) # Sort Items by Artist, Title items.sort(key=lambda line: (line.artist.name, line.title) , reverse=False) items = ['%s' % item.id for item in items] else: items = [item_id] playlist = session.user.selectPlaylistDialog(allowNew=True) if playlist: xbmc.executebuiltin('ActivateWindow(busydialog)') try: session.user.add_playlist_entries(playlist=playlist, item_ids=items) except Exception, e: log(str(e), level=xbmc.LOGERROR) traceback.print_exc() xbmc.executebuiltin('Dialog.Close(busydialog)') xbmc.executebuiltin('Container.Refresh()')
def play_video(video_id): media_url = session.get_video_url(video_id) log("Playing: %s" % media_url) li = ListItem(path=media_url) li.setProperty('mimetype', 'video/mp4') xbmcplugin.setResolvedUrl(plugin.handle, True, li)