From 92db320b105d524d9ff3fb6376344fca1c4ba2e9 Mon Sep 17 00:00:00 2001 From: Heersin Date: Wed, 1 Jul 2020 17:34:43 +0800 Subject: [PATCH 1/9] cmd show enhancement(issue ) -- show albums of an artist --- fuocore/cmds/show.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index 5b15d66f67..e121c9a464 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -90,3 +90,15 @@ def playlist_songs(req, provider, pid): playlist = provider.Playlist.get(pid) songs = reader_to_list(to_reader(playlist, "songs")) return songs + +''' +Issue #317 +Description: fuo show enhancment -- show all albums of an artist identified by aid +example : fuo show fuo:///artists//albums +''' +@route('//artists//albums') +def albums_of_artist(req, provider, aid): + provider = req.ctx['library'].get(provider) + artist = provider.Artist.get(aid) + albums = reader_to_list(to_reader(artist, "albums")) + return albums \ No newline at end of file From 721ba12442440856bc95a71d983746d71ece9bb8 Mon Sep 17 00:00:00 2001 From: Heersin Date: Wed, 1 Jul 2020 23:38:49 +0800 Subject: [PATCH 2/9] cmd show enhancement 1. exception handle, 2.get info about current user --- fuocore/cmds/__init__.py | 5 ++ fuocore/cmds/show.py | 141 +++++++++++++++++++++++++++++++++------ fuocore/router.py | 25 +++++-- 3 files changed, 148 insertions(+), 23 deletions(-) diff --git a/fuocore/cmds/__init__.py b/fuocore/cmds/__init__.py index 299fd8cea7..cd8dde6fed 100644 --- a/fuocore/cmds/__init__.py +++ b/fuocore/cmds/__init__.py @@ -1,6 +1,8 @@ import logging from fuocore.excs import FuoException +from fuocore.router import ShowCmdException + from .base import cmd_handler_mapping from .help import HelpHandler # noqa @@ -66,6 +68,9 @@ def exec_cmd(cmd, *args, app): playlist=playlist, live_lyric=live_lyric) rv = handler.handle(cmd) + except ShowCmdException: + logger.exception('handle cmd({}) error'.format(cmd)) + return False, 'show command not correct' except Exception: logger.exception('handle cmd({}) error'.format(cmd)) return False, 'internal server error' diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index e121c9a464..49495d35fc 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -11,12 +11,11 @@ import logging from urllib.parse import urlparse -from fuocore.router import Router +from fuocore.router import Router, ShowCmdException from fuocore.utils import reader_to_list, to_reader from .base import AbstractHandler - logger = logging.getLogger(__name__) @@ -46,59 +45,163 @@ def list_providers(req): @route('//songs/') def song_detail(req, provider, sid): + provider_path_name = provider provider = req.ctx['library'].get(provider) - song = provider.Song.get(sid) - return song + + try: + song = provider.Song.get(sid) + except AttributeError: + return "No such provider : {}-{}".format(provider.name, provider_path_name) + # marshallow exception -- Validation Error + except Exception: + return "song identified by {} is unavailable in {} ".format(sid, provider.name) + else: + if song is None: + return "song {} is not in local library".format(sid) + return song @route('//songs//lyric') def lyric(req, provider, sid): + provider_path_name = provider provider = req.ctx['library'].get(provider) - song = provider.Song.get(sid) - if song.lyric: - return song.lyric.content - return '' + + try: + song = provider.Song.get(sid) + except AttributeError: + return "No such provider : {}-{}".format(provider.name, provider_path_name) + # marshallow exception -- Validation Error + except Exception: + return "song identified by {} is unavailable in {} ".format(sid, provider.name) + else: + if song is None: + return "song {} is not in local library".format(sid) + if song.lyric: + return song.lyric.content + return 'no lyric, enjoy it~' @route('//artists/') def artist_detail(req, provider, aid): + provider_path_name = provider provider = req.ctx['library'].get(provider) - return provider.Artist.get(aid) + + try: + artist = provider.Artist.get(aid) + except AttributeError: + return "No such provider : {}-{}".format(provider.name, provider_path_name) + except Exception: + return "artist identified by {} is not found in {}".format(aid, provider.name) + else: + if artist is None: + return "artist {} is not in local library".format(aid) + return artist @route('//albums/') def album_detail(req, provider, bid): + provider_path_name = provider provider = req.ctx['library'].get(provider) - return provider.Album.get(bid) + + try: + album = provider.Album.get(bid) + except AttributeError: + return "No such provider : {}-{}".format(provider.name, provider_path_name) + except Exception: + return "album identified by {} in {} is unavailable".format(bid, provider.name) + else: + if album is None: + return "album identified by {} in {} is unavailable".format(bid, provider.name) + return album +''' +------------------------------------ +Original Route -- get User by uid +example : fuo show fuo:///users/12345678 +------------------------------------ +Issue #317 +Description: fuo show nehancement -- show info about current user +example : fuo show fuo:///users/me +''' @route('//users/') def user_detail(req, provider, uid): + provider_path_name = provider provider = req.ctx['library'].get(provider) - return provider.User.get(uid) + + try: + if uid == 'me': + user = provider._user + else: + user = provider.User.get(uid) + except AttributeError: + return "No such provider : {}-{}".format(provider.name, provider_path_name) + except Exception: + return "No user identified by {} in {}".format(uid, provider.name) + else: + if user is not None: + return user + elif uid == 'me': + return "User is not logged in in current session(plugin) -- {}-{}".format(provider.name, provider_path_name) + else: + return "No user in local" @route('//playlists/') def playlist_detail(req, provider, pid): + provider_path_name = provider provider = req.ctx['library'].get(provider) - return provider.Playlist.get(pid) + + try: + playlist = provider.Playlist.get(pid) + except AttributeError: + return "No such provider : {}-{}".format(provider.name, provider_path_name) + except Exception: + return "No playlist found by {} in {} ".format(pid, provider.name) + else: + if playlist is None: + return "No playlist found by {} in {} ".format(pid, provider.name) + return playlist + @route('//playlists//songs') def playlist_songs(req, provider, pid): + provider_path_name = provider provider = req.ctx['library'].get(provider) - playlist = provider.Playlist.get(pid) - songs = reader_to_list(to_reader(playlist, "songs")) - return songs + + try: + playlist = provider.Playlist.get(pid) + except AttributeError: + return "No such provider : {}-{}".format(provider.name, provider_path_name) + except Exception: + return "No playlist found by {} in {} ".format(pid, provider.name) + else: + if playlist is None: + return "No playlist found by {} in {} ".format(pid, provider.name) + songs = reader_to_list(to_reader(playlist, "songs")) + return songs + + ''' Issue #317 -Description: fuo show enhancment -- show all albums of an artist identified by aid +Description: fuo show enhancement -- show all albums of an artist identified by aid example : fuo show fuo:///artists//albums ''' @route('//artists//albums') def albums_of_artist(req, provider, aid): + provider_path_name = provider provider = req.ctx['library'].get(provider) - artist = provider.Artist.get(aid) - albums = reader_to_list(to_reader(artist, "albums")) - return albums \ No newline at end of file + + try: + artist = provider.Artist.get(aid) + except AttributeError: + return "No such provider : {}-{}".format(provider.name, provider_path_name) + except Exception: + return "artist identified by {} is not found in {}".format(aid, provider.name) + else: + if artist is not None: + albums = reader_to_list(to_reader(artist, "albums")) + return albums + return "artist identified by {} is not found in {}".format(aid, provider.name) \ No newline at end of file diff --git a/fuocore/router.py b/fuocore/router.py index 3a72301fe9..403f1f17b5 100644 --- a/fuocore/router.py +++ b/fuocore/router.py @@ -2,10 +2,20 @@ from collections import namedtuple from urllib.parse import parse_qsl, urlsplit - -class NotFound(Exception): +class ShowCmdException(Exception): pass +# Rule not found +class NotFound(ShowCmdException): + def __init__(self, rule): + self.rule = rule + + def __str__(self): + # use backstrace lib (the format_exc/print_exc) causes fail + # maybe the coroutine issue ? + uri_msg = "Bad Uri Exception: fuo://{}".format(self.rule) + return uri_msg + def match(url, rules): """找到 path 对应的 rule,并解析其中的参数 @@ -30,7 +40,8 @@ def match(url, rules): query = dict(parse_qsl(qs)) params = match.groupdict() return rule, params, query - raise NotFound + + raise NotFound(path) def _validate_rule(rule): @@ -96,7 +107,13 @@ def wrapper(*args, **kwargs): return decorator def dispatch(self, uri, ctx): - rule, params, query = match(uri, self.rules) + try: + rule, params, query = match(uri, self.rules) + except NotFound: + # pass it to the exception handle procedure in __init__.py + raise + return None + handler = self.handlers[rule] req = Request(uri=uri, rule=rule, params=params, query=query, ctx=ctx) return handler(req, **params) From 6a1c925ca75365679412edf0598308005f8a8a39 Mon Sep 17 00:00:00 2001 From: Heersin Date: Thu, 2 Jul 2020 00:08:09 +0800 Subject: [PATCH 3/9] fix for pr requirement --- fuocore/cmds/show.py | 12 +++++++----- fuocore/router.py | 4 +++- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index 49495d35fc..8de5bc6ef5 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -11,7 +11,6 @@ import logging from urllib.parse import urlparse -from fuocore.router import Router, ShowCmdException from fuocore.utils import reader_to_list, to_reader from .base import AbstractHandler @@ -124,6 +123,8 @@ def album_detail(req, provider, bid): Description: fuo show nehancement -- show info about current user example : fuo show fuo:///users/me ''' + + @route('//users/') def user_detail(req, provider, uid): provider_path_name = provider @@ -142,7 +143,7 @@ def user_detail(req, provider, uid): if user is not None: return user elif uid == 'me': - return "User is not logged in in current session(plugin) -- {}-{}".format(provider.name, provider_path_name) + return "User is not logged in in current session(plugin) {}-{}".format(provider.name, provider_path_name) else: return "No user in local" @@ -164,7 +165,6 @@ def playlist_detail(req, provider, pid): return playlist - @route('//playlists//songs') def playlist_songs(req, provider, pid): provider_path_name = provider @@ -183,12 +183,13 @@ def playlist_songs(req, provider, pid): return songs - ''' Issue #317 Description: fuo show enhancement -- show all albums of an artist identified by aid example : fuo show fuo:///artists//albums ''' + + @route('//artists//albums') def albums_of_artist(req, provider, aid): provider_path_name = provider @@ -204,4 +205,5 @@ def albums_of_artist(req, provider, aid): if artist is not None: albums = reader_to_list(to_reader(artist, "albums")) return albums - return "artist identified by {} is not found in {}".format(aid, provider.name) \ No newline at end of file + return "artist identified by {} is not found in {}".format(aid, provider.name) + diff --git a/fuocore/router.py b/fuocore/router.py index 403f1f17b5..c22cff5b65 100644 --- a/fuocore/router.py +++ b/fuocore/router.py @@ -2,9 +2,11 @@ from collections import namedtuple from urllib.parse import parse_qsl, urlsplit + class ShowCmdException(Exception): pass + # Rule not found class NotFound(ShowCmdException): def __init__(self, rule): @@ -14,7 +16,7 @@ def __str__(self): # use backstrace lib (the format_exc/print_exc) causes fail # maybe the coroutine issue ? uri_msg = "Bad Uri Exception: fuo://{}".format(self.rule) - return uri_msg + return uri_msg def match(url, rules): From 7bdb046714b8be74d41b3e3168f716b0c8799407 Mon Sep 17 00:00:00 2001 From: Heersin Date: Thu, 2 Jul 2020 00:12:15 +0800 Subject: [PATCH 4/9] fix for pr requirement -- forget to import router --- fuocore/cmds/show.py | 1 + 1 file changed, 1 insertion(+) diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index 8de5bc6ef5..d82f3d62af 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -12,6 +12,7 @@ from urllib.parse import urlparse from fuocore.utils import reader_to_list, to_reader +from fuocore.router import Router from .base import AbstractHandler From 34f4688cd48ec780fafbd16f20e15ee12e0a46d1 Mon Sep 17 00:00:00 2001 From: Heersin Date: Thu, 2 Jul 2020 00:30:26 +0800 Subject: [PATCH 5/9] fix for pr requirement -- forget to import router --- fuocore/cmds/show.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index d82f3d62af..8bfc9dd288 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -111,7 +111,8 @@ def album_detail(req, provider, bid): return "album identified by {} in {} is unavailable".format(bid, provider.name) else: if album is None: - return "album identified by {} in {} is unavailable".format(bid, provider.name) + return "album identified by {} in {} is unavailable"\ + .format(bid, provider.name) return album @@ -144,7 +145,8 @@ def user_detail(req, provider, uid): if user is not None: return user elif uid == 'me': - return "User is not logged in in current session(plugin) {}-{}".format(provider.name, provider_path_name) + return "User is not logged in in current session(plugin) \{}-{}"\ + .format(provider.name, provider_path_name) else: return "No user in local" @@ -207,4 +209,3 @@ def albums_of_artist(req, provider, aid): albums = reader_to_list(to_reader(artist, "albums")) return albums return "artist identified by {} is not found in {}".format(aid, provider.name) - From 3d431d3a6c40d42e1ef255bbcee4bae2c73f6573 Mon Sep 17 00:00:00 2001 From: Heersin Date: Thu, 2 Jul 2020 00:35:34 +0800 Subject: [PATCH 6/9] fix for pr requirement -- rm blank line, add indentation --- fuocore/cmds/show.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index 8bfc9dd288..c51a9079ad 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -112,7 +112,7 @@ def album_detail(req, provider, bid): else: if album is None: return "album identified by {} in {} is unavailable"\ - .format(bid, provider.name) + .format(bid, provider.name) return album @@ -145,8 +145,8 @@ def user_detail(req, provider, uid): if user is not None: return user elif uid == 'me': - return "User is not logged in in current session(plugin) \{}-{}"\ - .format(provider.name, provider_path_name) + return "User is not logged in in current session(plugin) {}-{}"\ + .format(provider.name, provider_path_name) else: return "No user in local" @@ -208,4 +208,4 @@ def albums_of_artist(req, provider, aid): if artist is not None: albums = reader_to_list(to_reader(artist, "albums")) return albums - return "artist identified by {} is not found in {}".format(aid, provider.name) + return "artist identified by {} is not found in {}".format(aid, provider.name) \ No newline at end of file From 8a42fdb8be8336621073d92f5493923eca5859dc Mon Sep 17 00:00:00 2001 From: Heersin Date: Thu, 2 Jul 2020 00:43:43 +0800 Subject: [PATCH 7/9] fix for pr requirement -- add line at the end --- fuocore/cmds/show.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index c51a9079ad..d888454c87 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -208,4 +208,4 @@ def albums_of_artist(req, provider, aid): if artist is not None: albums = reader_to_list(to_reader(artist, "albums")) return albums - return "artist identified by {} is not found in {}".format(aid, provider.name) \ No newline at end of file + return "artist identified by {} is not found in {}".format(aid, provider.name) From 89a0af09e08dc95be79fe7dd04cecda421e02a5b Mon Sep 17 00:00:00 2001 From: Heersin Date: Thu, 2 Jul 2020 12:53:45 +0800 Subject: [PATCH 8/9] abstract some codes -> get_from_provider --- fuocore/cmds/show.py | 212 +++++++++++++++++++------------------------ 1 file changed, 95 insertions(+), 117 deletions(-) diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index d888454c87..8c94269db1 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -38,82 +38,105 @@ def handle(self, cmd): return rv -@route('/') -def list_providers(req): - return req.ctx['library'].list() +def noexception_handler_default(obj_name, obj_identifier, obj): + if obj is None: + return "{} identified by {} is not found"\ + .format(obj_name, obj_identifier) + return obj -@route('//songs/') -def song_detail(req, provider, sid): - provider_path_name = provider - provider = req.ctx['library'].get(provider) +def noexception_handler_lyric(obj_name, obj_identifier, obj): + song,sid = obj,obj_identifier + if song is None: + return "{} identified by {} is not found"\ + .format(obj_name, obj_identifier) - try: - song = provider.Song.get(sid) - except AttributeError: - return "No such provider : {}-{}".format(provider.name, provider_path_name) - # marshallow exception -- Validation Error - except Exception: - return "song identified by {} is unavailable in {} ".format(sid, provider.name) + if song.lyric is None: + return "no lyric for this song, enjoy it ~" + + return song.lyric.content + + +def noexception_handler_user(obj_name, obj_identifier, obj): + user,uid = obj, obj_identifier + if user is not None: + return user + elif uid == 'me': + return "User is not logged in in current session(plugin)" else: - if song is None: - return "song {} is not in local library".format(sid) - return song + return "No {} with uid {} ".format(obj_name, uid) -@route('//songs//lyric') -def lyric(req, provider, sid): +def noexception_handler_readerlist(obj_name, obj_identifier, obj): + if obj is None: + return "No {} found by {} "\ + .format(obj_name, obj_identifier) + + # quick and dirty implement + if obj_name == 'playlists': + return reader_to_list(to_reader(obj, "songs")) + else: + return reader_to_list(to_reader(obj, "albums")) + + +def get_from_provider( + req, + provider, + obj_identifier, + obj_name, + handler=noexception_handler_default): provider_path_name = provider provider = req.ctx['library'].get(provider) + if provider is None: + return "No such provider : {}".format(provider_path_name) + try: - song = provider.Song.get(sid) - except AttributeError: - return "No such provider : {}-{}".format(provider.name, provider_path_name) - # marshallow exception -- Validation Error + if obj_name == 'songs': + obj = provider.Song.get(obj_identifier) + elif obj_name == 'artists': + obj = provider.Artist.get(obj_identifier) + elif obj_name == 'ablums': + obj = provider.Album.get(obj_identifier) + elif obj_name == 'playlists': + obj = provider.Playlist.get(obj_identifier) + elif obj_name == 'users': + if obj_identifier == 'me': + obj = provider._user + else: + obj = provider.User.get(obj_identifier) + else: + obj = None except Exception: - return "song identified by {} is unavailable in {} ".format(sid, provider.name) + return "resource-{} identified by {} is unavailable in {}"\ + .format(obj_name, obj_identifier, provider.name) else: - if song is None: - return "song {} is not in local library".format(sid) - if song.lyric: - return song.lyric.content - return 'no lyric, enjoy it~' + return handler(obj_name, obj_identifier, obj) + + +@route('/') +def list_providers(req): + return req.ctx['library'].list() + + +@route('//songs/') +def song_detail(req, provider, sid): + return get_from_provider(req, provider, sid, "songs") + + +@route('//songs//lyric') +def lyric(req, provider, sid): + return get_from_provider(req, provider, sid, "songs", noexception_handler_lyric) @route('//artists/') def artist_detail(req, provider, aid): - provider_path_name = provider - provider = req.ctx['library'].get(provider) - - try: - artist = provider.Artist.get(aid) - except AttributeError: - return "No such provider : {}-{}".format(provider.name, provider_path_name) - except Exception: - return "artist identified by {} is not found in {}".format(aid, provider.name) - else: - if artist is None: - return "artist {} is not in local library".format(aid) - return artist + return get_from_provider(req, provider, aid, "artists") @route('//albums/') def album_detail(req, provider, bid): - provider_path_name = provider - provider = req.ctx['library'].get(provider) - - try: - album = provider.Album.get(bid) - except AttributeError: - return "No such provider : {}-{}".format(provider.name, provider_path_name) - except Exception: - return "album identified by {} in {} is unavailable".format(bid, provider.name) - else: - if album is None: - return "album identified by {} in {} is unavailable"\ - .format(bid, provider.name) - return album + return get_from_provider(req, provider, bid, "albums") ''' @@ -129,61 +152,23 @@ def album_detail(req, provider, bid): @route('//users/') def user_detail(req, provider, uid): - provider_path_name = provider - provider = req.ctx['library'].get(provider) - - try: - if uid == 'me': - user = provider._user - else: - user = provider.User.get(uid) - except AttributeError: - return "No such provider : {}-{}".format(provider.name, provider_path_name) - except Exception: - return "No user identified by {} in {}".format(uid, provider.name) - else: - if user is not None: - return user - elif uid == 'me': - return "User is not logged in in current session(plugin) {}-{}"\ - .format(provider.name, provider_path_name) - else: - return "No user in local" + return get_from_provider(req, provider, uid, "users", noexception_handler_user) @route('//playlists/') def playlist_detail(req, provider, pid): - provider_path_name = provider - provider = req.ctx['library'].get(provider) - - try: - playlist = provider.Playlist.get(pid) - except AttributeError: - return "No such provider : {}-{}".format(provider.name, provider_path_name) - except Exception: - return "No playlist found by {} in {} ".format(pid, provider.name) - else: - if playlist is None: - return "No playlist found by {} in {} ".format(pid, provider.name) - return playlist + return get_from_provider(req, provider, pid, "playlists") @route('//playlists//songs') def playlist_songs(req, provider, pid): - provider_path_name = provider - provider = req.ctx['library'].get(provider) - - try: - playlist = provider.Playlist.get(pid) - except AttributeError: - return "No such provider : {}-{}".format(provider.name, provider_path_name) - except Exception: - return "No playlist found by {} in {} ".format(pid, provider.name) - else: - if playlist is None: - return "No playlist found by {} in {} ".format(pid, provider.name) - songs = reader_to_list(to_reader(playlist, "songs")) - return songs + return get_from_provider( + req, + provider, + pid, + "playlists", + noexception_handler_readerlist + ) ''' @@ -195,17 +180,10 @@ def playlist_songs(req, provider, pid): @route('//artists//albums') def albums_of_artist(req, provider, aid): - provider_path_name = provider - provider = req.ctx['library'].get(provider) - - try: - artist = provider.Artist.get(aid) - except AttributeError: - return "No such provider : {}-{}".format(provider.name, provider_path_name) - except Exception: - return "artist identified by {} is not found in {}".format(aid, provider.name) - else: - if artist is not None: - albums = reader_to_list(to_reader(artist, "albums")) - return albums - return "artist identified by {} is not found in {}".format(aid, provider.name) + return get_from_provider( + req, + provider, + aid, + "artists", + noexception_handler_readerlist + ) \ No newline at end of file From a64deeb22ada91e878638a695896c082be6b46b1 Mon Sep 17 00:00:00 2001 From: Heersin Date: Thu, 2 Jul 2020 13:00:14 +0800 Subject: [PATCH 9/9] fix for pr check --- fuocore/cmds/show.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/fuocore/cmds/show.py b/fuocore/cmds/show.py index 8c94269db1..9ae0c5e76c 100644 --- a/fuocore/cmds/show.py +++ b/fuocore/cmds/show.py @@ -46,10 +46,10 @@ def noexception_handler_default(obj_name, obj_identifier, obj): def noexception_handler_lyric(obj_name, obj_identifier, obj): - song,sid = obj,obj_identifier + song, sid = obj, obj_identifier if song is None: return "{} identified by {} is not found"\ - .format(obj_name, obj_identifier) + .format(obj_name, sid) if song.lyric is None: return "no lyric for this song, enjoy it ~" @@ -58,7 +58,7 @@ def noexception_handler_lyric(obj_name, obj_identifier, obj): def noexception_handler_user(obj_name, obj_identifier, obj): - user,uid = obj, obj_identifier + user, uid = obj, obj_identifier if user is not None: return user elif uid == 'me': @@ -71,7 +71,7 @@ def noexception_handler_readerlist(obj_name, obj_identifier, obj): if obj is None: return "No {} found by {} "\ .format(obj_name, obj_identifier) - + # quick and dirty implement if obj_name == 'playlists': return reader_to_list(to_reader(obj, "songs")) @@ -80,10 +80,10 @@ def noexception_handler_readerlist(obj_name, obj_identifier, obj): def get_from_provider( - req, - provider, - obj_identifier, - obj_name, + req, + provider, + obj_identifier, + obj_name, handler=noexception_handler_default): provider_path_name = provider provider = req.ctx['library'].get(provider) @@ -163,10 +163,10 @@ def playlist_detail(req, provider, pid): @route('//playlists//songs') def playlist_songs(req, provider, pid): return get_from_provider( - req, - provider, - pid, - "playlists", + req, + provider, + pid, + "playlists", noexception_handler_readerlist ) @@ -181,9 +181,9 @@ def playlist_songs(req, provider, pid): @route('//artists//albums') def albums_of_artist(req, provider, aid): return get_from_provider( - req, + req, provider, aid, "artists", noexception_handler_readerlist - ) \ No newline at end of file + )