Home Manual Reference Source Test

Get category for each file

const TorrentLibrary = require("torrent-files-library");

let paths = [
    "D:\\DDL\\FILMS", // a path where I can find both movies and tv-series
    "D:\\DDL\\SERIES TV\\Le juge et le pilote" // a path where I can find episodes of a tv-serie
];

// create an instance
let libInstance = new TorrentLibrary();

// add these paths inside this lib
libInstance
    .addNewPath(...paths)
    .then( (message) => {
        console.log(message);
        return libInstance.scan();
    })
    .then( (otherMessage) => {
        console.log(otherMessage);

        setTimeout(function(){
            // display the found files and their category
            libInstance
                .allFilesWithCategory
                .forEach(function(value,key){
                    console.log(key + " : " + value);
                });
        }, 1000);
    })
    .catch( (err) => {
        console.log(err.message);
    });

fileMappingDemo

List found movies

const TorrentLibrary = require("torrent-files-library");

let paths = [
    "D:\\DDL\\FILMS", // a path where I can find both movies and tv-series
    "D:\\DDL\\SERIES TV\\Le juge et le pilote" // a path where I can find episodes of a tv-serie
];

// create an instance
let libInstance = new TorrentLibrary();

// add these paths inside this lib
libInstance
    .addNewPath(...paths)
    .then( (message) => {
        console.log(message);
        return libInstance.scan();
    })
    .then( (otherMessage) => {
        console.log(otherMessage);
        console.log("I found these movie(s) : ");
        setTimeout(function(){
            // display the found movie(s)
            for (let movie of libInstance.allMovies) {
                console.log(movie.title + ((movie.year) ? " - " + movie.year : "") + " at " + movie.filePath );
            }
        }, 1000);
    })
    .catch( (err) => {
        console.log(err.message);
    });

foundMovies

List each found tv serie

const TorrentLibrary = require("torrent-files-library");

let paths = [
    "D:/DDL/FILMS", // a path where I can find both movies and tv-series
    "D:\\DDL\\SERIES TV\\Le juge et le pilote" // a path where I can find episodes of a tv-serie
];

// create an instance
let libInstance = new TorrentLibrary();

// add these paths inside this lib
libInstance
    .addNewPath(...paths)
    .then( (message) => {
        console.log(message);
        return libInstance.scan();
    })
    .then( (otherMessage) => {
        console.log(otherMessage);
        console.log("I found these tv-series :");
        let mapSeries = libInstance.allTvSeries;

        for (let [foundTvShow,episodeSet] of mapSeries.entries() ) {
            console.log("\n"+foundTvShow);
            console.log("\t Total found episodes : ", episodeSet.size);
            let foundSeasons = new Set([...episodeSet].map( episode => episode.season));
            console.log("\t Found season(s) count : ", foundSeasons.size);
            for (let seasonNumber of foundSeasons){
                console.log("\t\t Season %d", seasonNumber);
                let seasonEpisodes = [...episodeSet].filter(episode => episode.season === seasonNumber);
                console.log("\t\t\t Season count : " + seasonEpisodes.length);
                console.log("\t\t\t Files : ");
                seasonEpisodes.forEach( episode => console.log("\t\t\t " + episode.filePath));
            }
        }

    })
    .catch( (err) => {
        console.log(err.message);
    });

foundTvSeries

Filter movies by parameters

const TorrentLibrary = require("torrent-files-library");

let paths = [
    "D:/",
];

// create an instance
let libInstance = new TorrentLibrary();

// add these paths inside this lib
libInstance
    .addNewPath(...paths)
    .then( () => {
        return libInstance.scan();
    })
    .then( () => {
        console.log('Now time to search all remastered movies with year >= 2012 in one of following container avi/mp4');
        let filteredSet = libInstance.filterMovies({
          year: '>=2012',
          remastered: true,
          container: ['avi', 'mp4'],
        });
        for (let movie of filteredSet) {
          console.log(`${movie.title + ((movie.year) ? ` - ${movie.year}` : '')} at ${movie.filePath}`);
        }
    })
    .catch( (err) => {
            console.log(err.message);
    });

filterMovies

Filter tv series by parameters

const TorrentLibrary = require("torrent-files-library");

let paths = [
    'D:/DDL/SERIES TV/Le juge et le pilote',
    'D:/DDL/ANIME',
];

// create an instance
let libInstance = new TorrentLibrary();

// add these paths inside this lib
libInstance
    .addNewPath(...paths)
    .then(() => libInstance.scan())
    .then(() => {
        console.log('Now time to search all episodes <=5 in season 1 of Hardcastle And McCormick / Assassination Classroom , in one of following container avi/mp4');
        let filteredMap = libInstance.filterTvSeries({
            title: ['Hardcastle And McCormick', 'Assassination Classroom'],
            season: 1,
            episode: '<=5',
            container: ['avi', 'mp4'],
        });
        for (let [foundTvShow, episodeSet] of filteredMap.entries()) {
            console.log(`\n${foundTvShow}`);
            console.log('\t Total found episodes : ', episodeSet.size);
            let foundSeasons = new Set([...episodeSet].map(episode => episode.season));
            console.log('\t Found season(s) count : ', foundSeasons.size);
            for (let seasonNumber of foundSeasons) {
                console.log('\t\t Season %d', seasonNumber);
                let seasonEpisodes = [...episodeSet].filter(episode => episode.season === seasonNumber);
                console.log(`\t\t\t Season count : ${seasonEpisodes.length}`);
                console.log('\t\t\t Files : ');
                seasonEpisodes.forEach(episode => console.log(`\t\t\t ${episode.filePath}`));
            }
        }
    })
    .catch((err) => {
        console.log(err.message);
    });

filterTvSeries

Create custom playlist(s)

const TorrentLibrary = require("torrent-files-library");
const m3u = require('m3u'); // a basic playlist writer (in m3u format)

let paths = [
    'D:/DDL/SERIES TV/Le juge et le pilote',
    'D:/DDL/ANIME',
];

// create an instance
let libInstance = new TorrentLibrary();

// add these paths inside this lib
libInstance
    .addNewPath(...paths)
    .then(() => libInstance.scan())
    .then(() => {
        console.log('Now time to search all episodes <=5 in season 1 of Hardcastle And McCormick / Assassination Classroom , in one of following container avi/mp4');
        let filteredMap = libInstance.filterTvSeries({
            title: ['Hardcastle And McCormick', 'Assassination Classroom'],
            season: 1,
            episode: '<=5',
            container: ['avi', 'mp4'],
        });
        var writer = m3u.writer();
        for (let [foundTvShow, episodeSet] of filteredMap.entries()) {
            let foundSeasons = new Set([...episodeSet].map(episode => episode.season));
            for (let seasonNumber of foundSeasons) {
                writer.comment(`${foundTvShow} - Season ${seasonNumber}`);
                let seasonEpisodes = [...episodeSet].filter(episode => episode.season === seasonNumber);
                seasonEpisodes.forEach(episode => writer.file(`${episode.filePath}`));
            }
        }
        let m3uAsString = writer.toString();
        // save this result into a *.m3u file , using fs.writeFile or whatever you want to do that
        // ...
    })
    .catch((err) => {
        console.log(err.message);
    });
# Assassination Classroom - Season 1
D:\DDL\ANIME\Assassination.Classroom.S01.FRENCH.720p.WEB-DL.x264-GODSPACE\Assassination.Classroom.S01E01.FRENCH.720p.WEB-DL.x264-GODSPACE.mp4
D:\DDL\ANIME\Assassination.Classroom.S01.FRENCH.720p.WEB-DL.x264-GODSPACE\Assassination.Classroom.S01E02.FRENCH.720p.WEB-DL.x264-GODSPACE.mp4
D:\DDL\ANIME\Assassination.Classroom.S01.FRENCH.720p.WEB-DL.x264-GODSPACE\Assassination.Classroom.S01E03.FRENCH.720p.WEB-DL.x264-GODSPACE.mp4
D:\DDL\ANIME\Assassination.Classroom.S01.FRENCH.720p.WEB-DL.x264-GODSPACE\Assassination.Classroom.S01E04.FRENCH.720p.WEB-DL.x264-GODSPACE.mp4
D:\DDL\ANIME\Assassination.Classroom.S01.FRENCH.720p.WEB-DL.x264-GODSPACE\Assassination.Classroom.S01E05.FRENCH.720p.WEB-DL.x264-GODSPACE.mp4
# Hardcastle And McCormick - Season 1
D:\DDL\SERIES TV\Le juge et le pilote\Saison 1\Hardcastle.And.McCormick.1x01.Le.Monstre.D_acier.avi
D:\DDL\SERIES TV\Le juge et le pilote\Saison 1\Hardcastle.And.McCormick.1x03.Le.Canard.De.Cristal.avi
D:\DDL\SERIES TV\Le juge et le pilote\Saison 1\Hardcastle.And.McCormick.1x04.Je.Ne.Sais.Pas.Ou.Je.Vais.Mais.J.y.Vais..avi
D:\DDL\SERIES TV\Le juge et le pilote\Saison 1\Hardcastle.And.McCormick.1x05.La.Veuve.Noire..avi

Changelog

1.5.0 (2018-01-29)

Docs

Feat

1.4.0 (2018-01-28)

Chore

Docs

Feat

Perf

1.3.0 (2018-01-27)

Chore

Docs

Feat

Fix

Test

1.2.4 (2018-01-21)

Fix

1.2.3 (2018-01-21)

Chore

Docs

Perf

Style

Test

1.2.2 (2017-12-23)

Chore

CI

Refactor

1.2.1 (2017-09-10)

Fix

1.2.0 (2017-09-08)

Feat

Style

Test

1.1.0 (2017-09-08)

Chore

Docs

Feat

Style

Test

1.0.4 (2017-09-06)

Chore

Docs

Perf

Test

1.0.3 (2017-09-03)

Docs

Feat

Fix

Perf

Refactor

Test

1.0.2 (2017-08-30)

Docs

Fix

Refactor

1.0.1 (2017-08-29)

Fix

1.0.0 (2017-08-29)

CI

Docs

Feat

Fix

Test