Skip to content
Snippets Groups Projects
Commit b91d5147 authored by Síle Ekaterin Liszka's avatar Síle Ekaterin Liszka
Browse files

Chessa::URI::YouTube: smarter decision-making

parent adffcd3e
No related branches found
No related tags found
No related merge requests found
......@@ -24,29 +24,35 @@ sub wants($self, $uri) {
}
sub handle($self, $http, $on_info, $uri, $errors) {
my ($item, $kind, $fetch) = ('', '', '');
my ($item, $kind, $fetch);
if ($uri->authority =~ /\.be(?:\:\d+)?$/) {
$item = $uri->path;
$item =~ s!^/!!;
$kind = 'video';
$fetch = 'https://www.googleapis.com/youtube/v3/videos?id=%s&key=%s&fields=items(id,snippet(title,liveBroadcastContent),contentDetails(duration))&part=snippet,contentDetails';
} elsif ($uri->path =~ m!/shorts!) {
$item = $uri->path;
$item =~ s!^/shorts/!!;
$kind = 'video';
} else {
my %query = $uri->query_form;
if (exists($query{v})) {
($item, $kind) = ($query{v}, 'video');
$fetch = 'https://www.googleapis.com/youtube/v3/videos?id=%s&key=%s&fields=items(id,snippet(title,channelTitle,liveBroadcastContent),contentDetails(duration))&part=snippet,contentDetails';
} elsif (exists($query{list})) {
($item, $kind) = ($query{list}, 'playlist');
$fetch = 'https://www.googleapis.com/youtube/v3/playlists?id=%s&key=%s&part=snippet,contentDetails&fields=items(snippet(title,channelTitle),contentDetails(itemCount))';
} else {
# what else?
$self->{log}("Unknown YouTube item encountered: " . $uri);
return;
}
}
if ($kind eq 'video')
$fetch = 'https://www.googleapis.com/youtube/v3/videos?id=%s&key=%s&fields=items(id,snippet(title,liveBroadcastContent),contentDetails(duration))&part=snippet,contentDetails';
} elsif ($kind eq 'playlist') {
$fetch = 'https://www.googleapis.com/youtube/v3/playlists?id=%s&key=%s&part=snippet,contentDetails&fields=items(snippet(title,channelTitle),contentDetails(itemCount))';
} else {
# what else?
$self->{log}("Unknown YouTube item encountered: " . $uri);
return;
}
$self->{log}("Fetching $kind $item from YouTube...");
$http->do_request(
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment