The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

App::WatchLater::YouTube - The YouTube Data API

VERSION

Version 0.02

SYNOPSIS

This is a simple module for making requests to the YouTube Data API. Authorization is required, and can be obtained by registering for an API key from the Google Developer API Console. Alternatively, obtain user authorization through OAuth2 using the yt-oauth(1) script.

my $api = App::WatchLater::YouTube->new(
    access_token => ...,
    api_key      => ...,
);

# returns the body of the HTTP response as a string
my $body = $api->request('GET', '/videos', {
  id => 'Ks-_Mh1QhMc',
  part => 'snippet'
});
...

EXPORT

  • find_video_id - exported by default.

SUBROUTINES/METHODS

find_video_id

my $video_id = find_video_id($url);

Find a YouTube video ID from a YouTube watch URL. Also accepts youtu.be shortened URLs and literal video IDs.

new

my $api = App::WatchLater::YouTube->new(%opts)

This constructor returns a new API object. Attributes include:

  • http - an instance of HTTP::Tiny. If none is provided, a default new instance is used.

  • api_key - an API key.

  • access_token - an OAuth2 access token.

At least one of api_key and access_token must be provided. If both are provided, access_token is used for authorization.

request

my $body = $api->request($method, $endpoint, %params);

Send a request to the specified API endpoint using the given HTTP method. Query parameters may be specified in %params. Croaks if the request fails.

get_video

my \%snippet = $api->get_video($video_id);

Retrieves a YouTube video resource, including the snippet, for the video given by $video_id. Croaks if no such video is found.

AUTHOR

Aaron L. Zeng, <me at bcc32.com>

BUGS

Please report any bugs or feature requests to bug-app-watchlater at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=App-WatchLater. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

You can find documentation for this module with the perldoc command.

perldoc App::WatchLater::YouTube

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

Copyright 2017 Aaron L. Zeng.

This program is distributed under the MIT (X11) License: http://www.opensource.org/licenses/mit-license.php

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.