Skip to content

Instantly share code, notes, and snippets.

@getimiskon
Created January 22, 2022 15:26
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save getimiskon/a5e68f68df27b47f0be9c5678bacdd66 to your computer and use it in GitHub Desktop.
Save getimiskon/a5e68f68df27b47f0be9c5678bacdd66 to your computer and use it in GitHub Desktop.
#!/usr/bin/env raku
# Variables
my ($resolution, $mode, $video_link); # Main variables
my Bool $debug = True; # Debug mode. Should be turned off for actual use.
# Subroutines
sub intro {
say "YouTube CLI Viewer - Raku version";
sleep 0.5;
}
sub playVideo {
if $debug eq True {
say "DEBUG: Resolution: " ~ $resolution ~ "p";
}
shell "mpv '$video_link' --ytdl-format='bestvideo[height<=$resolution]+bestaudio/best'";
}
sub downloadMode {
if $debug eq True {
say "DEBUG: Mode: download";
}
die "ERROR: Download mode is not implemented yet";
}
sub exitScript {
say "Exiting YouTube viewer...";
sleep 0.75;
exit;
}
sub MAIN ($mode = 'viewer', $resolution = 720) {
intro;
if $debug eq True {
if @*ARGS[] eq '' {
say "DEBUG: Arguments: (no arguments)";
} else {
say "DEBUG: Arguments: " ~ @*ARGS[];
}
say "DEBUG: Resolution: " ~ $resolution ~ "p";
}
sleep 0.5;
if $mode eq 'download' {
downloadMode;
} else {
if $debug eq True {
say "DEBUG: Mode: viewer";
}
$video_link = prompt "Paste the video link: ";
if $video_link eq 'exit' {
exitScript;
} else {
say "Resolution: $resolution";
playVideo;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment