logo

multimedia-dl

Unnamed repository; edit this file 'description' to name the repository. git clone https://anongit.hacktivis.me/git/multimedia-dl.git/

kara-moe.pl (1825B)


  1. #!/usr/bin/env perl
  2. # Multimedia-DL: Youtube-DL inspired scraper
  3. # Copyright © 2021-2023 Multimedia-DL Authors <https://hacktivis.me/git/multimedia-dl/>
  4. # SPDX-License-Identifier: AGPL-3-only
  5. use strict;
  6. use utf8;
  7. use URI;
  8. use File::Basename;
  9. use LWP::UserAgent;
  10. use JSON;
  11. require HTTP::Request;
  12. my $ua = LWP::UserAgent->new;
  13. # Picked this one for it's stability
  14. my $webkit_ua = "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/14.0 Safari/605.1.15";
  15. $ua->agent($webkit_ua . "Multimedia-DL/1.0");
  16. if($#ARGV != 0) {
  17. print "usage: multimedia-dl <url>\n";
  18. exit 1;
  19. }
  20. # https://kara.moe/kara/shinkiro/0b880b76-c599-47b5-aa71-a7392a9c947f
  21. my $url = URI->new($ARGV[0]);
  22. my $id = basename($url->path);
  23. # https://kara.moe/api/karas/0b880b76-c599-47b5-aa71-a7392a9c947f
  24. my $api_url = URI->new_abs("/api/karas/" . $id, $url)->canonical;
  25. my $req = HTTP::Request->new(GET => $api_url);
  26. my $res = $ua->request($req);
  27. $res->is_success or die "Got ", $res->status_line, " instead of 2xx\n";
  28. my $content_type = $res->header("Content-Type");
  29. my $content_match = qr{^application/([^+]*\+)?json(; .*)?};
  30. ($content_type =~ $content_match) or die "Got $content_type instead of $content_match\n";
  31. my $kara = decode_json($res->content);
  32. my $title_lang = $kara->{'titles_default_language'};
  33. my $title = $kara->{'titles'}->{$title_lang};
  34. print STDERR "Title: ", $title, "\n";
  35. print "--title='", $title, "' ";
  36. # https://kara.moe/downloads/lyrics/JPN%20-%20GuraMarine%20-%20MV%20-%20SHINKIRO.ass
  37. my $subfile = URI->new_abs("/downloads/lyrics/" . $kara->{'subfile'}, $url)->canonical;
  38. print "--sub-file='", $subfile, "' ";
  39. # https://kara.moe/downloads/medias/JPN%20-%20GuraMarine%20-%20MV%20-%20SHINKIRO.mp4
  40. print URI->new_abs("/downloads/medias/" . $kara->{'mediafile'}, $url)->canonical;
  41. print "\n";