You are not logged in.
Hello there!
I'm totally out of my comfort zone here and I don't know where to start. I don't know any programming language but I would like to learn enough to do basic tasks like what I'm trying to achieve here.
My situation:
I want to watch the game highlights of the latest game of my favorite hockey team without opening youtube in my web browser.
What I think the script needs to do:
Look into the NHL youtube account, in the Highlights playlist and get the url of the latest video that contains my team's name in the title. Then run mpv <url>
What it doesn't need to do:
I added this to my mpv.conf
script-opts=ytdl_hook-ytdl_path=yt-dlp
so it uses yt-dlp to pick the best quality available and everything by default.
It also doesn't need to store the video locally. I only want to watch it once, so streaming is the way to go.
Another possible approach:
I saw yt-dlp has --title and --date options so it might be easier to automate filling these options, although I also wouldn't know how to use that in conjunction with mpv. As I said, I want to stream the video, not download it locally.
Any pointers will be greatly appreciated!
Last edited by froli (2021-10-15 16:57:27)
archlinux on Macbook Pro 10,1
Offline
You're aware of youtube-viewer?
Online
You're aware of youtube-viewer?
I wasn't no, thanks for that. But it doesn't quite achieve what I want. I need to launch it from cli and then select my video from the search result. My ultimate goal would be to automate all that, create a .desktop file so that I can start it with rofi and the video starts playing right away in mpv.
Is there a way to make youtube-viewer automatically play the first search result? Cause that would solve it. I looked for the --autoplay option but it seems to be for autoplaying the next video.
archlinux on Macbook Pro 10,1
Offline
You could also use jq in conjuction with youtube-dl (yt-dlp in your case) to download and parse the desired playlist.
Something like this should work:
#!/bin/sh
highlights='https://www.youtube.com/watch?list=PL1NbHSfosBuHInmjsLcBuqeSV256FqlOO'
youtube-dl --dump-json --flat-playlist --playlist-end 50 "$highlights" | \
jq -r 'select(.title | contains("Sharks")) .url'
I took the liberty to guess the playlist on youtube and used Sharks as the search term.
The `--playlist-end=50` is arbitrary (to reduce the number of requests and time) and should defniitly be changed, maybe you could leverage the `--date` flag from youtube-dl.
Edit: changed selector
Last edited by lmn (2021-10-15 15:30:11)
Offline
You could also use jq in conjuction with youtube-dl (yt-dlp in your case) to download and parse the desired playlist.
Something like this should work:#!/bin/sh highlights='https://www.youtube.com/watch?list=PL1NbHSfosBuHInmjsLcBuqeSV256FqlOO' youtube-dl --dump-json --flat-playlist --playlist-end 50 "$highlights" | \ jq -r 'select(.title | contains("Sharks")) .url'
I took the liberty to guess the playlist on youtube and used Sharks as the search term.
The `--playlist-end=50` is arbitrary (to reduce the number of requests and time) and should defniitly be changed, maybe you could leverage the `--date` flag from youtube-dl.Edit: changed selector
That helps a lot! Thank you.
archlinux on Macbook Pro 10,1
Offline
I slightly modified Imn's suggestion to pick the first line of the output (which seems to always be the latest added to the playlist), set it as a variable and run it with mpv.
Here's the result
#!/bin/sh
highlights='https://www.youtube.com/watch?list=PL1NbHSfosBuHInmjsLcBuqeSV256FqlOO'
url=$(youtube-dl --dump-json --flat-playlist --playlist-end 50 "$highlights" | \
jq -r 'select(.title | contains("Canadiens")) .url' | head -n 1)
exec mpv ytdl://$url
HUGE thanks for all the help!
Last edited by froli (2021-10-15 16:57:50)
archlinux on Macbook Pro 10,1
Offline
Fwwi
youtube-viewer -A --skip-watched --prefer-mp4 --results=1 --within=7d --author=UCqFMzb-4AUf6WAIbl132QKA Flyers
(I know nothing about NHL, but they've the best Mascot ;-)
"-A" plays all found videos, you can ignore seen ones, control the format, the resolution etcetc.
Online
mpv is also doing well
mpv --ytdl-raw-options=match-filter="title~=(?i)sharks" --ytdl-raw-options-append=playlist-end=50 "https://www.youtube.com/watch?list=PL1NbHSfosBuHInmjsLcBuqeSV256FqlOO"
Offline