core

package
v0.0.0-...-84503e1 Latest Latest
Warning

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

Go to latest
Published: Feb 8, 2025 License: GPL-3.0 Imports: 35 Imported by: 0

Documentation

Index

Constants

View Source
const (
	StrippedSDH = iota
	Sub
	Dub
	CC
)
View Source
const (
	//ContinueProcessing	= "continue"
	//ContinueWithWarning	= "warning"
	ProbeUser     = "probe"
	AbortTask     = "abort_task"
	AbortAllTasks = "abort_all"
)
View Source
const (
	Subs2Cards = iota
	Subs2Dubs
	Enhance
	Translit
)

Variables

View Source
var AstisubSupportedExt = []string{".srt", ".ass", ".ssa", "vtt", ".stl", ".ttml"}
View Source
var CodecToExtension = map[string]string{
	"MP3":        ".mp3",
	"AAC":        ".aac",
	"WMA":        ".wma",
	"FLAC":       ".flac",
	"ALAC":       ".m4a",
	"Opus":       ".opus",
	"Vorbis":     ".ogg",
	"PCM":        ".wav",
	"WAV":        ".wav",
	"AIFF":       ".aiff",
	"RealAudio":  ".ra",
	"AMR":        ".amr",
	"MPEG-4 ALS": ".mp4",
	"MPEG Audio": ".mp3",
	"AC-3":       ".ac3",
	"DTS":        ".dts",
	"TrueHD":     ".thd",
	"E-AC-3":     ".eac3",
	"MKA":        ".mka",
	"WebM":       ".webm",
	"Speex":      ".spx",
	"Musepack":   ".mpc",
}
View Source
var MediainfoPath = "mediainfo"
View Source
var (
	Splitter = "𓃰" // All providers must accept and return UTF-8.

)

Functions

func Base2Absolute

func Base2Absolute(s, dir string) string

func IsFlagBoolSet

func IsFlagBoolSet(cmd *cobra.Command, flagName string) (bool, bool)

func IsFlagIntSet

func IsFlagIntSet(cmd *cobra.Command, flagName string) (bool, int)

func IsFlagStrSet

func IsFlagStrSet(cmd *cobra.Command, flagName string) (bool, string)

func IsZeroLengthTimespan

func IsZeroLengthTimespan(last, t time.Duration) (b bool)

func SetPrefered

func SetPrefered(langs []Lang, l, atm Lang, filename string, out *string, Native *Lang) bool

func Str

func Str(l *iso.Language) string

func Subs2StringBlock

func Subs2StringBlock(subs *astisub.Subtitles) (mergedSubsStr string, subSlice []string)

func TagsStr2TagsArr

func TagsStr2TagsArr(tagsString string) []string

Types

type AudioTrack

type AudioTrack struct {
	Type                     string `json:"@type"`
	StreamOrder              string `json:"StreamOrder"`
	ID                       string `json:"ID"`
	Format                   string `json:"Format"`
	FormatCommercialIfAny    string `json:"Format_Commercial_IfAny"`
	FormatSettingsSBR        string `json:"Format_Settings_SBR"`
	FormatAdditionalFeatures string `json:"Format_AdditionalFeatures"`
	CodecID                  string `json:"CodecID"`
	Duration                 string `json:"Duration"`
	BitRateMode              string `json:"BitRate_Mode"`
	BitRate                  string `json:"BitRate"`
	Channels                 string `json:"Channels"`
	ChannelPositions         string `json:"ChannelPositions"`
	ChannelLayout            string `json:"ChannelLayout"`
	SamplesPerFrame          string `json:"SamplesPerFrame"`
	SamplingRate             string `json:"SamplingRate"`
	SamplingCount            string `json:"SamplingCount"`
	FrameRate                string `json:"FrameRate"`
	FrameCount               string `json:"FrameCount"`
	CompressionMode          string `json:"Compression_Mode"`
	StreamSize               string `json:"StreamSize"`
	StreamSizeProportion     string `json:"StreamSize_Proportion"`
	Title                    string `json:"Title"`
	LangRaw                  string `json:"Language"`
	Language                 *iso.Language
	Default                  string `json:"Default"`
	AlternateGroup           string `json:"AlternateGroup"`
}

AudioTrack represents the information about the audio stream in the media file

type CLIHandler

type CLIHandler struct {
	// contains filtered or unexported fields
}

CLI implementation

func NewCLIHandler

func NewCLIHandler() *CLIHandler

func (*CLIHandler) GetLogBuffer

func (h *CLIHandler) GetLogBuffer() bytes.Buffer

func (*CLIHandler) GetSnapshotsString

func (h *CLIHandler) GetSnapshotsString() string

func (*CLIHandler) HandleProgress

func (h *CLIHandler) HandleProgress(current, total int, description string)

func (*CLIHandler) HandleStatus

func (h *CLIHandler) HandleStatus(status string)

func (*CLIHandler) IsCLI

func (h *CLIHandler) IsCLI() bool

func (*CLIHandler) Log

func (h *CLIHandler) Log(level int8, behavior string, msg string) *ProcessingError

func (*CLIHandler) LogErr

func (h *CLIHandler) LogErr(err error, behavior string, msg string) *ProcessingError

func (*CLIHandler) LogErrFields

func (h *CLIHandler) LogErrFields(err error, behavior string, msg string, fields map[string]interface{}) *ProcessingError

func (*CLIHandler) LogFields

func (h *CLIHandler) LogFields(level int8, behavior string, msg string, fields map[string]interface{}) *ProcessingError

func (*CLIHandler) SaveSnapshot

func (h *CLIHandler) SaveSnapshot(state string, task *Task)

func (*CLIHandler) ZeroLog

func (h *CLIHandler) ZeroLog() *zerolog.Logger

type CreatingLibrary

type CreatingLibrary struct {
	Name    string `json:"name"`
	Version string `json:"version"`
}

CreatingLibrary represents the information about the library used to create the media information

type GUIHandler

type GUIHandler struct {
	// contains filtered or unexported fields
}

GUI implementation

func NewGUIHandler

func NewGUIHandler(ctx context.Context) *GUIHandler

func (*GUIHandler) GetLogBuffer

func (h *GUIHandler) GetLogBuffer() bytes.Buffer

func (*GUIHandler) GetSnapshotsString

func (h *GUIHandler) GetSnapshotsString() string

func (*GUIHandler) HandleProgress

func (h *GUIHandler) HandleProgress(current, total int, description string)

func (*GUIHandler) HandleStatus

func (h *GUIHandler) HandleStatus(status string)

func (*GUIHandler) IsCLI

func (h *GUIHandler) IsCLI() bool

func (*GUIHandler) Log

func (h *GUIHandler) Log(level int8, behavior string, msg string) *ProcessingError

func (*GUIHandler) LogErr

func (h *GUIHandler) LogErr(err error, behavior string, msg string) *ProcessingError

func (*GUIHandler) LogErrFields

func (h *GUIHandler) LogErrFields(err error, behavior string, msg string, fields map[string]interface{}) *ProcessingError

func (*GUIHandler) LogFields

func (h *GUIHandler) LogFields(level int8, behavior string, msg string, fields map[string]interface{}) *ProcessingError

func (*GUIHandler) SaveSnapshot

func (h *GUIHandler) SaveSnapshot(state string, task *Task)

func (*GUIHandler) ZeroLog

func (h *GUIHandler) ZeroLog() *zerolog.Logger

type GeneralTrack

type GeneralTrack struct {
	Type                  string `json:"@type"`
	VideoCount            string `json:"VideoCount"`
	AudioCount            string `json:"AudioCount"`
	FileExtension         string `json:"FileExtension"`
	Format                string `json:"Format"`
	FormatProfile         string `json:"Format_Profile"`
	CodecID               string `json:"CodecID"`
	CodecIDCompatible     string `json:"CodecID_Compatible"`
	FileSize              string `json:"FileSize"`
	Duration              string `json:"Duration"`
	OverallBitRate        string `json:"OverallBitRate"`
	FrameRate             string `json:"FrameRate"`
	FrameCount            string `json:"FrameCount"`
	StreamSize            string `json:"StreamSize"`
	HeaderSize            string `json:"HeaderSize"`
	DataSize              string `json:"DataSize"`
	FooterSize            string `json:"FooterSize"`
	IsStreamable          string `json:"IsStreamable"`
	Title                 string `json:"Title"`
	Collection            string `json:"Collection"`
	Season                string `json:"Season"`
	Track                 string `json:"Track"`
	Description           string `json:"Description"`
	RecordedDate          string `json:"Recorded_Date"`
	FileModifiedDate      string `json:"File_Modified_Date"`
	FileModifiedDateLocal string `json:"File_Modified_Date_Local"`
	EncodedApplication    string `json:"Encoded_Application"`
	Cover                 string `json:"Cover"`
	Extra                 struct {
		PartID string `json:"Part_ID"`
	} `json:"extra"`
}

GeneralTrack represents the general information about the media file

type IndexedSubItem

type IndexedSubItem struct {
	Index int
	Item  *astisub.Item
}

IndexedSubItem wraps a subtitle item along with its original index.

type Lang

type Lang struct {
	*iso.Language
	Subtag string // Typically a ISO 3166-1 region but can also be a ISO 15924 script
}

func GuessLangFromFilename

func GuessLangFromFilename(name string) (lang Lang, err error)

Only 1st subtag found is considered, the others are ignored

func ParseLanguageTags

func ParseLanguageTags(arr []string) (langs []Lang, err error)

Exemple of input slice: []string{"pt-BR", "yue", "zh-Hant"}

func (*Lang) String

func (l *Lang) String() string

type LogWriter

type LogWriter struct {
	// contains filtered or unexported fields
}

LogWriter must implement io.Writer for zerolog.MultiLevelWriter

func (*LogWriter) Write

func (w *LogWriter) Write(p []byte) (n int, err error)

type MediaInfo

type MediaInfo struct {
	CreatingLibrary CreatingLibrary
	GeneralTrack    GeneralTrack
	VideoTrack      VideoTrack
	AudioTracks     []AudioTrack
}

MediaInfo represents the media information including general, video, and audio tracks

func Mediainfo

func Mediainfo(path string) (media MediaInfo)

Mediainfo() processes each track by dynamically determining the type based on the @type field

type MessageHandler

type MessageHandler interface {
	IsCLI() bool

	Log(level int8, behavior string, msg string) *ProcessingError
	LogErr(err error, behavior string, msg string) *ProcessingError
	LogFields(level int8, behavior string, msg string, fields map[string]interface{}) *ProcessingError
	LogErrFields(err error, behavior string, msg string, fields map[string]interface{}) *ProcessingError

	ZeroLog() *zerolog.Logger
	GetLogBuffer() bytes.Buffer
	HandleProgress(current, total int, description string) //TODO
	HandleStatus(status string)                            //TODO
	SaveSnapshot(state string, task *Task)
}

type Meta

type Meta struct {
	FFmpeg     string
	MediaInfo  MediaInfo
	WorkersMax int
}

type Mode

type Mode int

func (Mode) String

func (m Mode) String() string

type ProcessedItem

type ProcessedItem struct {
	Index       int
	AlreadyDone bool
	Sound       string
	Time        string
	Source      string
	Image       string
	ForeignCurr string
	NativeCurr  string
	ForeignPrev string
	NativePrev  string
	ForeignNext string
	NativeNext  string
}

ProcessedItem represents the exported information of a single subtitle item.

type ProcessedItemWriter

type ProcessedItemWriter func(*os.File, *ProcessedItem)

type ProcessingError

type ProcessingError struct {
	Err      error
	Behavior string
	//Level    int8				// probably unneeded
	//Message  string			// probably unneeded
	Context map[string]interface{} // probably unneeded
}

type ProcessingSnapshot

type ProcessingSnapshot struct {
	Timestamp time.Time
	State     string
	TaskDump  string
}

type RawMedia

type RawMedia struct {
	Ref   string            `json:"@ref"`
	Track []json.RawMessage `json:"track"`
}

type RawMediaInfo

type RawMediaInfo struct {
	CreatingLibrary CreatingLibrary `json:"creatingLibrary"`
	Media           RawMedia        `json:"media"`
}

type SelectionHelper

type SelectionHelper func(*Task, int, AudioTrack) error

type Task

type Task struct {
	Handler MessageHandler
	Meta    Meta
	Mode    Mode

	// Language settings
	OriginalLang string // FIXME what for?
	Langs        []string
	RefLangs     []Lang
	Targ         Lang
	Native       Lang

	// File paths
	// mediaSourceFile is the path of the actual media provided or any media found while routing()
	MediaSourceFile string
	TargSubFile     string
	NativeSubFile   string
	// mediaprefix is the base string for building AVIF / OPUS to which timecodes of a subtitle line will be added.
	MediaPrefix string // base string for building AVIF/OPUS

	// Subtitles
	NativeSubs *subs.Subtitles
	TargSubs   *subs.Subtitles

	// Processing options
	IsBulkProcess bool
	DubsOnly      bool
	IsCCorDubs    bool

	// Common options
	FieldSep            string // defaults to "\t"
	OutputFileExtension string // defaults to ".tsv" for "\t" and ".csv" otherwise
	Offset              time.Duration

	// Subs2cards options
	WantCondensedAudio bool

	// Audio track options
	TargetChan    int // TODO rename TargetChanNum
	UseAudiotrack int

	// Voice enhancement options
	SeparationLib string
	TimeoutSep    int
	VoiceBoost    float64
	OriginalBoost float64
	Limiter       float64
	MergingFormat string

	// STT options
	STT        string
	TimeoutSTT int
	WantDubs   bool

	// Romanization options
	WantTranslit      bool
	RomanizationStyle string
	KanjiThreshold    int
	BrowserAccessURL  string
	DockerRecreate    bool
}

func NewTask

func NewTask(handler MessageHandler) (tsk *Task)

func (*Task) ApplyFlags

func (tsk *Task) ApplyFlags(cmd *cobra.Command) *ProcessingError

func (*Task) Autosub

func (tsk *Task) Autosub() *ProcessingError

idea: rework to create register: whichSub, whichLang map[string]string and scan subtitles passively without declaring tsk.Native or tsk.NativeSubFile

func (*Task) ChooseAudio

func (tsk *Task) ChooseAudio(helper func(tsk *Task, i int, track AudioTrack) error) (err error)

func (*Task) ConcatWAVstoOGG

func (tsk *Task) ConcatWAVstoOGG(suffix string)

func (*Task) Execute

func (tsk *Task) Execute(ctx context.Context) *ProcessingError

func (*Task) PrepareLangs

func (tsk *Task) PrepareLangs() *ProcessingError

func (*Task) ProcessItem

func (tsk *Task) ProcessItem(ctx context.Context, foreignItem *astisub.Item) (item ProcessedItem, procErr *ProcessingError)

func (*Task) Routing

func (tsk *Task) Routing(ctx context.Context) (procErr *ProcessingError)

func (*Task) Supervisor

func (tsk *Task) Supervisor(ctx context.Context, outStream *os.File, write ProcessedItemWriter) *ProcessingError

Supervisor manages multiple workers processing subtitle items concurrently. It handles cancellation, error reporting, duplicate checking for resuming a previous aborted run, and on‑the‑fly writing.

func (*Task) Translit

func (tsk *Task) Translit(subsFilepath string) *ProcessingError

type VideoTrack

type VideoTrack struct {
	Type               string `json:"@type"`
	StreamOrder        string `json:"StreamOrder"`
	ID                 string `json:"ID"`
	Format             string `json:"Format"`
	FormatProfile      string `json:"Format_Profile"`
	FormatLevel        string `json:"Format_Level"`
	CodecID            string `json:"CodecID"`
	Duration           string `json:"Duration"`
	BitRate            string `json:"BitRate"`
	Width              string `json:"Width"`
	Height             string `json:"Height"`
	SampledWidth       string `json:"Sampled_Width"`
	SampledHeight      string `json:"Sampled_Height"`
	PixelAspectRatio   string `json:"PixelAspectRatio"`
	DisplayAspectRatio string `json:"DisplayAspectRatio"`
	Rotation           string `json:"Rotation"`
	FrameRateMode      string `json:"FrameRate_Mode"`
	FrameRate          string `json:"FrameRate"`
	FrameRateMinimum   string `json:"FrameRate_Minimum"`
	FrameRateMaximum   string `json:"FrameRate_Maximum"`
	FrameCount         string `json:"FrameCount"`
	ColorSpace         string `json:"ColorSpace"`
	ChromaSubsampling  string `json:"ChromaSubsampling"`
	BitDepth           string `json:"BitDepth"`
	StreamSize         string `json:"StreamSize"`
	Title              string `json:"Title"`
	ColourRange        string `json:"colour_range"`
	ColourRangeSource  string `json:"colour_range_Source"`
	Extra              struct {
		CodecConfigurationBox string `json:"CodecConfigurationBox"`
	} `json:"extra"`
}

VideoTrack represents the information about the video stream in the media file

type WorkerConfig

type WorkerConfig struct {
	// contains filtered or unexported fields
}

Jump to

Keyboard shortcuts

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