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

Video::NRK::Cache::Store - Store NRK Video on Demand cache on disk (abstract base class)

VERSION

version 3.01

SYNOPSIS

 $store = Video::NRK::Cache::Ytdlp->new(
   program_id => 'DVFJ64001010',
   url        => 'https://tv.nrk.no/program/DVFJ64001010',
   meta_title => 'Flåmsbana',
   meta_desc  => 'Bli med frå høgfjell til fjord.',
   options    => { quality => 4, nice => 3 },
 );
 $store->create;

DESCRIPTION

Abstract base class for the different video cache storage implementations.

Your subclass must implement the "download" method, which is not provided by this base class.

This distribution provides the following concrete subclasses:

Video::NRK::Cache::Ytdl

Uses YouTube-dl for downloading. The youtube-dl binary must exist on your PATH.

Video::NRK::Cache::Ytdlp

Uses YT-dlp for downloading. The yt-dlp binary must exist on your PATH.

PARAMETERS

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

meta_desc

A description of the NRK video to cache. Used as meta data. Defaults to an empty string. Optional.

meta_title

The title of the NRK video to cache. Used as file and directory name for the cache store. By default, the program ID is used. Optional.

options

Hash ref with options for the cache. See "OPTIONS". Optional.

program_id

The NRK program ID of the NRK video to cache. Used primarily for naming and as meta data. Required.

url

The URL of the NRK video to cache. Required.

METHODS

Video::NRK::Cache::Store provides accessors for all parameters listed above. Additionally, it provides the following methods:

create
 $store->create;

Create the offline NRK cache store. This is a convenience method, exactly equivalent to the following sequence:

 $store->prep;
 $store->download;
 $store->ffmpeg;
 $store->post;
dir
 $path = $store->dir;

Return the location of the cache store directory as a Path::Tiny object.

dir_mp4
 $path = $store->dir_mp4;

Return the (temporary) location of the video cache file inside the cache store directory as a Path::Tiny object.

dir_sub
 %path_hash = $store->dir_sub;

Return the (temporary) location of the video subtitle cache files inside the cache store directory as a hash of Path::Tiny objects. Has entries for the keys nb_ttv, nb_nor, nn_ttv, nn_nor. Each of these files may or may not actually exist, depending on the subtitles offered for the particular video.

download
 $store->download;

Download video data and subtitles into the cache store directory.

This method is not implemented in this class. Subclasses are expected to provide it.

ffmpeg
 $store->ffmpeg;

Use FFmpeg for post-processing. In particular, subtitles and meta data need to be added to the target cache file.

file
 $path = $store->file;

Return the location of the target cache file as a Path::Tiny object.

nice
 $nice = $store->nice;

Return the value of the nice option. See "OPTIONS".

post
 $store->post;

Ensure any necessary cleanup steps have been taken. In particular, the cache store directory should be removed (but the target cache file preserved).

prep
 $store->prep;

Ensure all necessary preparations for downloading video data into the cache have been taken. In particular, the target cache file must not exist and the cache store directory must have been created.

quality
 $quality = $store->quality;

Return the value of the quality option. See "OPTIONS".

rate
 $kbyte_per_sec = $store->rate;

Return the suggested maximum transfer rate in kilobytes per second, based on the value of the nice option.

system
 $store->system( $cmd, @args );

Equivalent to "system" in perlfunc, but additionally prints a summary of the system call to stdout and checks for errors.

OPTIONS

Video::NRK::Cache::Store accepts the following options, which are to be provided as hash entries to the options parameter:

nice

The nice option is an integer describing bandwidth reduction. Increasing this value may reduce the bandwidth used by the program. The value 0 means no bandwidth limitation. The value 1 is the default and limits bandwidth to 1600 kB/s.

Reducing the bandwidth may be useful when the caching is done on a good network connection for later viewing, where it prevents the overuse of network and server resources. It may also be useful on a bad network connection to keep the remaining bandwidth available for other purposes.

quality

The quality option is an integer describing the format of the AV content to store in the cache. Usually the AV quality for NRK content ranges from 0 to 5.

If this option is not given, by default quality 3 is preferred when available, otherwise the highest numerical value available is chosen. AV content at quality 3 means "540p" or "qHD" resolution, which is similar to Standard Definition TV (though typically encoded at higher quality than standard TV). It may sound old-fashioned, but it saves valuable bandwidth, and for a lot of TV programs, this quality is actually plenty fine.

LIMITATIONS

The code deciding the output filename seems fairly brittle and should probably be overhauled. In particular, a suitable output file name should ideally start with the numeric season/episode code if available and continue with the name of the program (if this is a TV episode with a name of its own, the show name should be excluded). It should perhaps always end with the program ID (although this may be redundant, given that the ID is also in the meta data). Spaces should be used for separation on macOS, hyphens otherwise. These considerations are currently unimplemented.

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.

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.