Rand Stats

WWW::YouTube

zef:antononcube

WWW::YouTube

Raku package for getting metadata and transcripts of YouTube videos.

The Raku implementation closely follows the Wolfram Language function YouTubeTranscript, [AAf1].


Installation

From Zef ecosystem:

zef install WWW::YouTube

From GitHub:

zef install https://github.com/antononcube/Raku-WWW-YouTube.git

Usage

youtube-metadata($id)

youtube-playlist($id)

youtube-transcript($id)


Details


Examples

Metadata

Get the metadata associated with a YouTube video identifier:

use WWW::YouTube;
use Data::Translators;

youtube-metadata('S_3e7liz4KM') 
==> to-html(align => 'left')
descriptionComputationally neat examples with Raku packages featuring graphs and graph plots. (3rd set.)\n\nHere is the presentation Jupyter notebook: https://github.com/antononcube/RakuForPrediction-blog/blob/main/Presentations/Notebooks/Graph-neat-examples-set-3.ipynb\n\n------------------\n\nPlease, consider buying me a coffee: https://buymeacoffee.com/antonov70
publish-date2024-11-28T11:24:44-08:00
titleGraph neat examples in Raku (Set 3)
view-count139 views
channel-titleN/A

Transcripts

my $transcript = youtube-transcript('ewU83vHwN8Y');

say $transcript.chars;

say $transcript.substr(^300);
# 36700
# Hi everyone, welcome to a wolf from
# language design review for version 14.3.
# We are talking about LLM
# graph. So,
# okay. So this is for the purpose of of
# knitting together LLM calls like LLM
# function type calls.
# Exactly.
# To support more complex workflows
# um and and to have asynchronous calls to
# LLMs.

Summarize using a Large Language Model (LLM):

use LLM::Functions;
use LLM::Prompts;

llm-synthesize(llm-prompt('Summarize')($transcript), e => 'Gemini')
# This language design review introduces LLM graphs, which orchestrate calls to LLMs for complex workflows, including asynchronous execution.  LLM graphs use nodes containing prompts or code (node functions) that can depend on each other, with inputs and outputs managed through associations.  The design includes features like listable templates and conditional execution, and it aims to provide a powerful, yet simple, way to build agentic workflows.

Get the transcript as a dataset:

my @t = youtube-transcript('S_3e7liz4KM', format => 'dataset');

@t.head(10) ==> to-html(field-names => <time duration content>, align => 'left')
timedurationcontent
0.524.64this presentation is titled graph neat
2.85.2examples in Raku set
5.164.84three my name is Anton Antonov today's
85November 28th
1062024 I have prepared two sets of
136.68examples nested graphs and file system
165.72graphs the neat examples in general are
19.683.96defined as concise or straightforward
21.723.76code that produce compelling visual
23.644.399textual outputs I'm going to be

Playlists

youtube-playlist('PLke9UbqjOSOiMnn8kNg6pb3TFWDsqjNTN')
# [fwQrQyWC7R0 S_3e7liz4KM E7qhutQcWCY kQo3wpiUu6w JHO2Wk1b-Og 5qXgqqRZHow 0uJl9q7jIf8]

CLI

The package provides Command Line Interface (CLI) scripts. Here are their usage messages:

youtube-metadata --help
# Usage:
#   youtube-metadata <id> [--format=<Str>] -- Get YouTube video metadata.
#   
#     <id>              Video identifier
#     --format=<Str>    Format of the result, one of 'json', 'raku', 'asis'. [default: 'json']
youtube-playlist --help
# Usage:
#   youtube-playlist <id> -- Get video identifiers of a YouTube playlist.
#   
#     <id>    Video playlist identifier
youtube-transcript --help
# Usage:
#   youtube-transcript <id> [--format=<Str>] -- Get YouTube transcripts.
#   
#     <id>              Video identifier
#     --format=<Str>    Format of the result, one of 'text', 'dataset', or 'json'. [default: 'text']

TODO


References

[AAf1] Anton Antonov, YouTubeTranscript, (2025), Wolfram Function Repository.