Home Manual Reference Source Test
import TorrentLibrary from 'torrent-files-library/src/TorrentLibrary.js'
public class | source

TorrentLibrary

Extends:

EventEmitter → TorrentLibrary

Class representing the TorrentLibrary

Static Member Summary

Static Public Members
public static get

constant for movie category

since 0.0.0
public static get

constant for tv series category

since 0.0.0

Static Method Summary

Static Public Methods
public static

Creates an instance of TorrentLibrary

since 1.2.0
public static

Provides the array of files extensions considered to be media extensions

since 0.0.0

Constructor Summary

Public Constructor
public

Create a TorrentLibrary

since 1.0.4

Member Summary

Public Members
public get

Getter for the mapping between filepaths and category

since 0.0.0
public get

Getter for all found movies

since 0.0.0
public get

Getter for all found tv-series

since 0.0.0
public

Mapping filepath => category

since 0.0.0
public

just an easy way to scan the current directory path, if not other paths provided

since 0.0.0
public

The parsing function to be used with this lib

since 1.4.0
public

the paths where we are looking the media files

since 0.0.0
public

The variable where we store all kind of media files found in paths

since 0.0.0

Method Summary

Public Methods
public

addNewPath(paths: ...string): Promise

Add the path(s) to be analyzed by the library if they exist and are readable

since 0.0.0
public

filterMovies(searchParameters: searchParameters): Set<TPN>

Filter the movies based on search parameters

since 1.3.0
public

filterTvSeries(searchParameters: searchParameters): Map<string, Set<TPN>>

Filter the tv-series based on search parameters

since 1.5.0
public

Tell us if the user has provided us paths

since 0.0.0
public

Removes files stored in this library

since 1.0.3
public

Scans the paths in search for new files to be added inside this lib

since 0.0.0
public

Returns an JSON stringified of the current state

since 1.0.3

Static Public Members

public static get MOVIES_TYPE: string since 0.0.0 source

constant for movie category

Test:

public static get TV_SERIES_TYPE: string since 0.0.0 source

constant for tv series category

Test:

Static Public Methods

public static createFromJSON(json: Object, parser: customParsingFunction): TorrentLibrary since 1.2.0 source

Creates an instance of TorrentLibrary

Params:

NameTypeAttributeDescription
json Object
  • optional

the JSON object of toJSON() string

json.paths String[]

the paths where we are looking the media files

json.allFilesWithCategory Array<Array<String, String>>

Mapping filepath => category

json.movies TPN_Extended[]

the movies files

json.tv-series Array<Array<String, TPN_Extended[]>>

the serie files

parser customParsingFunction
  • optional
  • default: nameParser

The custom parser you want to use

Return:

TorrentLibrary

an TorrentLibrary instance

Example:

// creates an new instance from another one
  const createdInstance = TorrentLibrary.createFromJSON(
     JSON.parse(libInstance.toJSON()),
  );
// As explained there : https://github.com/clement-escolano/parse-torrent-title#regular-expressions
// If you want an extra field to be populated
const ptt = require("parse-torrent-title");
ptt.addHandler("part", /Part[. ]([0-9])/i, { type: "integer" });
// creates an new instance from another one; with custom parser
  const createdInstance = TorrentLibrary.createFromJSON(
     JSON.parse(libInstance.toJSON()),
     ptt.parse
  );

Test:

See:

  • https://github.com/jy95/torrent-files-library/tree/master/tests/fixtures/example.json for an param example

public static listVideosExtension(): string[] since 0.0.0 source

Provides the array of files extensions considered to be media extensions

Return:

string[]

array of files extensions

Example:

// Returns [..., 'webm', 'wmv']
TorrentLibrary.listVideosExtension()

Test:

Public Constructors

public constructor(config: Object, parser: customParsingFunction) since 1.0.4 source

Create a TorrentLibrary

Params:

NameTypeAttributeDescription
config Object
  • optional

the config object

config.defaultPath String
  • optional
  • default: process.cwd()

the default path

config.paths String[]
  • optional
  • default: []

the paths where we are looking the media files

config.allFilesWithCategory Map<string, string>
  • optional
  • default: new Map()

Mapping filepath => category

config.movies Set<TPN_Extended>
  • optional
  • default: new Set()

the movies files

config.series Map<string, Set<TPN_Extended>>
  • optional
  • default: new Map()

the serie files

parser customParsingFunction
  • optional
  • default: nameParser

The parsing function to be used with this lib ; default is function parse from parse-torrent-title package

Public Members

public get allFilesWithCategory: Map<string, string> since 0.0.0 source

Getter for the mapping between filepaths and category

Example:

{ "D:\somePath\Captain Russia The Summer Soldier (2014) 1080p BrRip x264.MKV" => TorrentLibrary.MOVIES_TYPE }

Test:

public get allMovies: Set<TPN_Extended> since 0.0.0 source

Getter for all found movies

Example:

// an JSON stringified example of this method
[
 {
  "year":2012,
  "source":"dvdrip",
  "codec":"xvid",
  "group":"-www.zone-telechargement.ws.avi",
  "container":"avi",
  "language":"truefrench",
  "title":"Bad Ass",
  "filePath":"D:\\workspaceNodeJs\\torrent-files-library\\test\\folder1\\Bad.Ass.2012.LiMiTED.TRUEFRENCH.DVDRiP.XviD-www.zone-telechargement.ws.avi"
 }
]

Test:

public get allTvSeries: Map<string, Set<TPN_Extended>> since 0.0.0 source

Getter for all found tv-series

Example:

// an JSON stringified example of this method
{
"The Blacklist":[
   {
     "season":4,
     "episode":21,
     "source":"webrip",
     "codec":"xvid",
     "container":"avi",
     "language":"french",
     "title":"The Blacklist",
     "filePath":"D:\\workspaceNodeJs\\torrent-files-library\\test\\folder1\\The.Blacklist.S04E21.FRENCH.WEBRip.XviD.avi"
  },
  {
     "season":4,
     "episode":14,
     "source":"webrip",
     "codec":"xvid",
     "container":"avi",
     "language":"french",
     "title":"The Blacklist",
     "filePath":"D:\\workspaceNodeJs\\torrent-files-library\\test\\folder2\\The.Blacklist.S04E14.FRENCH.WEBRip.XviD.avi"
  }
]
}

Test:

public categoryForFile: Map<string, string> since 0.0.0 source

Mapping filepath => category

Example:

{ "D:\somePath\Captain Russia The Summer Soldier (2014) 1080p BrRip x264.MKV" => TorrentLibrary.MOVIES_TYPE }

public defaultPath: string since 0.0.0 source

just an easy way to scan the current directory path, if not other paths provided

public parser: customParsingFunction since 1.4.0 source

The parsing function to be used with this lib

public paths: String[] since 0.0.0 source

the paths where we are looking the media files

Example:

// after have added some paths ...
[ "D:\somePath", "D:\anotherPath" ]

public stores: StoreVar since 0.0.0 source

The variable where we store all kind of media files found in paths

Public Methods

public addNewPath(paths: ...string): Promise since 0.0.0 source

Add the path(s) to be analyzed by the library if they exist and are readable

Params:

NameTypeAttributeDescription
paths ...string

A or more path(s)

Return:

Promise

On success the promise will be resolved with "All paths were added!"
On error the promise will be rejected with an Error object "Missing parameter" if the argument is missing
or an Error object from fs

Emit:

*

Events#missing_parameter

*

Events#error_in_function

*

Events#addNewPath

Example:

// return resolved Promise "All paths were added!"
TorrentLibraryInstance.addNewPath("C:\Users\jy95\Desktop\New folder","C:\Users\jy95\Desktop\New folder2");

Test:

public filterMovies(searchParameters: searchParameters): Set<TPN> since 1.3.0 source

Filter the movies based on search parameters

Params:

NameTypeAttributeDescription
searchParameters searchParameters

search parameters.

Return:

Set<TPN>

the filtered movie set

Test:

public filterTvSeries(searchParameters: searchParameters): Map<string, Set<TPN>> since 1.5.0 source

Filter the tv-series based on search parameters

Params:

NameTypeAttributeDescription
searchParameters searchParameters

search parameters.

Return:

Map<string, Set<TPN>>

the filtered movie set

Test:

public hasPathsProvidedByUser(): boolean since 0.0.0 source

Tell us if the user has provided us paths

Return:

boolean

Has user provided us paths ?

Example:

TorrentLibraryInstance.addNewPath("C:\Users\jy95\Desktop\New folder","C:\Users\jy95\Desktop\New folder2");
TorrentLibraryInstance.hasPathsProvidedByUser() // TRUE

public removeOldFiles(files: ...string): Promise since 1.0.3 source

Removes files stored in this library

Params:

NameTypeAttributeDescription
files ...string

An array of filePath (for example the keys of allFilesWithCategory)

Return:

Promise

an resolved or rejected promise
On success, the resolve will contain an message and the removed filePaths
On error the promise will be rejected with an Error object from sub modules

Emit:

*

Events#removeOldFiles

*

Events#error_in_function

Example:

// with multiples files
TorrentLibraryInstance.removeOldFiles(
   "D:\somePath\Captain Russia The Summer Soldier (2014) 1080p BrRip x264.MKV",
   "D:\\workspaceNodeJs\\torrent-files-library\\test\\folder1\\The.Blacklist.S04E21.FRENCH.WEBRip.XviD.avi"
)

Test:

public scan(): Promise since 0.0.0 source

Scans the paths in search for new files to be added inside this lib

Return:

Promise

On success the promise will be resolved with "Scanning completed"
On error the promise will be rejected with an Error object from sub modules

Emit:

*

Events#scan

*

Events#error_in_function

Test:

public toJSON(): string since 1.0.3 source

Returns an JSON stringified of the current state

Return:

string

json - the JSON stringified

Test:

See:

  • https://github.com/jy95/torrent-files-library/blob/master/test/fixtures/example.json