torrent-files-library samples

node v8.9.4
version: 1.2.3
endpointsharetweet
Set up for runkit
const cwd = process.cwd(); const join = require("path").join; const fs = require('fs'); // just to force the creation of temp files let folderPaths = [ join(cwd,"/DDL/FILMS"), // a path where I can find both movies and tv-series join(cwd,"/DDL/SERIES TV/Le juge et le pilote") // a path where I can find episodes of a tv-serie ]; let CorleoneSerie = ["Corleone.S01E01.2010.FRENCH.DVDRIP.XVID-ARTEFAC.By.Hadopix..avi", "Corleone.S01E02.FRENCH.DVDRiP.XViD.avi", "Corleone.S01E03.FRENCH.DVDRiP.XViD.avi", "Corleone.S01E04.FRENCH.DVDRiP.XViD.avi", "Corleone.S01E05.2010.FRENCH.DVDRIP.XVID-ARTEFAC.By.Hadopix.avi", "Corleone.S01E06.2010.FRENCH.DVDRIP.XVID-ARTEFAC.By.Hadopix.avi"]; let seasons = [ ["Saison 1",["Hardcastle.And.McCormick.1x01.Le.Monstre.D_acier.avi","Hardcastle.And.McCormick.1x13.Revision.D.un.Proces..avi","Hardcastle.And.McCormick.1x09.Chef.De.Gang..avi"],folderPaths[1]], ["Saison 5",["Hardcastle.And.McCormick.3x16.Des.Promesses_.Toujours.Des.Promesses..avi","Hardcastle.And.McCormick.3x14.L.election..avi"],folderPaths[1]]]; function setUp(){ // fwrite folders // suppose here it is a perfect world ^^ fs.mkdirSync(join(cwd,"DDL")); fs.mkdirSync(join(cwd,"DDL","FILMS")); fs.mkdirSync(join(folderPaths[0],"/toto riina")); fs.mkdirSync(join(cwd,"DDL","SERIES TV")); fs.mkdirSync(join(cwd,"DDL","SERIES TV","Le juge et le pilote")); for(var [seasonNumber,data,folder] of seasons){ fs.mkdirSync(join(cwd,"DDL","SERIES TV","Le juge et le pilote",seasonNumber)); for(var episode of data){ fs.writeFileSync(join(folder,episode), ''); } } for(var episode of CorleoneSerie){ fs.writeFileSync(join(folderPaths[0],episode), ''); } }
Custom viewer
const bootstrapJs = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/js/bootstrap.min.js"; const bootstrapCss = "https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta.2/css/bootstrap.min.css"; const jquery = "https://code.jquery.com/jquery-3.2.1.slim.min.js"; const popper = "https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.3/umd/popper.min.js"; const { ValueViewerSymbol } = require("@runkit/value-viewer"); class SeriesViewer { constructor(data){ const title = "Tv Show Viewer"; var HTML = `<link rel = "stylesheet" href = "${bootstrapCss}">`; HTML += `<script src="${jquery}"></script>`; HTML += `<script src="${popper}"></script>`; HTML += `<script src="${bootstrapJs}"></script>`; HTML += `<div class="col-4"><div class="list-group" id="list-tab" role="tablist">`; for (let [foundTvShow] of data ) { HTML += `<a class="list-group-item list-group-item-action" id="list-${foundTvShow}-list" data-toggle="list" href="#list-${foundTvShow.replace(/\s/g,'')}" role="tab" aria-controls="${foundTvShow}">${foundTvShow}</a>`; } HTML += `</div></div><div class="col-8"><div class="tab-content" id="nav-tabContent">`; for (let [foundTvShow,episodeSet] of data.entries() ) { HTML += `<div class="tab-pane fade" id="list-${foundTvShow.replace(/\s/g,'')}" role="tabpanel" aria-labelledby="list-${foundTvShow.replace(/\s/g,'')}-list">`; let foundSeasons = new Set([...episodeSet].map( episode => episode.season)); HTML += `<ul><li>Total found episodes : ${episodeSet.size}</li>`; HTML += `<li>Found season(s) count : ${foundSeasons.size}</li><li><ul>`; for (let seasonNumber of foundSeasons){ HTML += `<ul> <li>Season ${seasonNumber}</li>`; let seasonEpisodes = [...episodeSet].filter(episode => episode.season === seasonNumber); HTML += `<li> Season count : ${seasonEpisodes.length}</li>`; HTML += `<ul> Files :`; seasonEpisodes.forEach( episode => HTML += `<li> ${episode.filePath} </li>`); HTML += `</ul></ul>`; } HTML += `</ul></li></ul></div>`; } HTML += `</div></div>` Object.assign(this, data, { [ValueViewerSymbol]: { title, HTML } }); } }
List all tv-shows
const TorrentLibrary = require("torrent-files-library"); // set up environement setUp(); // create an instance let libInstance = new TorrentLibrary(); // add these paths inside this lib libInstance.addNewPath(...folderPaths) .then( (message) => { return libInstance.scan(); }) .then( (otherMessage) => { let mapSeries = libInstance.allTvSeries; console.log(new SeriesViewer(mapSeries)); }) .catch( (err) => { console.log(err.message); });
Loading…

no comments

    sign in to comment