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