NAME

Video::NRK::Cache - Cache NRK Video on Demand broadcasts for offline viewing

VERSION

version 3.00

SYNOPSIS

my $cache = Video::NRK::Cache->new( url => 'DVFJ64001010' );
say "Creating cache from URL: ", $cache->url;
$cache->store->create;

Video::NRK::Cache->new(
  url => 'https://tv.nrk.no/program/DVFJ64001010',
  options => { nice => 3, quality => 2 },
  store_class => 'Video::NRK::Cache::Ytdl',
)->store->create;

DESCRIPTION

The Video-on-Demand programs of the Norwegian Broadcasting Corporation (NRK) can be difficult to watch over a slow or unstable network connection. This script creates a local cache of such video programs in an MPEG-4 container, enabling users to watch without interruptions.

For network transport, this class by default uses YT-dlp. Norwegian subtitles and metadata are retrieved from NRK as well. The data is muxed into a single MP4 file using FFmpeg.

PREREQUISITES

FFmpeg

This software expects the FFmpeg executable to be available on your PATH as ffmpeg. See ffmpeg.org and Alien::ffmpeg.

YT-dlp

This software by default expects the YT-dlp executable to be available on your PATH as yt-dlp. Alternatives are optionally supported. See "store_class" and github.com/yt-dlp.

PARAMETERS

When constructing a Video::NRK::Cache object, new() accepts the following parameters:

meta

Meta data to be used for the cache. A hash ref with the entries title and/or desc. If not provided as parameter, this is determined automatically using NRK's PSAPI. Optional.

options

Options for the cache. A hash ref with the entries nice and/or quality. See "OPTIONS" in Video::NRK::Cache::Store. Optional.

psapi_base

The base URL of NRK's Programspiller API. By default, this software uses the fixed value https://psapi.nrk.no or tries to determine the base URL from NRK's web site. Optional.

store_class

Name of the class that implements storing the video in the cache. By default, Video::NRK::Cache::Ytdlp is used. Another subclass of Video::NRK::Cache::Store may be named here. Optional.

url

The URL of the NRK video to cache. Also accepts a NRK program ID. Required.

METHODS

Video::NRK::Cache provides the following methods:

get_json
$hashref = $cache->get_json( $endpoint );

Query NRK's PSAPI for the endpoint provided and return the decoded result. If the string {id} is present in $endpoint, it will be replaced with the NRK program ID.

get_metadata
$cache->get_metadata;

Determine the meta data to be used for storing the cached video using NRK's PSAPI.

program_id
$program_id = $cache->program_id;

Return the NRK program ID of the video being cached, as a string.

store
$cache->store;

Return the Video::NRK::Cache::Store object.

url
$url = $cache->url;

Return the URL of the NRK video being cached.

LIMITATIONS

The caching of multiple videos at the same time is currently unsupported.

This software's OOP API is new and still evolving. Additionally, this software uses perlclass, which is an experimental feature. The class structure and API will likely be redesigned in future, once the implementation of Corinna in Perl is more complete.

SEE ALSO

https://psapi.nrk.no/documentation/redoc/programsider-tv/

AUTHOR

Arne Johannessen <ajnn@cpan.org>

If you contact me by email, please make sure you include the word "Perl" in your subject header to help beat the spam filters.

COPYRIGHT AND LICENSE

Arne Johannessen has dedicated the work to the Commons by waiving all of his or her rights to the work worldwide under copyright law and all related or neighboring legal rights he or she had in the work, to the extent allowable by law.

Works under CC0 do not require attribution. When citing the work, you should not imply endorsement by the author.