Documentation
¶
Overview ¶
Package scraper provides video file scraping functionality
Index ¶
- Constants
- Variables
- func ScrapeFFProbe(filename string, vid *models.Video, logger *logrus.Entry) error
- func ScrapeSHA512(filename string, vid *models.Video, logger *logrus.Entry) error
- type FFFormatInfo
- type FFProbeData
- type FFStreamInfo
- type FieldIndexMap
- type NameScrapingPreset
- type Scrape
- type ScrapeStatus
- type Scraper
- type ScrapingFunc
Constants ¶
const ( // FldTitle marks a match for the "Title"" field of a video FldTitle = "Title" // FldArtist marks a match for the "Artist"" field of a video FldArtist = "Artist" // FldRelatedMedium marks a match for the "RelatedMedium"" field of a video FldRelatedMedium = "RelatedMedium" // FldMediumDetail marks a match for the "MediumDetail"" field of a video FldMediumDetail = "MediumDetail" // FldDescription marks a match for the "Description"" field of a video FldDescription = "Description" // FldLanguage marks a match for the "Language"" field of a video FldLanguage = "Language" // FldIdentifier marks a match for the "Identifier" field of a video FldIdentifier = "Identifier" // StatusQueued is the status a scrape has when it waits to be started StatusQueued = iota // StatusRunning is the status of a scrape that is currently active StatusRunning // StatusFinished is the status of a scrape that has been finished successfully StatusFinished // StatusFailed is the status of a scrape that has failed for some reason. To look up the reason, see the Err field // of the scrape struct StatusFailed // StatusCancelled is the status of a scrape that has been cancelled by the user StatusCancelled )
Variables ¶
var ( // ErrAlreadyQueued is the error that is returned when scraping the same or a parent directory is already inside // the scraping queue ErrAlreadyQueued = fmt.Errorf("A scraping operation is already queued for this directory") )
Functions ¶
func ScrapeFFProbe ¶
ScrapeFFProbe uses the ffprobe commandline tool to scrape the video metadata from its JSON output
Types ¶
type FFFormatInfo ¶
type FFFormatInfo struct {
Filename string `json:"filename"`
NumStreams uint `json:"nb_streams"`
NumPrograms uint `json:"nb_programs"`
FormatName string `json:"format_name"`
FormatLongName string `json:"format_long_name"`
StartTime string `json:"start_time"`
Duration string `json:"duration"`
Size string `json:"size"`
Bitrate string `json:"bit_rate"`
ProbeScore uint `json:"probe_score"`
Tags map[string]string `json:"tags"`
}
FFFormatInfo contains information about the media format.
type FFProbeData ¶
type FFProbeData struct {
Format *FFFormatInfo `json:"format"`
Streams []*FFStreamInfo `json:"streams"`
}
FFProbeData is the data format the tool ffprobe generates in JSON
func (*FFProbeData) GetFirstSteamByType ¶
func (d *FFProbeData) GetFirstSteamByType(t string) *FFStreamInfo
GetFirstSteamByType returns the first stream in the media file's streams that has the given type
type FFStreamInfo ¶
type FFStreamInfo struct {
CodecType string `json:"codec_type"`
CodecName string `json:"codec_name"`
CodecLongName string `json:"codec_long_name"`
Width int `json:"width"`
Height int `json:"height"`
Bitrate string `json:"bit_rate"`
}
FFStreamInfo contains information about a stream inside a media file This struct does not contain all of the fields returned by ffprobe
type FieldIndexMap ¶
FieldIndexMap describes the correlation between a field of a video struct and the index in the scraping result that will be used to fill this field. It is used in the "FileNameSchema" scraper for configuring which field will be filled with the result of which capture group of the regular expression
type NameScrapingPreset ¶
type NameScrapingPreset struct {
Name string
Regex string
FieldMap FieldIndexMap
}
NameScrapingPreset defines a named preset for scraping file names It is used to make it easier for repeating scrapes of a special kind
type Scrape ¶
type Scrape struct {
// The current status of the scrape. See the Status* constants for possible values
Status ScrapeStatus `json:"status"`
// The root directory where the scraping started - since multiple scrapes in the same directory are not allowed,
// this can also be seen as a unique ID
RootDir string `json:"rootDir"`
// The directory currently being traversed
CurrentDir string `json:"currentDir"`
// The file currently being scanned
CurrentFile string `json:"currentFile"`
// The number of video files already scraped
NumFiles uint `json:"filesScraped"`
// The number of new video files scraped
NumNewFiles uint `json:"newFiles"`
// The number of already existing video files updated
NumUpdatedFiles uint `json:"updatedFiles"`
// The time the scape has started
StartedAt time.Time `json:"startedAt"`
// If the scrape has failed, this is the error that caused it
Err error `json:"error"`
// contains filtered or unexported fields
}
Scrape describes a video scraping operation currently running
type ScrapeStatus ¶
type ScrapeStatus uint
ScrapeStatus defines the status of a scrape
func (ScrapeStatus) MarshalJSON ¶
func (s ScrapeStatus) MarshalJSON() ([]byte, error)
MarshalJSON implements the json.marshaler interface returning the name of the status
func (ScrapeStatus) String ¶
func (s ScrapeStatus) String() string
Converts the scrape status into a readable name
type Scraper ¶
type Scraper struct {
// contains filtered or unexported fields
}
A Scraper runs a set of Scraping functions on files fed to it
func NewDefault ¶
NewDefault creates a new scraper that is setup using the default scraping functions
func (*Scraper) Start ¶
Start begins scraping from the given root directory. It returns the ID of the
func (*Scraper) Status ¶
Status retrieves the status of the scrape running for the given root directory
func (*Scraper) StatusAll ¶
StatusAll returns the status object for all scrapes currently available in the scrape list
type ScrapingFunc ¶
A ScrapingFunc is a function that scrapes a file identified by its file name and writes the found meta data into the video struct provided
func MakeFileNameScraper ¶
func MakeFileNameScraper(presetName string) (ScrapingFunc, error)
MakeFileNameScraper returns a scraping function that uses a regular expression to extract data from a file's name using capturing groups. These extracted data fields are then mapped to fields of the video struct, resulting in filling them with the appropriate data
Regex and field mappings are derived by taking them from the presets stored in this
func MustMakeFileNameScraper ¶
func MustMakeFileNameScraper(presetName string) ScrapingFunc
MustMakeFileNameScraper is a version of MakeFileNameScraper that panics when creating the scraping function fails