diff --git a/couchpotato/core/providers/automation/letterboxd/__init__.py b/couchpotato/core/providers/automation/letterboxd/__init__.py new file mode 100644 index 0000000..17f5ae2 --- /dev/null +++ b/couchpotato/core/providers/automation/letterboxd/__init__.py @@ -0,0 +1,28 @@ +from .main import Letterboxd + +def start(): + return Letterboxd() + +config = [{ + 'name': 'letterboxd', + 'groups': [ + { + 'tab': 'automation', + 'list': 'watchlist_providers', + 'name': 'letterboxd_automation', + 'label': 'Letterboxd', + 'description': 'import movies from your Letterboxd watchlist', + 'options': [ + { + 'name': 'automation_enabled', + 'default': False, + 'type': 'enabler', + }, + { + 'name': 'automation_username', + 'label': 'Username', + }, + ], + }, + ], +}] \ No newline at end of file diff --git a/couchpotato/core/providers/automation/letterboxd/main.py b/couchpotato/core/providers/automation/letterboxd/main.py new file mode 100644 index 0000000..3c60d58 --- /dev/null +++ b/couchpotato/core/providers/automation/letterboxd/main.py @@ -0,0 +1,37 @@ +from couchpotato.core.logger import CPLog +from couchpotato.core.providers.automation.base import Automation +from bs4 import BeautifulSoup +import re + +log = CPLog(__name__) + + +class Letterboxd(Automation): + url = 'http://letterboxd.com/%s/watchlist/' + pattern = re.compile(r'(.*)\((\d*)\)') + + def getIMDBids(self): + + if not self.conf('automation_username'): + log.error('Please fill in your username') + return [] + + movies = [] + + for movie in self.getWatchlist(): + imdb_id = self.search(movie.get('title'), movie.get('year'), imdb_only = True) + movies.append(imdb_id) + + return movies + + def getWatchlist(self): + url = self.url % self.conf('automation_username') + soup = BeautifulSoup(self.getHTMLData(url)) + + movies = [] + + for movie in soup.find_all('a', attrs = { 'class': 'frame' }): + match = filter(None, self.pattern.split(movie['title'])) + movies.append({ 'title': match[0], 'year': match[1] }) + + return movies