@@ -0,0 +1,3201 @@
+from __future__ import unicode_literals, division, absolute_import%0Aimport logging%0Aimport xml.etree.ElementTree as ElementTree%0A%0Afrom requests import RequestException%0A%0Afrom flexget import plugin%0Afrom flexget.event import event%0A%0Atry:%0A    from flexget.plugins.api_tvdb import get_mirror, api_key%0Aexcept ImportError:%0A    raise plugin.DependencyError(issued_by='thetvdb_submit', missing='api_tvdb',%0A                                 message='thetvdb_add/remove requires the %60api_tvdb%60 plugin')%0A%0A%0Aclass TVDBSubmit(object):%0A    %0A    schema = %7B%0A        'type': 'object',%0A        'properties': %7B%0A            'account_id': %7B'type': 'string'%7D%0A        %7D,%0A        'required': %5B'account_id'%5D,%0A        'additionalProperties': False%0A    %7D%0A    %0A    # Defined by subclasses%0A    remove = None%0A    log = None%0A    %0A    def exists(self, favs, tvdb_id):%0A        if favs is not None:%0A            for series in favs.findall('Series'):%0A                if series.text == tvdb_id:%0A                    return True%0A        return False%0A    %0A    @plugin.priority(-255)%0A    def on_task_output(self, task, config):%0A        mirror = None%0A        favs = None%0A        for entry in task.accepted:%0A            if entry.get('tvdb_id'):%0A                tvdb_id = str(entry%5B'tvdb_id'%5D)%0A                ser_info = entry.get('series_name', tvdb_id)%0A                if favs is not None:%0A                    isin = self.exists(favs, tvdb_id)%0A                    if (self.remove and not isin) or (isin and not self.remove):%0A                        self.log.verbose('Nothing to do for series %25s, skipping...' %25 ser_info)%0A                        continue%0A                if not mirror:%0A                    mirror = get_mirror()%0A                url = mirror + 'User_Favorites.php?accountid=%25s&type=%25s&seriesid=%25s' %25 %5C%0A                    (config%5B'account_id'%5D, 'remove' if self.remove else 'add', tvdb_id)%0A                try:%0A                    page = task.requests.get(url).content%0A                except RequestException as e:%0A                    self.log.error('Error submitting series %25s to tvdb: %25s' %25 (tvdb_id, e))%0A                    continue%0A                if not page:%0A                    self.log.error('Null response from tvdb, aborting task.')%0A                    return%0A                favs = ElementTree.fromstring(page)%0A                isin = self.exists(favs, tvdb_id)%0A                if (isin and not self.remove):%0A                    self.log.verbose('Series %25s added to tvdb favorites.' %25 ser_info)%0A                elif (self.remove and not isin):%0A                    self.log.verbose('Series %25s removed from tvdb favorites.' %25 ser_info)%0A                else:%0A                    self.log.info(%22Operation failed for series %25s (don't know why).%22 %25 ser_info)%0A%0A%0Aclass TVDBAdd(TVDBSubmit):%0A    %22%22%22Add all accepted shows to your tvdb favorites.%22%22%22%0A    remove = False%0A    log = logging.getLogger('thetvdb_add')%0A%0A%0Aclass TVDBRemove(TVDBSubmit):%0A    %22%22%22Remove all accepted shows from your tvdb favorites.%22%22%22%0A    remove = True%0A    log = logging.getLogger('thetvdb_remove')%0A%0A%0A@event('plugin.register')%0Adef register_plugin():%0A    plugin.register(TVDBAdd, 'thetvdb_add', api_ver=2)%0A    plugin.register(TVDBRemove, 'thetvdb_remove', api_ver=2)%0A

Manage TVDB favorites