Use rss for imdb watchlist. fix #322
This commit is contained in:
@@ -10,7 +10,7 @@ config = [{
|
|||||||
'tab': 'automation',
|
'tab': 'automation',
|
||||||
'name': 'imdb_automation',
|
'name': 'imdb_automation',
|
||||||
'label': 'IMDB',
|
'label': 'IMDB',
|
||||||
'description': 'From any <strong>public</strong> IMDB watchlists. Url should end with <strong>export?list_id=XXXXX&author_id=XXXXX<strong>',
|
'description': 'From any <strong>public</strong> IMDB watchlists. Url should be the RSS link.',
|
||||||
'options': [
|
'options': [
|
||||||
{
|
{
|
||||||
'name': 'automation_enabled',
|
'name': 'automation_enabled',
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
from couchpotato.core.helpers.variable import md5
|
from couchpotato.core.helpers.rss import RSS
|
||||||
|
from couchpotato.core.helpers.variable import md5, getImdb
|
||||||
from couchpotato.core.logger import CPLog
|
from couchpotato.core.logger import CPLog
|
||||||
from couchpotato.core.providers.automation.base import Automation
|
from couchpotato.core.providers.automation.base import Automation
|
||||||
from couchpotato.environment import Env
|
from couchpotato.environment import Env
|
||||||
from dateutil.parser import parse
|
from dateutil.parser import parse
|
||||||
import StringIO
|
|
||||||
import csv
|
|
||||||
import time
|
import time
|
||||||
import traceback
|
import traceback
|
||||||
|
import xml.etree.ElementTree as XMLTree
|
||||||
|
|
||||||
log = CPLog(__name__)
|
log = CPLog(__name__)
|
||||||
|
|
||||||
|
|
||||||
class IMDB(Automation):
|
class IMDB(Automation, RSS):
|
||||||
|
|
||||||
interval = 1800
|
interval = 1800
|
||||||
|
|
||||||
@@ -21,46 +21,41 @@ class IMDB(Automation):
|
|||||||
return
|
return
|
||||||
|
|
||||||
movies = []
|
movies = []
|
||||||
headers = {}
|
|
||||||
|
|
||||||
enablers = self.conf('automation_urls_use').split(',')
|
enablers = self.conf('automation_urls_use').split(',')
|
||||||
|
|
||||||
index = -1
|
index = -1
|
||||||
for csv_url in self.conf('automation_urls').split(','):
|
for rss_url in self.conf('automation_urls').split(','):
|
||||||
|
|
||||||
index += 1
|
index += 1
|
||||||
if not enablers[index]:
|
if not enablers[index]:
|
||||||
continue
|
continue
|
||||||
elif 'author_id=' not in csv_url:
|
elif 'rss.imdb' not in rss_url:
|
||||||
log.error('This isn\'t the correct url.: %s' % csv_url)
|
log.error('This isn\'t the correct url.: %s' % rss_url)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
prop_name = 'automation.imdb.last_update.%s' % md5(csv_url)
|
prop_name = 'automation.imdb.last_update.%s' % md5(rss_url)
|
||||||
last_update = float(Env.prop(prop_name, default = 0))
|
last_update = float(Env.prop(prop_name, default = 0))
|
||||||
|
|
||||||
try:
|
try:
|
||||||
cache_key = 'imdb_csv.%s' % md5(csv_url)
|
cache_key = 'imdb.rss.%s' % md5(rss_url)
|
||||||
csv_data = self.getCache(cache_key, csv_url)
|
|
||||||
csv_reader = csv.reader(StringIO.StringIO(csv_data))
|
|
||||||
if not headers:
|
|
||||||
nr = 0
|
|
||||||
for column in csv_reader.next():
|
|
||||||
headers[column] = nr
|
|
||||||
nr += 1
|
|
||||||
else:
|
|
||||||
csv_reader.next()
|
|
||||||
|
|
||||||
for row in csv_reader:
|
rss_data = self.getCache(cache_key, rss_url)
|
||||||
created = int(time.mktime(parse(row[headers['created']]).timetuple()))
|
data = XMLTree.fromstring(rss_data)
|
||||||
if created < last_update:
|
rss_movies = self.getElements(data, 'channel/item')
|
||||||
|
|
||||||
|
for movie in rss_movies:
|
||||||
|
created = int(time.mktime(parse(self.getTextElement(movie, "pubDate")).timetuple()))
|
||||||
|
imdb = getImdb(self.getTextElement(movie, "link"))
|
||||||
|
|
||||||
|
if not imdb or created < last_update:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
imdb = row[headers['const']]
|
movies.append(imdb)
|
||||||
if imdb:
|
|
||||||
movies.append(imdb)
|
|
||||||
except:
|
except:
|
||||||
log.error('Failed loading IMDB watchlist: %s %s' % (csv_url, traceback.format_exc()))
|
log.error('Failed loading IMDB watchlist: %s %s' % (rss_url, traceback.format_exc()))
|
||||||
|
|
||||||
Env.prop(prop_name, time.time())
|
Env.prop(prop_name, time.time())
|
||||||
|
|
||||||
|
|
||||||
return movies
|
return movies
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 32 KiB After Width: | Height: | Size: 41 KiB |
Reference in New Issue
Block a user