diff --git a/bin/peertube-dl-web b/bin/peertube-dl-web index 2903867..9ae5ba6 100755 --- a/bin/peertube-dl-web +++ b/bin/peertube-dl-web @@ -22,10 +22,14 @@ post '/api' => sub { status => 400 ) ); + my $format = $c->req->json->{format}; my $render_returned; eval { $render_returned = $c->render( - json => Peertube::DL::URLHandler::getDownloadDataFromURL($url) ); + json => Peertube::DL::URLHandler::getDownloadDataFromURL( + $url, { ( ( defined $format ) ? ( format => $format ) : () ) }, + ) + ); }; if ($@) { return $c->render( text => $@, status => 500 ); diff --git a/lib/Peertube/DL/Downloaders.pm b/lib/Peertube/DL/Downloaders.pm index 92d684b..f511b76 100644 --- a/lib/Peertube/DL/Downloaders.pm +++ b/lib/Peertube/DL/Downloaders.pm @@ -31,6 +31,14 @@ sub youtube { my $microformat = $ytInitialPlayerResponse->{microformat}{playerMicroformatRenderer}; $ytInitialPlayerResponse = $ytInitialPlayerResponse->{streamingData}; + say Data::Dumper::Dumper [ + scalar @{ $ytInitialPlayerResponse->{adaptiveFormats} } + ? @{ $ytInitialPlayerResponse->{adaptiveFormats} } + : (), + scalar @{ $ytInitialPlayerResponse->{formats} } + ? @{ $ytInitialPlayerResponse->{formats} } + : () + ]; if ( defined $options->{format} ) { my $format = $options->{format}; @@ -116,26 +124,64 @@ sub youtube { ? @{ $ytInitialPlayerResponse->{formats} } : () ]; + my @formats = map { + { + id => $_->{itag}, + mimeType => $_->{mimeType}, + ( + ( defined $_->{averageBitrate} && defined $_->{bitrate} ) + ? ( bitrate => $_->{averageBitrate} // $_->{bitrate} ) + : () + ), + ( + ( defined $_->{qualityLabel} ) + ? ( qualityLabel => int( $_->{qualityLabel} ) ) + : () + ), + ( + ( defined $_->{audioSampleRate} ) + ? ( audioSampleRate => $_->{audioSampleRate} ) + : () + ), + ( + ( defined $_->{quality} ) + ? ( quality => $_->{quality} ) + : () + ), + } + } ( + scalar @{ $ytInitialPlayerResponse->{adaptiveFormats} } + ? @{ $ytInitialPlayerResponse->{adaptiveFormats} } + : (), + scalar @{ $ytInitialPlayerResponse->{formats} } + ? @{ $ytInitialPlayerResponse->{formats} } + : () + ); + my $video_formats = [ + sort { + $b->{qualityLabel} <=> $a->{qualityLabel} + || $b->{bitrate} <=> $a->{bitrate} + } grep { defined $_->{qualityLabel} } @formats + ]; + my $audio_formats = [ + sort { + $a->{audioSampleRate} <=> $b->{audioSampleRate} + || $b->{bitrate} <=> $a->{bitrate} + } grep { + defined $_->{audioSampleRate} + && $_->{mimeType} =~ /webm;/ + } @formats + ]; return { options => { list_formats => 1 }, title => $microformat->{title}{simpleText}, description => $microformat->{description}{simpleText}, - formats => [ - map { - { - id => $_->{itag}, - mimeType => $_->{mimeType} - } - } ( - scalar @{ $ytInitialPlayerResponse->{adaptiveFormats} } - ? @{ $ytInitialPlayerResponse->{adaptiveFormats} } - : (), - scalar @{ $ytInitialPlayerResponse->{formats} } - ? @{ $ytInitialPlayerResponse->{formats} } - : () - ) - ] + formats => { + video_formats => $video_formats, + audio_formats => $audio_formats, + }, + }; } } diff --git a/lib/Peertube/DL/URLHandler.pm b/lib/Peertube/DL/URLHandler.pm index 115e48b..3715bf9 100644 --- a/lib/Peertube/DL/URLHandler.pm +++ b/lib/Peertube/DL/URLHandler.pm @@ -66,7 +66,7 @@ sub getDownloadDataFromURL { die "No title." unless defined $download_data->{title}; die "No description." unless defined $download_data->{description}; die "No formats available." unless defined $download_data->{formats}; - die "Formats is not an arrayref." unless ref $download_data->{formats} eq 'ARRAY'; + die "Formats is not a hash." unless ref $download_data->{formats} eq 'HASH'; say "The video title is $download_data->{title}."; say "The video description is $download_data->{description}."; say "The available formats are: @{[Data::Dumper::Dumper $download_data->{formats}]}."; diff --git a/lib/Peertube/DL/public/css/index.css b/lib/Peertube/DL/public/css/index.css index 6b504d5..fa83ef8 100644 --- a/lib/Peertube/DL/public/css/index.css +++ b/lib/Peertube/DL/public/css/index.css @@ -135,7 +135,7 @@ h2 { width: 10%; } -.poping-notice { +#poping-notice { display: none; position: fixed; top: 50%; @@ -150,17 +150,17 @@ h2 { overflow-y: scroll; } -.poping-notice.active { +#poping-notice.active { display: block; } -.poping-notice-container-bar { +#poping-notice-container-bar { display: flex; justify-content: center; font-size: 5rem; } -.close-poping-notice { +#close-poping-notice { width: 150px; height: 150px; align-items: center; @@ -173,7 +173,7 @@ h2 { text-decoration: none; } -.close-poping-notice:hover,.close-poping-notice:focus { +#close-poping-notice:hover,#close-poping-notice:focus { background: black; color: white; } @@ -229,18 +229,22 @@ h2 { .format-list > div { width: 100%; + display: grid; + grid-auto-columns: 50%; + grid-template-areas: "a a"; } .format-list > div > a { border: 1px solid black; - width: 100%; display: flex; align-items: center; justify-content: center; - font-size: 5rem; + font-size: 1.5rem; + padding-right: 5%; + padding-left: 5%; text-decoration: none; color: black; - background: grey; + background: #eee; } .format-list > div > a:hover { @@ -259,7 +263,7 @@ div.video-formats a { } @media (min-width: 668px) { - .poping-notice { + #poping-notice { width: 629px; } } diff --git a/lib/Peertube/DL/public/index.html b/lib/Peertube/DL/public/index.html index 1c6f5c7..4eac01f 100644 --- a/lib/Peertube/DL/public/index.html +++ b/lib/Peertube/DL/public/index.html @@ -12,6 +12,21 @@ +
Example description
+This webpage is free as in freedom software, it is offered to you with the hope it will be useful, but without any warranty, - you can find the source code at my gitea with docs to setup your own - webpage like this, this software is licensed under the AGPLv3 license which means you MUST convey the source code in a human readable form - if you distribute this software or use it as an service to users of service or distributees.
+
This webpage is free as in freedom software, it is offered to you with the hope it will be useful, but without any warranty, + you can find the source code at my gitea with docs to setup your own + webpage like this, this software is licensed under the AGPLv3 license which means you MUST convey the source code in a human readable form + if you distribute this software or use it as an service to users of service or distributees.
-
I hope that if you find a non supported url which should be supported, a bug, or a feature you would like this webpage to have you file an issue in - https://gitea.sergiotarxz.freemyip.com/sergiotarxz/Peertube-dl/issues - to help this software improve since I find tracking users a pretty bad way to discover bugs and potential good features.
+I hope that if you find a non supported url which should be supported, a bug, or a feature you would like this webpage to have you file an issue in + https://gitea.sergiotarxz.freemyip.com/sergiotarxz/Peertube-dl/issues + to help this software improve since I find tracking users a pretty bad way to discover bugs and potential good features.
-This webpage may load third party resources depending on the url you give to it which may put cookies in your browser, you are - encouraged to frecuently delete your browser cookies to avoid those third parties tracking you on internet, Firefox offers you an - option to delete cookies as soon as you close the browser which may be a good idea to enable in the orwellian internet of today.
+This webpage may load third party resources depending on the url you give to it which may put cookies in your browser, you are + encouraged to frecuently delete your browser cookies to avoid those third parties tracking you on internet, Firefox offers you an + option to delete cookies as soon as you close the browser which may be a good idea to enable in the orwellian internet of today.