dotfiles/miscellany/yt-dlp.pl

53 lines
1.3 KiB
Perl
Executable File

#! /usr/bin/env perl
use warnings;
use strict;
use utf8;
use YAML::Syck;
use File::Slurp;
# vars with static values during runtime
my $skip = " Skipping...\n";
my $conf = LoadFile('yt-dlp.yml');
# declare empty vars for use later
my $site;
my $type;
foreach my ($url) (@ARGV) {
if ($url =~ /^(https?:?\/\/)?((www|m)\.)?(youtube(-nocookie)?\.com|youtu\.be)/g ) {
$site = "yout";
print "[".$url."] YouTube URL";
if ( $url =~ /((watch\?v=)([0-9A-Za-z_-]{10}[048AEIMQUYcgkosw])|playlist|watch)(&|\?)(list=)(PL)([A-Z0-9]{16}|[0-9A-Za-z_-]{32})((&v=)([0-9A-Za-z_-]{10}[048AEIMQUYcgkosw]))?&?$/g ) {
$type = "lst";
print ": playlist\n";
} elsif ( $url =~ /((channel\/)(UC)?[0-9A-Za-z_-]{21}[AQgw]|(@|\/c\/|\/user\/).{1,})$/g ) {
$type = "usr";
print ": channel\n";
} elsif ( $url =~ /(watch\?v=)([0-9A-Za-z_-]{10}[048AEIMQUYcgkosw])(\?t=\d{3,5})?$/g ) {
$type = "vid";
print ": video\n";
} else {
print "\nCannot determine whether this is a video, playlist, or channel.".$skip;
}
} elsif ($url =~ /^(https?:\/\/)?((www)\.)?(bilibili\.com)/g ) {
$site = "bili";
print "[".$url."] Bilibili URL\n";
} elsif ($url =~ /^(https?:\/\/)?((www)\.)?(nicovideo\.jp)/g ) {
$site = "nico";
print "[".$url."] niconico URL\n";
} else {
print "Unknown or invalid URL: `".$url."`".$skip;
}
}