summaryrefslogtreecommitdiff
path: root/get.pl
blob: 4b94c22378de5a00ec93660594b0789e044501c8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
#!/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;
}

chdir('datasets');

my $fn, $new_fn;
foreach my $s (@ARGV){
  if ($s =~ /^http/) {
    if ($s =~ /(wav|aiff?|flac|mp3|opus)$/i) {
      my $fn = `basename $s`;
      print "downloading $fn\n";
      system('/usr/bin/wget', $s);
      system('/usr/bin/perl', 'dataset.pl', $fn);
    } else {
      print "youtube-dl $s\n";
      my $yt = `youtube-dl --extract-audio --audio-format flac -o "%(title)s.%(ext)s" $s`;
      my @partz = split("\n", $yt);
      foreach $part (@partz) {
        if ($part =~ /\[ffmpeg\] Destination\: (.*\.flac)$/) {
          $fn = $1;
        }
      }
      if ($fn) {
        $new_fn = sanitize($fn)
        $new_fn .= '.flac';
        system('mv', $fn, $new_fn);
        print "got fn, $fn => $new_fn\n";
        system('/usr/bin/perl', 'dataset.pl', $new_fn);
      }
    }
  } else {
    if ($s !~/\..*$/) { $s .= ".wav"; }
    print "downloading $s\n";
    system('/usr/bin/wget', 'https://neural:spawn5@asdf.us/neural/' . $s);
    system('/usr/bin/perl', 'dataset.pl', $s);
  }
  my $tag = sanitize($fn);
  open(my $fd, ">>../run_slap.sh");
  print $fd "standard $tag\n";
  close $fn;

  $fn = undef;
}

END {
  chdir('..');
}