diff --git a/mps_youtube/commands/search.py b/mps_youtube/commands/search.py index 1412218a..3127138b 100644 --- a/mps_youtube/commands/search.py +++ b/mps_youtube/commands/search.py @@ -307,7 +307,7 @@ def search(term): @command(r'u(?:ser)?pl\s(.*)', 'userpl', 'upl') def user_pls(user): """ Retrieve user playlists. """ - return usersearch_id(user, pafy.channel_id_from_name(user)[0], '')#pl_search(user, is_user=True) + return pl_search(user, is_user=True) @command(r'(?:\.\.|\/\/|pls(?:earch)?\s)\s*(.*)', 'plsearch') @@ -328,41 +328,18 @@ def pl_search(term, page=0, splash=True, is_user=False): g.message = "Searching playlists for %s" % c.y + prog + c.w screen.update() + logging.info("playlist search for %s", prog) if is_user: ret = channelfromname(term) - if not ret: # Error + if not ret: return user, channel_id = ret - - else: - # playlist search is done with the above url and param type=playlist - logging.info("playlist search for %s", prog) - # qs = generate_search_qs(term) - # qs['pageToken'] = token(page) - # qs['type'] = 'playlist' - # if 'videoCategoryId' in qs: - # del qs['videoCategoryId'] # Incompatable with type=playlist - - #pldata = pafy.playlist_search(term) - - #id_list = [i.get('id', {}) for i in pldata] - - #result_count = len(pldata) - - #todo: what is the purpose of this code? #qs = {'part': 'contentDetails,snippet','maxResults': 50} - if is_user: - if page: - pass #qs['pageToken'] = token(page) - pass #qs['channelId'] = channel_id + pldata = pafy.all_playlists_from_channel(channel_id) else: - pass #qs['id'] = ','.join(id_list) + pldata = pafy.playlist_search(term) - pldata = pafy.playlist_search(term) playlists = get_pl_from_json(pldata)[:util.getxy().max_results] - # if is_user: - # result_count = pldata['pageInfo']['totalResults'] - if playlists: g.last_search_query = (pl_search, {"term": term, "is_user": is_user}) g.browse_mode = "ytpl" @@ -394,7 +371,7 @@ def get_pl_from_json(pldata): link=item["id"], size=item["videoCount"], title=item["title"], - author=item['channel']["name"], + author= item['channel']["name"] if 'channel' in item.keys() else None, created=item.get("publishedAt"), updated=item.get('publishedAt'), #XXX Not available in API? description=item.get("description"))) diff --git a/mps_youtube/pafy.py b/mps_youtube/pafy.py index 8a7ab37d..1f59cd54 100644 --- a/mps_youtube/pafy.py +++ b/mps_youtube/pafy.py @@ -170,3 +170,11 @@ def extract_video_id(url: str) -> str: err = "Need 11 character video id or the URL of the video. Got %s" raise ValueError(err % url) + +def all_playlists_from_channel(channel_id): + channel = Channel(channel_id) + playlists = channel.result['playlists'] + while channel.has_more_playlists(): + channel.next() + playlists.extend(channel.result["playlists"]) + return playlists \ No newline at end of file