Forum › Forums › General › Tips and Tricks › Simple YLE TV and Radio script
- This topic has 5 replies, 3 voices, and was last updated May 7-6:06 pm by Robin.
-
AuthorPosts
-
May 6, 2023 at 6:56 am #106089Member
RJP
A script for watching and listening Finnish YLE programs.
#!/bin/bash yad --form --width=500 --text="Valitse kanava, jota haluat katsoa tai kuunnella:" \ --field="YLE TV1":fbtn "mpv --ytdl-raw-options=abort-on-error= --ytdl-format='best[tbr<='\500']/bestvideo[tbr<='\500']+bestaudio' --hls-bitrate=min https://yletv.akamaized.net/hls/live/622365/yletv1fin/index.m3u8 & " \ --field="YLE TV2":fbtn "mpv --ytdl-raw-options=abort-on-error= --ytdl-format='best[tbr<='\500']/bestvideo[tbr<='\500']+bestaudio' --hls-bitrate=min https://yletv.akamaized.net/hls/live/622366/yletv2fin/index.m3u8" \ --field="YLE TEEMA":fbtn "mpv --ytdl-raw-options=abort-on-error= --ytdl-format='best[tbr<='\500']/bestvideo[tbr<='\500']+bestaudio' --hls-bitrate=min https://yletv.akamaized.net/hls/live/622367/yletvteemafemfin/index.m3u8 &" \ --field="Radio 1":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027672/in-YleRadio1/master.m3u8" \ --field="Yle X":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027674/in-YleX/master.m3u8 &" \ --field="Radio Suomi":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027675/in-YleRS/master.m3u8 &" \ --field="YLE Puhe":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027677/in-YlePuhe/master.m3u8 &" \ --field="Lopeta radio":fbtn "killall mpv" \ --button=gtk-cancel:1May 6, 2023 at 9:04 am #106101MemberRobin
::Looks great to me. Just tried it, and actually it plays finish radio stream. Unfortunately it fails for all the tv streams, probably due to geoblocking:
Playing: https://yletv.akamaized.net/hls/live/622365/yletv1fin/index.m3u8 [ffmpeg] https: HTTP error 403 Forbidden Failed to open https://yletv.akamaized.net/hls/live/622365/yletv1fin/index.m3u8. [ytdl_hook] ERROR: [generic] None: Unable to download webpage: HTTP Error 403: Forbidden (caused by <HTTPError 403: 'Forbidden'>); please report this issue on https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using yt-dlp -U [ytdl_hook] youtube-dl failed: unexpected error occurred Playing: & [file] Cannot open file '&': No such file or directory Failed to open &. Exiting... (Errors when loading file) [ffmpeg] https: HTTP error 403 Forbidden Failed to open https://yletv.akamaized.net/hls/live/622366/yletv2fin/index.m3u8. [ytdl_hook] ERROR: [generic] None: Unable to download webpage: HTTP Error 403: Forbidden (caused by <HTTPError 403: 'Forbidden'>); please report this issue on https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using yt-dlp -U [ytdl_hook] youtube-dl failed: unexpected error occurred Exiting... (Errors when loading file) Playing: https://yletv.akamaized.net/hls/live/622367/yletvteemafemfin/index.m3u8 [ffmpeg] https: HTTP error 403 Forbidden Failed to open https://yletv.akamaized.net/hls/live/622367/yletvteemafemfin/index.m3u8. [ytdl_hook] ERROR: [generic] None: Unable to download webpage: HTTP Error 403: Forbidden (caused by <HTTPError 403: 'Forbidden'>); please report this issue on https://github.com/yt-dlp/yt-dlp/issues?q= , filling out the appropriate issue template. Confirm you are on the latest version using yt-dlp -U [ytdl_hook] youtube-dl failed: unexpected error occurred Playing: & [file] Cannot open file '&': No such file or directory Failed to open &. Exiting... (Errors when loading file)Playing radio I works fine, but after closing the Yad window there is no way to stop the radio playing; mpv doesn’t seem to provide an icon for this on tray. Had to kill it via kill command on console, searching it’s proper process pid before. Obviously I’ve missed the stop button in the yad window, since I don’t speak Finnish language 🙂 Noticed it on second try.
Just a suggestion: Don’t do killall mpv. It will kill other instances of MPV working on something different (e.g doing a recording) the same time as well, while you just want to stop the radio. You’ll need to kill more selectively, either by sending the kill command to a process group or by storing the mpv pid when starting it up and using it then to quit it on exit of the GUI. Also you could check out how aCSTV does the cleanup task, to get an idea, it sends the quit command via json ipc command to mpv; (see the aufräumen function starting around line 151). aCSTV won’t stop your radio/tv script playing when closing down and quitting itself.
Windows is like a submarine. Open a window and serious problems will start.
May 6, 2023 at 9:24 am #106103MemberRJP
::Yes … this is for Finnish only and geo restriction probably prevents other countries to see videos?
The sript keeps on, and Lopeta Radio means Quit Radio. 😉
May 7, 2023 at 6:34 am #106157MemberLead Farmer
May 7, 2023 at 9:07 am #106159MemberRJP
::Very nice script!
Thank you. 🙂
I forgot Yle classic radio channel, so fixed version here:
#!/bin/bash yad --form --width=500 --text="VALITSE KANAVA, JOTA HALUAT KATSOA TAI KUUNNELLA:" \ \ --field="YLE TV1":fbtn "mpv --ytdl-raw-options=abort-on-error= --ytdl-format='best[tbr<='\500']/bestvideo[tbr<='\500']+bestaudio' --hls-bitrate=min https://yletv.akamaized.net/hls/live/622365/yletv1fin/index.m3u8 & " \ --field="YLE TV2":fbtn "mpv --ytdl-raw-options=abort-on-error= --ytdl-format='best[tbr<='\500']/bestvideo[tbr<='\500']+bestaudio' --hls-bitrate=min https://yletv.akamaized.net/hls/live/622366/yletv2fin/index.m3u8 & " \ --field="YLE TEEMA":fbtn "mpv --ytdl-raw-options=abort-on-error= --ytdl-format='best[tbr<='\500']/bestvideo[tbr<='\500']+bestaudio' --hls-bitrate=min https://yletv.akamaized.net/hls/live/622367/yletvteemafemfin/index.m3u8 &" \ --field="Radio 1":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027672/in-YleRadio1/master.m3u8" \ --field="Yle X":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027674/in-YleX/master.m3u8 &" \ --field="Radio Suomi":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027675/in-YleRS/master.m3u8 &" \ --field="YLE Puhe":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027677/in-YlePuhe/master.m3u8 &" \ --field="YLE Klassinen":fbtn "mpv https://yleradiolive.akamaized.net/hls/live/2027676/in-YleKlassinen/master.m3u8 &" \ --field="LOPETA RADION KUUNTELU":fbtn "killall mpv" \ --button=gtk-cancel:1Attachments:
May 7, 2023 at 6:06 pm #106198MemberRobin
::I really like the new channel 🙂
And I like your script. It reminds me of what aCSTV looked like in its very first and early 0.01 to 0.09 versions I started with some years ago, which I never have published 🙂The fixed version of your script still has the dangerous issue: It kills unwanted and for the user unexpectedly all other instances of MPV working on other tasks already on the very PC all of a sudden when pressing the Lopeta Radion kuuntelu button. This way it even crashes and ruins recordings running in the background which were not started by your script altogether.
A hint how to solve it:
– to the startup command for each stream add the command
pidof mpv
– put the resulting pid’s in a list.
– only then let start mpv with the stream meant to play
– immediately again run pidof mpv and put the result to a second list
– match the new list against the first list; the pid not present in both lists is the very pid you want to kill on exit. (it is most unlikely the user starts another MPV instance the very moment he clicks the play button, so you can rely on the pid returned from this is actually „your” pid.)
– store or add this single pid in a variable or in a tmp file for later usage.– in the stop command replace the killall by kill -15 <pid>, using the very pid(s) from your variable or the tmp file. (There might be stored multiple pids, since your script allows of starting multiple streams in parallel.)
(alternatively you could use killall -g -n <pid> to only close the mpv processes running in the very process group your script lives in. But be aware, this might fail horribly as long the issues in the launchers present in antiX not establishing process groups properly for the programs they start, as you’ve spotted in aCSTV already. Adding the hotfix line I’ve invented to your script would fix this here also if you decide to go for the groups instead of the method described above.)
The second issue is also still present in your fixed version: You can leave the script by the abort button, then having no means any longer to stop a playing radio stream.
Windows is like a submarine. Open a window and serious problems will start.
-
AuthorPosts
- You must be logged in to reply to this topic.

