Expand description
§rsynko-media
rsynko-media states what a media item is, how it is described, chosen, produced, and named, and how those meanings compose into one download program. These specifications are always used together, so they live together as modules of one package. It chooses no extractor, network library, serialization format, or filesystem.
§Observation
An observation record is an open, keyed, heterogeneous collection of values. It is open because an extractor may state fields the core has never heard of, keyed because later fields with equal keys replace earlier ones, and heterogeneous because sources describe themselves in whatever shapes they use. MetadataAlg constructs records and values in an interpreter-chosen carrier; InfoRecord and InfoValue reify them.
A format denotes one alternative representation of a media item: an identity together with everything observed about it. It fixes no schema. Where its bytes rest, which streams it carries, its container, and every quantity selection compares are observations. An artifact denotes one produced file the same way, classified by the role it plays.
FormatAlg defines one format from an identity and everything observed about it, and FormatViewAlg observes one named value back. A derived operation composes the three without naming a representation:
use alux_ext::ext;
use rsynko_media::{FORMAT_EXTENSION, FORMAT_SOURCE, FormatAlg, FormatViewAlg, MetadataAlg};
#[ext(name = LocatedFormatExt)]
impl<This> This
where
This: MetadataAlg + FormatAlg + FormatViewAlg,
{
/// Defines one format from where its bytes rest and the container it states.
fn located_format(&self, id: &str, url: &str, extension: &str) -> This::Format {
self.format(
id,
self.metadata([
(FORMAT_SOURCE.to_owned(), self.string_metadata(url)),
(FORMAT_EXTENSION.to_owned(), self.string_metadata(extension)),
]),
)
}
/// Observes where a format's bytes rest, exactly when it stated that.
fn located_source<'a>(&self, format: &'a This::Format) -> Option<&'a str> {
self.format_text(format, FORMAT_SOURCE)
}
}The well-known keys named here — FORMAT_SOURCE, FORMAT_EXTENSION, FORMAT_HAS_AUDIO, FORMAT_HAS_VIDEO, ARTIFACT_LOCATION — are conventions, not fields. An extractor that states them gains the derived observations; one that does not is still complete, and an operation needing an unstated observation says so rather than inventing a value.
§Extraction
An extraction result denotes one playable media description, a reference requiring another extraction, or an ordered collection of further results. ExtractionCatalogAlg exposes extractor order and acceptance, ExtractionApplyAlg applies one selected key, and ExtractionExt derives first-accepting choice and URL extraction from exactly those two.
ExtractionAlg defines those three shapes, ExtractionViewAlg observes when a result denotes exactly one media item, and MediaViewAlg observes that item’s identity, title, and formats in extractor order.
§Selection
A catalog’s order means increasing preference. Every predicate primitive except identity ranges over observations, so one set of primitives speaks about any field an extractor recorded. FormatPredicateExt derives the named predicates — has_audio, has_video, format_extension — and the comparisons at_most, at_least, exactly, less_than, and greater_than from them. FormatPredicateMatchAlg observes whether one format satisfies one predicate, and FormatSelectionApplyAlg interprets a whole program against a catalog. Interpreting reified syntax is an interpreter rather than a derived operation, so interpret_selection states the canonical fold and an interpreter that chose the reified sorts delegates to it.
FormatPredicateAlg constructs the primitives, FormatSelectionAlg composes them into best, worst, merge, and fallback programs, and FormatSelectionApplyAlg interprets a whole program against a catalog.
Interpreting that program against a catalog is FormatSelectionApplyAlg, and a reference interpreter for these sorts lives in rsynko-memory.
§Processing and output
A processing program denotes an ordered sequence of named artifact transformations, each assigned to one stage. Interpreting a program applies every step in declaration order; interpreting a stage applies the subsequence belonging to it without reordering. Portable output naming is a separate pure meaning: it admits one Linux and Windows safe file component, bounds the stem, and falls back to a stated identity.
§The composed program
FormatSourceAlg is the only bridge from a selected format to a retrieval carrier, and it may state that a format cannot be located from what was observed. MediaDownloadExt::download_extraction and ApplicationExt::download_url compose extraction, selection, naming, and one-resource download over that bridge. A protocol specification specializes the source description while preserving every other meaning.
use alux_ext::ext;
use rsynko_download::{
AtomicPublishAlg, DownloadObservationAlg, DownloadProgressAlg, DownloadReportAlg,
FetchStreamAlg,
};
use rsynko_media::{
ExtractionViewAlg, FormatPredicateAlg, FormatSelectionAlg, FormatSelectionApplyAlg,
FormatSelectionProgramExt, FormatSourceAlg, FormatViewAlg, MediaDownloadError,
MediaDownloadExt, MediaViewAlg, OutputTarget,
};
use std::fmt::Display;
use std::path::PathBuf;
#[ext(name = PreferredMediaExt)]
impl<This, Source, FetchError, Stream, PublishError, Event, Progress> This
where
This: ExtractionViewAlg
+ MediaViewAlg
+ FormatViewAlg
+ FormatPredicateAlg
+ FormatSelectionAlg
+ FormatSelectionApplyAlg
+ FormatSourceAlg<Source>
+ FetchStreamAlg<Source, Error = FetchError, Stream = Stream>
+ AtomicPublishAlg<Error = PublishError>
+ DownloadObservationAlg<Event = Event, Progress = Progress>
+ DownloadProgressAlg<Progress = Progress>
+ DownloadReportAlg<Event = Event>,
FetchError: Display,
PublishError: Display,
{
/// Publishes one extraction through the named format, falling back to the best progressive one.
fn download_preferred(
&self,
extraction: This::Extraction,
format_id: &str,
target: &OutputTarget,
) -> Result<PathBuf, MediaDownloadError<FetchError, PublishError>> {
let selection = self.preferred_progressive_format(format_id);
self.download_extraction(extraction, &selection, target)
}
}§Laws
- the empty observation record is neutral, later equal keys replace earlier ones, and observation is total into an option;
- an unstated truth denotes falsity, and a typed observation succeeds exactly when the stated value has that type;
- choosing returns the first accepting extractor, and no extractor exactly when no catalog entry accepts the URL;
- extracting a supported URL applies exactly the chosen extractor and an unsupported URL applies none;
BestandWorstdiffer only by which end of the same preference order they choose;Mergesucceeds exactly when every child succeeds and preserves child order, andFallbackis left-biased;- a predicate speaking about an unstated observation accepts no format;
- the empty processing program is an identity, concatenation denotes sequential composition, stage selection preserves declaration order, and failure stops interpretation before later steps;
- portable naming depends only on the stated title, fallback identity, and extension;
- extraction happens before selection, exactly one selected format is required, naming depends only on the extraction, selected format, and output target, and the source
FormatSourceAlgproduces is passed unchanged to the generic download meaning.
Macros§
- ambassador_
impl_ Artifact Alg - A macro to be used by
ambassador::Delegateto delegateArtifactAlg - ambassador_
impl_ Extraction Alg - A macro to be used by
ambassador::Delegateto delegateExtractionAlg - ambassador_
impl_ Extraction Apply Alg - A macro to be used by
ambassador::Delegateto delegateExtractionApplyAlg - ambassador_
impl_ Extraction Catalog Alg - A macro to be used by
ambassador::Delegateto delegateExtractionCatalogAlg - ambassador_
impl_ Extraction View Alg - A macro to be used by
ambassador::Delegateto delegateExtractionViewAlg - ambassador_
impl_ Format Alg - A macro to be used by
ambassador::Delegateto delegateFormatAlg - ambassador_
impl_ Format Predicate Alg - A macro to be used by
ambassador::Delegateto delegateFormatPredicateAlg - ambassador_
impl_ Format Predicate Match Alg - A macro to be used by
ambassador::Delegateto delegateFormatPredicateMatchAlg - ambassador_
impl_ Format Selection Alg - A macro to be used by
ambassador::Delegateto delegateFormatSelectionAlg - ambassador_
impl_ Format Selection Apply Alg - A macro to be used by
ambassador::Delegateto delegateFormatSelectionApplyAlg - ambassador_
impl_ Format View Alg - A macro to be used by
ambassador::Delegateto delegateFormatViewAlg - ambassador_
impl_ Media View Alg - A macro to be used by
ambassador::Delegateto delegateMediaViewAlg - ambassador_
impl_ Metadata Alg - A macro to be used by
ambassador::Delegateto delegateMetadataAlgA macro to be used byambassador::Delegateto delegateMetadataAlgA macro to be used byambassador::Delegateto delegateMetadataAlg - ambassador_
impl_ Metadata View Alg - A macro to be used by
ambassador::Delegateto delegateMetadataViewAlgA macro to be used byambassador::Delegateto delegateMetadataViewAlgA macro to be used byambassador::Delegateto delegateMetadataViewAlg - ambassador_
impl_ Output Name Alg - A macro to be used by
ambassador::Delegateto delegateOutputNameAlg - ambassador_
impl_ Processing Program Alg - A macro to be used by
ambassador::Delegateto delegateProcessingProgramAlg
Enums§
- Application
Error - Denotes failure of an ordinary direct-resource media program.
- Artifact
Kind - Classifies a produced artifact by its semantic role.
- Collection
Kind - Classifies an ordered extraction collection.
- Extract
UrlError - Denotes failure to derive extraction from an input URL.
- Format
Comparison - Denotes how an observed number is compared against a stated one.
- Media
Download Error - Denotes failure after extraction has produced a media description.
- Output
Target - Selects how a final output path is denoted.
- Processing
Stage - Names the public processing stages in their product order.
Constants§
- ARTIFACT_
LOCATION - Names the observation stating where an artifact currently rests.
- FORMAT_
EXTENSION - Names the observation stating a format’s container or filename extension.
- FORMAT_
HAS_ AUDIO - Names the observation stating whether a format contains audio.
- FORMAT_
HAS_ VIDEO - Names the observation stating whether a format contains video.
- FORMAT_
SOURCE - Names the observation locating a format’s bytes when an extractor states one.
Traits§
- Application
Ext - Derives ordinary extraction, format selection, destination naming, and download.
- Artifact
Alg - Provides the carrier and constructor for produced artifacts.
- Artifact
Laws - Authors the produced-artifact laws.
- Extraction
Alg - Provides the carriers and constructors for extraction results.
- Extraction
Apply Alg - Specifies application of one selected extractor.
- Extraction
Catalog Alg - Specifies an ordered catalog of extractor meanings.
- Extraction
Ext - Derives ordered extractor choice and URL extraction from primitive capabilities.
- Extraction
LawFixture - Supplies the catalog-dependent inputs an extraction scenario cannot author for itself.
- Extraction
Laws - Authors the ordered-extractor-choice laws over a catalog the interpreter supplies.
- Extraction
View Alg - Specifies observation of what shape an extraction result denotes.
- Format
Alg - Provides the carriers and constructor for one alternative representation.
- Format
Laws - Authors the format-observation laws.
- Format
Predicate Alg - Provides the carrier and primitive constructors for format predicates.
- Format
Predicate Ext - Derives named and comparative predicates from primitive observation construction.
- Format
Predicate Match Alg - Specifies interpretation of reified format predicates.
- Format
Selection Alg - Provides the carrier and primitive constructors for selection programs.
- Format
Selection Apply Alg - Specifies interpretation of a selection program against a preference-ordered catalog.
- Format
Selection Program Ext - Derives common selection programs by equating predicate carriers.
- Format
Source Alg - Specifies how one generic format denotes a retrievable source carrier.
- Format
View Alg - Specifies observation of what one format states about itself.
- Media
Download Ext - Derives selection, naming, and download for an already extracted result.
- Media
Output Ext - Derives a final path from media observations, the selected format, and the output target.
- Media
Program LawFixture - Supplies the retrieval inputs a media-program scenario cannot author for itself.
- Media
Program Laws - Authors the composed media-download laws.
- Media
Sorts - The sorts of media meaning — the Rust encoding of the type families the media algebra classes share.
- Media
View Alg - Specifies the observations one media item offers.
- Metadata
Alg - Provides the carriers and constructors for open metadata.
- Metadata
Ext - Derives concise metadata records from primitive construction.
- Metadata
View Alg - Specifies reading back what one metadata record states.
- Observation
Laws - Authors the open-record laws.
- Output
Name Alg - Provides the carrier and constructor for one portable output name.
- Output
Name Ext - Derives portable output names independently of their carrier.
- Output
Name Laws - Authors the portable-output-naming laws.
- Processing
Application Laws - Authors the processing-application laws.
- Processing
Apply Alg - Specifies application of primitive artifact-processing steps.
- Processing
Ext - Derives complete-program and single-stage processing from primitive step application.
- Processing
LawFixture - Supplies the application trace a processing scenario cannot author for itself.
- Processing
Laws - Authors the processing-program laws.
- Processing
Program Alg - Provides the carriers and primitive constructors for processing programs.
- Processing
Program Ext - Derives concise processing-program construction.
- Processing
Program View Alg - Specifies observation of a reified processing program.
- Processing
Sorts - The sorts of artifact-processing meaning.
- Selection
Laws - Authors the selection-program laws.
Functions§
- portable_
file_ name - Derives a portable file name from a title, fallback identity, and selected extension.
- portable_
file_ stem - Derives a portable single-component file stem from a title and fallback identity.
- portable_
user_ file_ name - Normalizes an edited file name while preserving a valid explicit extension.