summaryrefslogtreecommitdiff
path: root/get.pl
diff options
context:
space:
mode:
Diffstat (limited to 'get.pl')
-rwxr-xr-xget.pl79
1 files changed, 79 insertions, 0 deletions
diff --git a/get.pl b/get.pl
new file mode 100755
index 0000000..0a12a81
--- /dev/null
+++ b/get.pl
@@ -0,0 +1,79 @@
+#!/usr/bin/perl
+
+$SIG{TERM} = $SIG{INT} = sub { exit 1 };
+
+sub sanitize ($) {
+ my $s = lc shift;
+ $s =~ s/\.[^.]+$//g;
+ $s =~ s/\W/_/g;
+ $s =~ s/\s+/_/g;
+ if (length($s) == 0) {
+ print "fn is empty";
+ exit(1);
+ }
+ $s =~ s/_+/_/g;
+ return $s;
+}
+
+my ($s) = @ARGV;
+
+if (not defined $s || $s !~ /^http/) {
+ die "usage: ./get.pl http://...\n";
+}
+
+mkdir("sequences/");
+chdir("sequences/");
+
+my $fn, $new_fn, $video_fn;
+
+if ($s =~ /(mov|mp4|webm|avi|mpe?g)$/i) {
+ $s =~ s/^\s+//;
+ $s =~ s/\s+$//;
+ my $fn = `basename $s`;
+ $clean_fn = $fn;
+ $clean_fn =~ s/-/_/g;
+ $clean_fn =~ s/^\s//;
+ $clean_fn =~ s/\s$//;
+ $clean_fn =~ s/\s/_/g;
+ $clean_fn =~ s/_+/_/g;
+ system('rm', $fn);
+ system('rm', $clean_fn);
+ print "downloading $clean_fn\n";
+ system('wget', '-O', $clean_fn, $s);
+ $video_fn = $clean_fn;
+}
+else {
+ print "youtube-dl $s\n";
+ my $yt = `youtube-dl -o "%(title)s.%(ext)s" $s`;
+ # print $yt;
+ my @partz = split("\n", $yt);
+ foreach $part (@partz) {
+ print "$part\n";
+ if ($part =~ /\[download\] Destination\: ([^)]+)$/) {
+ $video_fn = $1;
+ print ">>> $video_fn\n";
+ }
+ if ($part =~ /\[download\] (.*) has already been downloaded and merged/) {
+ $video_fn = $1;
+ print ">>> $video_fn\n";
+ }
+ if ($part =~ /\[ffmpeg\] Merging formats into "(.*)"/) {
+ $video_fn = $1;
+ print ">>> $video_fn\n";
+ }
+ }
+}
+
+if ($video_fn) {
+ print "Video filename: $video_fn\n";
+ my $tag = sanitize($video_fn);
+ print "creating dataset: $tag\n";
+ mkdir($tag);
+ system('ffmpeg', '-i', $video_fn, "-filter:v", "scale=1024x512", $tag . '/frame_%05d.png');
+ print "created dataset: $tag\n";
+}
+
+END {
+ chdir('..');
+}
+