DLPATH = '/Path/To/TorrentWatchFolder/' FEED = 'http://rss.torrentleech.org/rss.php?passkey=%s' RSSKEY = '' # grab your passkey from torrentleech.org/getrss.php # tuple of shows you want to grab - duplicate seasons/eps will # not be grabbed. Spaces converted to /.*?/ SHOWS = ( 'Stargate Atlantis', ) """ Copyright (c) 2008, Will Boyce All rights reserved. Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met: Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution. Neither the name of the ShowGrabber nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. """ import os import re import sqlite3 import threading import urllib class ShowGrabber(threading.Thread): def __init__(self, show, path, feed, db): threading.Thread.__init__(self) self.show = show self.path = path self.feed = feed self.db = db def initdb(self, con): cur = con.cursor() cur.executescript(""" CREATE TABLE IF NOT EXISTS grabbed_shows ( show TEXT NOT NULL, season INTEGER NULL, episode INTEGER NULL ); """) con.commit() cur.close() def run(self): con = sqlite3.connect(self.db) self.initdb(con) cur = con.cursor() entries = self.feed['entries']; entries.reverse() for entry in entries: if re.match(self.show.replace(' ', '.*?'), entry['title']): try: g = re.match('.*(?:S(\d{1,2})E(\d{1,2})|(\d{1,2})x(\d{1,2})).*', entry['title']).groups() season, episode = (g[0] or g[2]), (g[1] or g[3]) season = season.lstrip('0'); episode = episode.lstrip('0') cur.execute('SELECT COUNT(show) AS rc FROM grabbed_shows WHERE show=? AND season=? AND episode=?', (show, int(season), int(episode))) for res in cur: if res[0] == 0: print 'Grabbing %s...' % entry['title'] urllib.urlretrieve(entry['link'], os.path.join(self.path, entry['link'][entry['link'].rfind('/')+1:])) cur.execute('INSERT INTO grabbed_shows (show, season, episode) VALUES (?, ?, ?)', (show, int(season), int(episode))) con.commit() except: pass cur.close() if __name__ == "__main__": import feedparser feed = feedparser.parse(FEED % RSSKEY) db = os.path.join(os.environ['HOME'], '.torrentWatch.sql') for show in SHOWS: sg = ShowGrabber(show, DLPATH, feed, db).start()