Skip to content

Instantly share code, notes, and snippets.

@juanrossi
Last active July 21, 2018 13:30
Show Gist options
  • Save juanrossi/47fc4b5166966d13ed612aaee9169ce9 to your computer and use it in GitHub Desktop.
Save juanrossi/47fc4b5166966d13ed612aaee9169ce9 to your computer and use it in GitHub Desktop.
Script to download TV Shows (uses showrss.info)
"""
Requirements:
* requests
* sqlite3
* xmltodict
* transmission-remote (add with brew or apt-get)
* showrss account and rss link
"""
import os
import requests
import sqlite3
import time
import xmltodict
URL = 'http://showrss.info/user/84098.rss?magnets=true&namespaces=true&name=null&quality=null&re=null'
IP = '127.0.0.1'
USER = 'transmission'
PASSWORD = 'password'
TIMER = 30
# Creates or opens a file called mydb with a SQLite3 DB
db_file = 'tvshows.db'
db = sqlite3.connect(db_file)
def boostrap():
cursor = db.cursor()
cursor.execute('''
CREATE TABLE if not exists shows(id INTEGER PRIMARY KEY, show_name VARCHAR(200),
show_id INT(11), episode_id INT(11))
''')
db.commit()
def download(magnet):
"""Add magnet to transmission-remote"""
cmd = "transmission-remote "
cmd = cmd + "%s -n %s:%s --add '%s'" % (IP, USER, PASS, magnet)
print cmd
os.system(cmd)
boostrap()
while True:
"""Get shows, verify if they had been downloaded or add them to list"""
rss = requests.get(URL).text
parse_rss = xmltodict.parse(rss)
cursor = db.cursor()
for shows in parse_rss.get('rss').get('channel').get('item'):
cursor.execute(
'''SELECT id FROM shows where show_id=? and episode_id=?;''',
(shows.get('tv:show_id'), shows.get('tv:episode_id'))
)
episode = cursor.fetchone()
print 'Verificando show: {}'.format(shows.get('title'))
if not episode:
cursor.execute('''INSERT INTO shows(show_name, show_id, episode_id)
VALUES(?,?,?)''', (shows.get('tv:show_name'), shows.get('tv:show_id'), shows.get('tv:episode_id')))
download(shows.get('link'))
print 'Bajando show: {}'.format(shows.get('title'))
else:
print 'Show ya bajado: {}'.format(shows.get('title'))
db.commit()
time.sleep(TIMER * 60)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment