Skip to content

Instantly share code, notes, and snippets.

@ssplatt
Created October 5, 2015 02:21
Show Gist options
  • Save ssplatt/7fa02084231519b065ff to your computer and use it in GitHub Desktop.
Save ssplatt/7fa02084231519b065ff to your computer and use it in GitHub Desktop.
add torrent to transmission from rss feed and sort into subdirectory based on file name
#!/usr/bin/env python
import feedparser, subprocess, urllib2, re, os, libtorrent
out_dir_base = ''
logfile = ''
rss=''
feed = feedparser.parse(rss)
log = open( logfile, 'r+' )
log_cont = log.read()
for item in feed['items']:
if not item['link'] in log_cont:
torr = urllib2.urlopen(item['link']).read()
torr_dec = libtorrent.bdecode(torr)
info = libtorrent.torrent_info(torr_dec)
m = re.match( '([\w\d\(\)\.]+)\.([\d]{4}|[sS][0-9]{1,2}[eE][0-9]{1,2})', info.name() )
down_dir = os.path.join( out_dir_base, m.group(1).replace('.', ' ') )
if not os.path.exists(down_dir):
os.makedirs(down_dir)
subprocess.call( ['transmission-remote', 'localhost', '-a', item['link'], '-w', down_dir] )
log.write( item['link'] + '\n' )
log.close
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment