Last active
July 15, 2021 11:02
-
-
Save dantheman213/bc36d732726c4efffc2bc882c0dba028 to your computer and use it in GitHub Desktop.
showRSS scheduler rss feed parse and download magent link files for your personal showRSS RSS URL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // showRSS scheduler rss feed parse and download magent link files for your personal showRSS RSS URL | |
| // HOW TO USE // | |
| // 1. Setup showRss Feed and get a personal URL | |
| // 2. Setup a torrent downloader (I like Deluge) and have it watch a folder to auto-add torrent_files | |
| // 3. Cron to setup | |
| // * 23 * * * nodejs /usr/bin/showrss_downloader.js >> /var/log/showrss_downloader.log 2>&1 | |
| var uuid = require('node-uuid'); | |
| var request = require('request'); | |
| var parser = require('xml2json'); | |
| var moment = require('moment'); | |
| var fs = require('fs'); | |
| // USER DEFINED VARIABLES // | |
| var showRssUrl = 'https://showrss.info/user/XXXXXX.rss?magnets=true&namespaces=true&name=clean&quality=null&re=null'; | |
| var watchDirectory = '/downloads/torrent_files'; | |
| function main() { | |
| console.log('Starting operation at ' + moment().format()); | |
| request(showRssUrl, function (error, response, body) { | |
| if (!error && response.statusCode == 200) { | |
| parseXmlPayload(body); | |
| } else { | |
| console.log('an error occurred!'); | |
| console.log(error); | |
| } | |
| }); | |
| } | |
| function parseXmlPayload(rawXml) { | |
| var json = null; | |
| try { | |
| json = JSON.parse(parser.toJson(rawXml)); | |
| } catch (ex) { | |
| console.log('Failed to parse showRSS XML'); | |
| process.exit(0); | |
| } | |
| var downloadList = []; | |
| var todayDateStr = moment().format('DD MMM YYYY'); | |
| try { | |
| if(json.rss.channel.item.length > 0) { | |
| for(var k = 0; k < json.rss.channel.item.length; k++) { | |
| var item = json.rss.channel.item[k]; | |
| if(item.pubDate.indexOf(todayDateStr) > -1) { | |
| console.log('Downloading magent for ' + item.title + '...'); | |
| downloadList.push(item.link); | |
| } else { | |
| console.log('Skipping magent for ' + item.title + '...'); | |
| } | |
| } | |
| if(downloadList.length > 0) { | |
| downloadMagentLinks(downloadList); | |
| } | |
| } else { | |
| console.log('No items to download today.'); | |
| } | |
| } catch (ex) { | |
| console.log('An error occurred while trying to gather the magent links to download'); | |
| console.log(ex); | |
| process.exit(0); | |
| } | |
| } | |
| function downloadMagentLinks(list) { | |
| for(var i = 0; i < list.length; i++) { | |
| fs.writeFileSync(watchDirectory + '/' + uuid.v4().replace(/-/g, '') + '.magnet', list[i], 'utf8'); | |
| } | |
| console.log('complete!'); | |
| } | |
| main(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment