Skip to content

Commit

Permalink
Fix Issue #1064 and #1283: User and Channel searches to return all vi…
Browse files Browse the repository at this point in the history
…deos 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]>
  • Loading branch information
iamtalhaasghar and UpHillSolutions-roberth authored Sep 11, 2024
1 parent 0c1e39d commit a5574cf
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion mps_youtube/commands/search.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,14 @@ def usersearch_id(user, channel_id, term):
else:
failmsg = "User %s not found or has no videos." % termuser[1]
msg = str(msg).format(c.w, c.y, c.y, term, user)
results = pafy.all_videos_from_channel(channel_id)

videos = pafy.all_videos_from_channel(channel_id)
query = term.lower() if term else None

if query:
results = [v for v in videos if query in v.get('title', '').lower() or query in v.get('description', '').lower()]
else:
results = videos
_display_search_results(progtext, results, msg, failmsg)


Expand Down
6 changes: 6 additions & 0 deletions mps_youtube/pafy.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,13 @@ def channel_id_from_name(query):
return (channel_id, channel_name)

def all_videos_from_channel(channel_id):
'''
Get all videos of a playlist identified by channel_id
'''

playlist = Playlist(playlist_from_channel_id(channel_id))
while playlist.hasMoreVideos:
playlist.getNextVideos()
return playlist.videos

def search_videos_from_channel(channel_id, query):
Expand Down

0 comments on commit a5574cf

Please sign in to comment.