CogentRedTester / mpv-scripts

A collection of scripts for mpv player
MIT License
258 stars 18 forks source link

youtube-search.lua: Use yt-dlp instead of curl+API #22

Open gunir opened 1 year ago

gunir commented 1 year ago

##################################### Is this a request for a brand new script? If so please make a Discussion thread instead #####################################

Is your feature request related to a problem? Please describe. I like the idea of being able to search and browse Youtube infinitely, but having to enter API key is a bit rough, yt-dlp support searching out-of-the-box and doens't require API at all.

Describe the solution you'd like Use yt-dlp instead, with --flat-playlist it's very very fast:

yt-dlp ytsearch10:SEARCH --get-id --get-title --flat-playlist

10 = number of result, of course it must be used with --flat-playlist to increase searching speed by ten forth.

Describe alternatives you've considered yt-dlp instead of curl+API

Additional context Should be good enough information.

CogentRedTester commented 1 year ago

Is there a way of getting channel information for each video as well?

gunir commented 1 year ago

Is there a way of getting channel information for each video as well?

Yes, a small issue is short videos doesn't return channel name, but shorts are irrelevant so we can just group NA as Shorts:

yt-dlp ytsearch10:fireemblem --flat-playlist --print id,title,channel
ZCdzzXYHID0
The AI Created a Great City Defense Chapter!
Mangs
30XVon_BBMc
Fire Emblem
RJ Pasin - Topic
itUvooNBHWk
The Necessary Evils of Fire Emblem Heroes
ZeShado
58GYGNvPJk8
The Questionable Design Choices and Hilarious Errors of Fire Emblem's First Game
Faerghast
bhi9lrGxUys
Fire Emblem characters all look the same
NA
Rw6wNkZeINg
Fire Emblem Engage is GREAT
NA
3E52D_iIUZI
Fire Emblem Engage Is Stupid
NA
9VTL5EkDIjY
Fire Emblem Heroes - New Hero (Byleth: Tested Professor)
NA
v6mcvASRAdY
The Fire Emblem: Three Houses OST in a nutshell
NA
6-dYmyg969M
Fire Emblem 0 Ironman Speedrun in 53.21s (WR)
NA
gunir commented 1 year ago

Just in case you want to get more channel information, try:

yt-dlp ytsearch10:fireemblem --flat-playlist --print id,title,channel,duration,thumbnails

Adding --dump-json to see more.