Last active
December 17, 2015 07:49
-
-
Save dmitriiivashko/5575895 to your computer and use it in GitHub Desktop.
TranceTraffic Seedbox
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
| rss_path = "http://www.trancetraffic.com/tt_rss_dl.php?w_cats=1&passkey=XXXXXXXXXXXXXXXXXXXXX" | |
| filter_categories=[ | |
| "Albums - Trance", | |
| "Singles - Trance", | |
| "Albums - Techno", | |
| "Singles - Techno", | |
| "Albums - House", | |
| "Singles - House", | |
| "Livesets - Trance" | |
| ] | |
| from urllib import request | |
| from xml.dom import minidom | |
| from datetime import datetime | |
| import time | |
| import re | |
| import os | |
| import shutil | |
| print(">> Downloading RSS:",rss_path) | |
| rss_content = request.urlopen(rss_path) | |
| print(">> Parsing RSS XML") | |
| dom = minidom.parse(rss_content) | |
| tracks = [] | |
| for node in dom.getElementsByTagName('item'): | |
| title=node.getElementsByTagName('title')[0].childNodes[0].nodeValue | |
| torrent=node.getElementsByTagName('link')[0].childNodes[0].nodeValue | |
| category = re.search('.+\((.*?)\)$',title).group(1) | |
| date=node.getElementsByTagName('pubDate')[0].childNodes[0].nodeValue | |
| date_match = re.search('^.+? ([0-9]+) ([a-zA-Z]+) ([0-9]+) ([0-9:]+).+$',date) | |
| date = date_match.group(1) + " " + date_match.group(2) + " " + date_match.group(3) + " " + date_match.group(4) | |
| time_stamp = datetime.strptime(date,"%d %b %Y %H:%M:%S") | |
| tracks.append({ | |
| 'title': title.strip(), | |
| 'category': category, | |
| 'torrent': torrent, | |
| 'timestamp': time_stamp | |
| }) | |
| print(">> XML Data parsed") | |
| print(">> Downloading new torrent files") | |
| now = datetime.now() | |
| for track in tracks: | |
| # Skip torrents older than 2 days | |
| difference_in_days = (now - track['timestamp']).days | |
| if difference_in_days > 2: | |
| continue | |
| # Skip existing torrents | |
| filename = re.sub('[^0-9a-zA-Z\-_\(\)]', '_', track['title'])+".torrent" | |
| path_downloaded = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","torrents",filename) | |
| path_finished = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","torrents_finished",filename) | |
| path_tmp = os.path.join(os.path.dirname(os.path.realpath(__file__)),"..","tmp",filename) | |
| if os.path.exists(path_finished) or os.path.exists(path_downloaded): | |
| continue | |
| # Skip unwanted releases | |
| if track['category'] not in filter_categories: | |
| continue | |
| print(">>>>>> Downloading torrent file:",track['torrent']) | |
| torrent_content = request.urlopen(track['torrent']) | |
| raw_data = torrent_content.read() | |
| if raw_data: | |
| f = open(path_tmp, 'wb') | |
| f.write(raw_data) | |
| f.close() | |
| shutil.move(path_tmp, path_downloaded) | |
| time.sleep(1) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment