subtitlefile

package
v0.10.0-dev.47 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Nov 9, 2026 License: AGPL-3.0 Imports: 7 Imported by: 0

Documentation

Overview

Package subtitlefile is the subtitle file name grammar, <stem>.<language>[.sdh][.forced][.<N>].<ext>, and which video in a folder owns a name. The names land on SMB and NFS shares that media servers read, so the segment order is a compatibility contract: Parse must read back every name Build writes.

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrZeroTag       = errors.New("subtitlefile: a name needs a language")
	ErrTagUnreadable = errors.New("subtitlefile: the language segment reads back as another language")
	ErrOrdinal       = errors.New("subtitlefile: an ordinal is from 1 to 999,999,999")
	ErrNotWritable   = errors.New("subtitlefile: no writer produces this extension")
)

The refusals of Build.

Functions

func Build

func Build(stem string, n Name) (string, error)

Build is the name of n beside a video whose stem is stem. It writes HI as .sdh (Jellyfin reads .hi after a language it does not know as Hindi) and both flags when both are set. Parse(stem, name) is n for every name Build returns: a Tag whose segment reads back as another language (language FilenameTag "cht" is Cholon but reads as Traditional Chinese) is ErrTagUnreadable.

func IsVideo

func IsVideo(name string) bool

IsVideo reports whether name, in any ASCII case, is a video file with a non-empty Stem, so Owner never sees the empty stem that would own every name beginning with a dot.

func LooksLikeText

func LooksLikeText(head []byte) bool

LooksLikeText reports whether at most a tenth of head is control bytes other than TAB, LF, VT, FF, CR and ESC: subtitle text passes, a binary container does not.

func Owner

func Owner(stems []string, name string) (string, bool)

Owner is the video stem among stems that owns name: the longest one that, followed by ".", prefixes it, so Movie.Extended.en.srt belongs to Movie.Extended beside Movie. stems holds the Stem of each IsVideo name in the folder, so two videos sharing a stem (Movie.mkv, Movie.mp4) appear twice and own none of its names. False: no video owns name.

func Stem

func Stem(videoName string) string

Stem is a video file name without its extension.

Types

type Ext

type Ext uint8

Ext is a subtitle extension the inventory reads. ExtVobSub (.sub) is on disk only: no writer produces it and timing.ParseCues refuses its payload.

const (
	ExtSRT Ext = iota + 1
	ExtASS
	ExtSSA
	ExtVobSub
)

The extensions; the zero Ext is none.

func ExtOf

func ExtOf(f timing.Format) Ext

ExtOf is the extension a writer uses for f; the zero Ext for the zero Format.

func (Ext) String

func (e Ext) String() string

String is the extension with its dot; "" for the zero or an unknown Ext.

type Name

type Name struct {
	Tag     language.Tag
	Ordinal int // 0: unnumbered; 1 to 999,999,999
	Flags   language.Flags
	Ext     Ext
}

Name is what a subtitle file name says beside its video's stem.

func Parse

func Parse(stem, name string) (Name, bool)

Parse reads name as a subtitle of the video whose stem is stem: the first segment after "<stem>." is always the language (language.ReadFilename, so "sdh" there is Southern Kurdish and "hi" Hindi), then hi, sdh or cc as HI and forced or foreign as Forced in either order, then an ordinal from 1 with no leading zero, then an extension subtitleext.OnDisk accepts. "<stem>.srt" is the zero Tag. False: name is not this grammar.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL