App-WatchLater

 view release on metacpan or  search on metacpan

lib/App/WatchLater/YouTube.pm  view on Meta::CPAN

package App::WatchLater::YouTube;

use 5.016;
use strict;
use warnings;

=head1 NAME

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

=head1 VERSION

Version 0.03

=cut

our $VERSION = '0.03';


=head1 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 L<API
Console|https://console.developers.google.com/apis/credentials>. 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'
    });
    ...

=head1 EXPORT

=over 4

=item *

C<find_video_id> - exported by default.

=back

=cut

BEGIN {
  require Exporter;
  our @ISA       = qw(Exporter);
  our @EXPORT    = qw(find_video_id);
  our @EXPORT_OK = qw(find_video_id);
}

=head1 SUBROUTINES/METHODS

=head2 find_video_id

    my $video_id = find_video_id($url);

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

=cut

my $regex = qr/[a-z0-9_-]+/i;

sub find_video_id {
  local $_ = shift;
  return $1 if m{youtube\.com/watch.*\bv=($regex)};
  return $1 if m{youtu.be/($regex)};
  return $1 if m{^($regex)$};
  die "'$_' is not a valid video ID";
}

=head2 new

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

This constructor returns a new API object. Attributes include:



( run in 2.117 seconds using v1.01-cache-2.11-cpan-140bd7fdf52 )