ptn

package module
v1.0.0 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2022 License: MIT Imports: 9 Imported by: 0

README

go-ptn - Parse Torrent File Name

GoDoc License Go Report Card

Extract media information from movie and tv series filename

A port of middelink/go-parse-torrent-name awesome library.

Extract all possible media information present in filenames. Multiple regex rules are applied on filename string each of which extracts corresponding information from the filename. If a regex rule matches, the corresponding part is removed from the filename. In the end, the remaining part is taken as the title of the content.

Why?

Online APIs by providers like TMDb, TVDb and OMDb don't react to well to search queries which include any kind of extra information. To get proper results from these APIs, only the title of the content should be provided as the search query where this library comes into play. The accuracy of the results can be improved by passing in the year which can also be extracted using this library.

This port assumes the files folllow the current (2022) formats, and puts less focus on older naming styles. This port fixed some bugs with file extentions (containter) and various title issues. It includes a test file which can easily be updated as a json file.

Information extracted

below is the resulting struct that the function returns.

Title      string `json:"title,omitempty"`
Season     int    `json:"season,omitempty"`
Episode    int    `json:"episode,omitempty"`
Year       int    `json:"year,omitempty"`
Resolution string `json:"resolution,omitempty"` //1080p etc
Quality    string `json:"quality,omitempty"`
Codec      string `json:"codec,omitempty"`
Audio      string `json:"audio,omitempty"`
Service    string `json:"service,omitempty"` // NF etc
Group      string `json:"group,omitempty"`
Region     string `json:"region,omitempty"`
Extended   bool   `json:"extended,omitempty"`
Hardcoded  bool   `json:"hardcoded,omitempty"`
Proper     bool   `json:"proper,omitempty"`
Repack     bool   `json:"repack,omitempty"`
Container  string `json:"container,omitempty"`
Widescreen bool   `json:"widescreen,omitempty"`
Website    string `json:"website,omitempty"`
Language   string `json:"language,omitempty"`
Sbs        string `json:"sbs,omitempty"`
Unrated    bool   `json:"unrated,omitempty"`
Size       string `json:"size,omitempty"`
Threed     bool   `json:"3d,omitempty"`
Country    string `json:"country,omitempty"`   // two letters uppercase at the end of the title US or UK only for now
IsMovie    bool   `json:"ismovie"` // true if this is a movie, false if tv show

Usage

package main

import (
	"fmt"
	"github.com/razsteinmetz/go-ptn"
)

func main() {
	filename := "series.title.s01e03.720p.hdtv-GROUP.avi"
	info,_ := ptn.Parse(filename)
	fmt.Println(info)
}

// info has all the data you need

PTN works well for both movies and TV episodes. All meaningful information is extracted and returned together in a dictionary.

Install

Automatic

go-ptn can be installed using go get.

$ go get github.com/razsteinmetz/go-ptn
Manual

First clone the repository.

$ git clone https://github.com/razsteinmetz/go-ptn go-ptn && cd go-ptn

And run the command for installing the package.

$ go install .

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type TorrentInfo

type TorrentInfo struct {
	Title      string `json:"title,omitempty"`
	Season     int    `json:"season,omitempty"`
	Episode    int    `json:"episode,omitempty"`
	Year       int    `json:"year,omitempty"`
	Resolution string `json:"resolution,omitempty"` //1080p etc
	Quality    string `json:"quality,omitempty"`
	Codec      string `json:"codec,omitempty"`
	Audio      string `json:"audio,omitempty"`
	Service    string `json:"service,omitempty"` // NF etc
	Group      string `json:"group,omitempty"`
	Region     string `json:"region,omitempty"`
	Extended   bool   `json:"extended,omitempty"`
	Hardcoded  bool   `json:"hardcoded,omitempty"`
	Limited    bool   `json:"limited,omitempty"`
	Proper     bool   `json:"proper,omitempty"`
	Repack     bool   `json:"repack,omitempty"` // also rerip
	Container  string `json:"container,omitempty"`
	Widescreen bool   `json:"widescreen,omitempty"`
	Website    string `json:"website,omitempty"`
	Language   string `json:"language,omitempty"`
	Sbs        string `json:"sbs,omitempty"`
	Unrated    bool   `json:"unrated,omitempty"`
	Size       string `json:"size,omitempty"`
	Threed     bool   `json:"3d,omitempty"`
	Country    string `json:"country,omitempty"`
	IsMovie    bool   `json:"ismovie"` // true if this is a movie, false if tv show
}

TorrentInfo is the resulting structure returned by Parse important, season/episode are 0,0 for movies (so you can't have S00E00 file!)

func Parse

func Parse(filename string) (*TorrentInfo, error)

Parse breaks up the given filename in TorrentInfo algo - remove the file extention if its one of known, then parse the rest the title is the last part.

func (TorrentInfo) Tojson

func (t TorrentInfo) Tojson() (string, error)

Jump to

Keyboard shortcuts

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