seedlinux

find open source torrents and stats for people wishing to contribute bandwidth.
git clone git://git.beardyjay.co.uk/seedlinux
Log | Files | Refs | README | LICENSE

commit 10dcedf2fb4e07f47cd09aefa0560d0f457a9cb3
parent a71b3c7c5a01833cecbd4ac5cbc797652e94ee2b
Author: Jay Scott <jay@beardyjay.co.uk>
Date:   Tue,  4 Jul 2017 15:10:45 +0100

adding script to parse torrent folder and update db

Diffstat:
Abin/parse | 81+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackage.json | 1-
Mviews/layout.pug | 1-
3 files changed, 81 insertions(+), 2 deletions(-)

diff --git a/bin/parse b/bin/parse @@ -0,0 +1,80 @@ +#!/usr/bin/env node +'use strict'; + +console.log('Parsing torrent folder'); + +const async = require('async'); +const mongoose = require('mongoose'); +const mongoDB = process.env.DB_URI; +const parseTorrent = require('parse-torrent'); +const Torrent = require('../models/torrent_model'); +const fs = require('fs'); + +const torrentFolder = './data/torrents'; + +mongoose.connect(mongoDB); +var db = mongoose.connection; +db.on('error', console.error.bind(console, 'MongoDB connection error:')); + +function saveTorrent(query, data, callback) { + Torrent.findOneAndUpdate(query, data, {upsert: true},function(err) { + if (err) { + callback(err, null); + } else { + callback(null); + } + }); +} + +fs.readdir(torrentFolder, function (err, files) { + if (err) console.log(err); + + async.eachSeries(files, function(file, callback) { + async.waterfall([ + function(callback){ + + console.log("Parsing - " + file); + + let tFile = fs.readFileSync(torrentFolder + '/' + file); + let tData = parseTorrent(tFile); + + let tMagnet = parseTorrent.toMagnetURI({ + infoHash: tData.infoHash + }); + + let newData = { + name: tData.name, + hash: tData.infoHash, + created: tData.created, + comment: tData.comment, + announce: tData.announce, + files: tData.files, + magneturi: tMagnet, + }; + + callback(null, newData); + }, + function(arg1, callback){ + saveTorrent({hash: arg1.hash }, arg1, function(err, data) { + if (err) callback(true); + + callback(null, data); + }); + }], function (err) { + + if (err) + throw err; + + callback(); + } + ); + }, function(err) { + if( err ) { + console.log('A torrent failed to process'); + process.exit(1); + } else { + console.log('All torrents have been processed successfully'); + process.exit(); + } + }); +});+ \ No newline at end of file diff --git a/package.json b/package.json @@ -9,7 +9,6 @@ "start": "DEBUG=seedlinux:* node ./bin/www" }, "dependencies": { - "app-root-path": "^2.0.1", "async": "^2.5.0", "body-parser": "~1.17.1", "cookie-parser": "~1.4.3", diff --git a/views/layout.pug b/views/layout.pug @@ -12,7 +12,6 @@ html img.ui.centered.medium.image(src='/images/logo.png') .sub.ui.centered.header= "Start Contributing to Open Source!" - .ui.hidden.divider .ui.container