home tags blog microbio cv tech cv

Nushell script for opening Youtube videos with MPV

Soc Virnyl Estela | 2024-03-05 | reading time: ~2min

#!/usr/bin/nu
alias MENU = fuzzel -d

let subbed_channels = [ 
  
 chrisbiscardi
 Coderized
 CodeAesthetic
 dreamsofcode
 fasterthanlime
 fireship
 fknight
 freecodecamp
 LearnLinuxTV
 LowLevelLearning
 niccoloveslinux 
 NoBoilerplate
 _noisecode
 RustVideos
 VideosByDefault
 ThePrimeTimeagen
 TraversyMedia

]

let channel = ($subbed_channels | to text | MENU -p "choose channel>" | str trim)
if ($channel | is-empty) {
 exit 0
}
if $channel not-in $subbed_channels {
  notify-send --icon dialog-error --app-name Error -u critical "Not in the list" $"($channel) channel is not in the list of your subs!"
  exit 1
}
let titles = (http get $"(http get $"https://www.youtube.com/@($channel | to text | str trim)" | query web -q 'link' -a href | find feeds | get 0 | ansi strip)" --raw | query web -q 'title')
let channel_title = ($titles | get 0)
let video_titles = ($titles | skip 1)
let chosen_video_title = ($titles | to text | MENU -p 'open link to>' | str trim)
if ($chosen_video_title | is-empty) {
 exit 0
}
let video_hashes = (http get $"(http get $"https://www.youtube.com/@($channel | str trim)" | query web -q 'link' -a href | find feeds | get 0 | ansi strip)" --raw | query web -q 'yt\:videoId')
for $video_title in $video_titles --numbered {
 if $chosen_video_title == $channel_title {
  notify-send --icon firefox --app-name firefox $"Opening Youtube channel - ($channel_title) - in default browser"
  setsid /bin/sh -c $"xdg-open 'https://youtube.com/@($channel)'"
  sleep 0.3sec
  exit 0
 }
 if ($chosen_video_title in $video_titles) and ($chosen_video_title in $video_title.item) {
  notify-send --icon mpv --app-name mpv $"Opening '($video_title.item)' in mpv"
  let ytflags = "(mp4,webm)[height<?1080]+bestaudio/best"  
  setsid /bin/sh -c $'mpv --slang=en --ytdl-raw-options=ignore-config=,sub-lang=en,write-auto-sub= --ytdl-format="($ytflags)" --no-fs "https://youtube.com/watch?v=($video_hashes | get $video_title.index)"'
  sleep 0.3sec
  exit 0
 }
}

Articles from blogs I follow around the net

Decrypting FortiOS 7.0.x

Introduction Decrypting Fortinet’s FortiGate FortiOS firmware is a topic that has been thoroughly covered, in part because of the many variants and permutations of FortiOS firmware, all differing based on hardware architecture and versioning — we may have …

via GreyNoise Labs April 23, 2024

Copyleft licenses are not “restrictive”

One may observe an axis, or a “spectrum”, along which free and open source software licenses can be organized, where one end is “permissive” and the other end is “copyleft”. It is important to acknowledge, however, that though copyleft can be found at the …

via Drew DeVault's blog April 19, 2024

What Precious Things Does The Corporate World Steal From Us?

It has been about a year and a half of working three days a week in response to burnout. It took me six months to regain the ability to do anything beyond resting the moment I was done working, and in the past year I have recovered much of my ability to fu…

via Ludicity April 15, 2024

Generated by openring-rs