update tvrss

This commit is contained in:
j 2007-03-02 20:44:43 +00:00
parent a9c8d43f6b
commit 0a8d0b2170
2 changed files with 53 additions and 27 deletions

View file

@ -170,9 +170,9 @@ class IMDb:
else: else:
IMDbDict['rating'] = -1 IMDbDict['rating'] = -1
#Votes #Votes
m = re.compile('<small>\(<a href="ratings">(.*?) votes</a>\)</small>', re.IGNORECASE).search(data) m = re.compile('<small>\(<a href="ratings">(.*?) votes</a>\)</small>', re.IGNORECASE).findall(data)
if m: if m:
IMDbDict['votes'] = int(m.group(1).replace(',', '')) IMDbDict['votes'] = int(m[0].replace(',', ''))
else: else:
IMDbDict['votes'] = -1 IMDbDict['votes'] = -1

View file

@ -9,6 +9,7 @@ import datetime
import time import time
import re import re
from urllib2 import urlopen from urllib2 import urlopen
from urllib import quote
import Image import Image
import StringIO import StringIO
@ -52,6 +53,17 @@ def get_episodedate(string):
return s[1].strip() return s[1].strip()
return None return None
def get_episode_string(string):
episode = get_episode(string)
season = get_season(string)
episodedate = get_episodedate(string)
estring = None
if season and episode:
estring = "S%02dE%02d" % (season, episode)
elif episodedate:
estring = episodedate
return estring
def choose_item(old, new): def choose_item(old, new):
if old['link'] == new['link']: if old['link'] == new['link']:
return False return False
@ -63,29 +75,50 @@ def choose_item(old, new):
return True return True
return False return False
def get_episodes(show_title):
search_url = "http://tvrss.net/search/index.php?distribution_group=combined&show_name=%s&show_name_exact=true&filename=&date=&quality=&release_group=&mode=rss" % quote(show_title)
data = read_url(search_url)
fd = feedparser.parse(search_url)
episodes = {}
for t in fd.entries:
episode = get_episode_string(t['summary'])
episodes[episode] = t['enclosures'][0]['href']
return episodes
def get_thumbnail(url):
try:
thumbnail = read_url(url)
im = Image.open(StringIO.StringIO(thumbnail))
out = StringIO.StringIO()
width = 100
height = int((100.0 / im.size[0]) * im.size[1])
im = im.resize((width, height))
im.crop((0,0,100,100)).convert().save(out, 'JPEG')
thumbnail = out.getvalue()
except:
thumbnail = None
return thumbnail
def get_imdbdata(imdbid): def get_imdbdata(imdbid):
thumbnail = None thumbnail = None
description='' description=''
imdb = IMDb.parse(imdbid) i = imdb.IMDb(imdbid).parse()
if imdb: if i:
poster = imdb['poster'] poster = i['poster']
if poster != 'http://i.imdb.com/Heads/npa.gif': if poster != 'http://i.imdb.com/Heads/npa.gif':
log.debug("getting poster %s" % poster) log.debug("getting poster %s" % poster)
try: thumbnail = get_thumbnail(poster)
thumbnail = read_url(poster) if i['plot']:
im = Image.open(StringIO.StringIO(thumbnail)) description=i['plot']
out = StringIO.StringIO() elif i['plot_outline']:
im.crop((0,0,100,100)).convert().save(out, 'JPEG') description=i['plot_outline']
thumbnail = out.getvalue()
except:
thumbnail = None
if imdb['summary']:
description=imdb['summary']
else: else:
description=imdb['tagline'] description=i['tagline']
return (imdb, description, thumbnail)
return (i, description, thumbnail)
else: else:
return(imdb, '', None) return(i, '', None)
def load(): def load():
log.debug("getting new shows from tvrss...") log.debug("getting new shows from tvrss...")
@ -93,14 +126,7 @@ def load():
shows = {} shows = {}
for item in feed['entries']: for item in feed['entries']:
show = get_show(item['description']) show = get_show(item['description'])
season = get_season(item['description']) estring = get_episode_string(item['description'])
episode = get_episode(item['description'])
episodedate = get_episodedate(item['description'])
estring = None
if season and episode:
estring = "S%02dE%02d" %(season, episode)
elif episodedate:
estring = episodedate
if estring: if estring:
if show and not hr_hdtv.search(item['title']): if show and not hr_hdtv.search(item['title']):
if shows.has_key(show): if shows.has_key(show):