WWW::Y...wnload(3pm)

πŸ’– WWW::YouTube::Download πŸ’–

okay bestie, so this is the WWW::YouTube::Download page β€” it's a User Contributed Perl Documentation situation, and it is literally the most low-key way to pull YouTube videos down onto your machine. it's giving "very simple interface" and honestly? it ate. ✨


πŸŽ€ VERSION πŸŽ€

version 0.65 β€” yes queen, we're on 0.65, no cap.


🌸 SYNOPSIS 🌸

use WWW::YouTube::Download;

my $client = WWW::YouTube::Download->new;
$client->download($video_id);

my $video_url = $client->get_video_url($video_id);
my $title     = $client->get_title($video_id);     # maybe encoded utf8 string.
my $fmt       = $client->get_fmt($video_id);       # maybe highest quality.
my $suffix    = $client->get_suffix($video_id);    # maybe highest quality file suffix

like. that's it. that's the whole vibe. 🫢


πŸ¦‹ DESCRIPTION πŸ¦‹

WWW::YouTube::Download is a library that downloads videos from YouTube, periodt. the way it works is it relies entirely on scraping a video's webpage β€” it does not use YT's /get_video_info URL space. so if you were wondering, that's the whole main character energy of this module: scrape the page, get the goods. πŸ’…


✨ METHODS ✨

🌈 new()

$client = WWW::YouTube::Download->new;

makes you a fresh WWW::YouTube::Download instance. iconic. a little baby object. obsessed.


🌈 download($video_id [, \%args])

$client->download($video_id);
$client->download($video_id, {
    fmt      => 37,
    filename => 'sample.mp4', # save file name
});
$client->download($video_id, {
    filename => '{title}.{suffix}', # maybe `video_title.mp4`
});
$client->download($video_id, {
    cb => \&callback,
});

this is the one that actually grabs the video file, bestie. the first parameter gets passed to the YouTube video url.

here's everything you're allowed to pass in:

  • cb β€” set a callback subroutine. peep LWP::UserAgent and its :content_cb for the deets, iykyk.
  • filename β€” set the filename! and you can use placeholders that get filled in with info it gathered about the video. πŸ’«

filename supported format placeholders:

{video_id}
{title}
{user}
{fmt}
{suffix}
{resolution}

output filename defaults to {video_id}.{suffix} β€” that's the default, no cap.

  • file_name β€” DEPRECATED alternative for filename. like, she's retired, don't call her. πŸ™ˆ
  • fmt β€” set the format to download. defaults to the best video quality (inferred by the available resolutions). slay.

🌈 playback_url($video_id, [, \%args])

$client->playback_url($video_id);
$client->playback_url($video_id, { fmt => 37 });

returns the playback URL of the video β€” and bestie, this is a direct link to the movie file. πŸ”₯ heads up tho: this function supports only the fmt option. that's it. that's the only one.


🌈 prepare_download($video_id)

gathers data about the video. you get back a hash reference, and these are the keys it comes with:

  • fmt β€” the default, suggested format. it's inferred by selecting the alternative with the highest resolution.
  • fmt_list β€” the list of available formats, as an array reference.
  • suffix β€” the filename extension associated to the default format (see fmt above).
  • title β€” the title of the video.
  • user β€” the YouTube user owning the video.
  • video_id β€” the video identifier.
  • video_url β€” the URL of the video associated to the default format (see fmt above).
  • video_url_map β€” a hash reference containing details about all available formats.

now, about that video_url_map: it has one key/value pair for each available format. the key is the format identifier (which you can use as the fmt parameter for download, for example), and the value is a hash reference with this data inside:

  • fmt β€” the format specifier, that can be passed to download.
  • resolution β€” the resolution as widthxheight.
  • suffix β€” the suffix, providing a hint about the video format (e.g. webm, flv, ...).
  • url β€” the URL where the video can be found.

🌈 ua([$ua])

$self->ua->agent();
$self->ua($LWP_LIKE_OBJECT);

sets and gets the LWP::UserAgent object. bring your own or grab the one she came with. 🧚


🌈 video_id($url)

parses the given URL and returns the video ID. cute and useful.


🌈 playlist_id($url)

parses the given URL and returns the playlist ID. πŸ’œ


🌈 user_id($url)

parses the given URL and returns the YouTube username. okay periodt.


🌈 the little getters πŸ’…

  • get_video_id($video_id)
  • get_video_url($video_id)
  • get_title($video_id)
  • get_user($video_id)
  • get_fmt($video_id)
  • get_fmt_list($video_id)
  • get_suffix($video_id)

just a whole lineup of little getter besties, standing there, doing their thing. 🌟


🌈 playlist($id,$ref)

fetches a playlist and returns a ref to an array of hashes, where each hash represents a video from the playlist with youtube id, runtime in seconds and title. on playlists with many videos, the method iteratively downloads pages until the playlist is complete. she's thorough, she doesn't leave anyone behind. 😭

optionally accepts a second argument β€” a hashref of options. right now you can pass a limit value to stop downloading of subsequent pages on larger playlists after x-amount of fetches. and listen, important detail: it's a limit of fetches, not playlist items. for example, pass 1 to only download the first page of videos from a playlist in order to "skim" the "tip" of new videos in a playlist. and FYI, YouTube currently returns 100 videos at max per page.

this method is used by the youtube-playlists.pl script. so like, if you've used that, you've already met her. 🫢


πŸ‘‘ CONTRIBUTORS πŸ‘‘

yusukebe

we love you yusukebe, thank you for your service. πŸŽ€


πŸ’€ BUG REPORTING πŸ’€

please use github issues: <https://github.com/xaicron/p5-www-youtube-download/issues>.

found a bug? do NOT suffer in silence bestie, go file that issue. it's giving responsible. ✨

⭐ SEE ALSO ⭐


πŸ’– AUTHOR πŸ’–

xaicron <xaicron {@} cpan.org>


this software is copyright (c) 2013 by Yuji Shimada.

this is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. so like, go off, share the love. 🫢


and that's the whole page, bestie!! perl v5.32.0, dated 2020-11-23, and yes, the header at the top calls it WWW::Y...wnload(3pm) because apparently we're all about the drama of the ellipsis now πŸ’… β€” anyway ilysm, go download some videos. πŸŒˆπŸ’–βœ¨

πŸ“¦ where this page comes from