Skip to content

Commit a5574cf

Browse files
Fix Issue #1064 and #1283: User and Channel searches to return all videos including optional filtering of search terms (#1282) (#1288)
* Updated the all_videos_from_channel function to return all videos from a channel, not just the first page of playlist results (previous method only returned up to 100 videos max). * Updated the usersearch_id function to filter the returned videos by search term in the title or description. This restores the ability to search a user's videos. Co-authored-by: Robert Hill <[email protected]>
1 parent 0c1e39d commit a5574cf

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

mps_youtube/commands/search.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,14 @@ def usersearch_id(user, channel_id, term):
216216
else:
217217
failmsg = "User %s not found or has no videos." % termuser[1]
218218
msg = str(msg).format(c.w, c.y, c.y, term, user)
219-
results = pafy.all_videos_from_channel(channel_id)
219+
220+
videos = pafy.all_videos_from_channel(channel_id)
221+
query = term.lower() if term else None
222+
223+
if query:
224+
results = [v for v in videos if query in v.get('title', '').lower() or query in v.get('description', '').lower()]
225+
else:
226+
results = videos
220227
_display_search_results(progtext, results, msg, failmsg)
221228

222229

mps_youtube/pafy.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,13 @@ def channel_id_from_name(query):
119119
return (channel_id, channel_name)
120120

121121
def all_videos_from_channel(channel_id):
122+
'''
123+
Get all videos of a playlist identified by channel_id
124+
'''
125+
122126
playlist = Playlist(playlist_from_channel_id(channel_id))
127+
while playlist.hasMoreVideos:
128+
playlist.getNextVideos()
123129
return playlist.videos
124130

125131
def search_videos_from_channel(channel_id, query):

0 commit comments

Comments
 (0)