Пример #1
0
    def full_lookup(self, path):
        if self.media_id is not None:
            log.debug("Have IMDB ID, no further lookup necessary for {!r}", self)
            return complete(self)

        path = pathlib.Path(path)
        nfo = path.with_suffix('.nfo')

        log.debug("Attempting NFO read {!r}", nfo)
        try:
            e = lxml.etree.fromstring(nfo.open('rb').read())
        except lxml.etree.XMLSyntaxError as e:
            log.warning("Error reading XML for {!r} {}", nfo, e)
            return convoluted_imdb_lookup(self)
        except FileNotFoundError:
            log.debug("No nfo found, doing lookup")
            return convoluted_imdb_lookup(self)
        else:
            def attr(a):
                try:
                    return e.xpath('./{}'.format(a))[0].text
                except IndexError:
                    return None

            title = attr('title')
            year = attr('year')
            media_id = attr('id')
            genres = e.xpath('./genre/text()')

            new = {}
            if title:
                new['title'] = title
            if year:
                new['year'] = int(year)
            if media_id:
                new['media_id'] = media_id
            if genres:
                new['genres'] = genres

            if any([title is None, year is None, media_id is None, not genres]):
                # we'll do the IMDB lookup, but try and fill out with any
                # information we did have
                return convoluted_imdb_lookup(self._replace(**new))

            return complete(self._replace(**new))
Пример #2
0
 def full_lookup(self, path):
     # FIXME: attempt thetvdb lookups?
     return convoluted_imdb_lookup(self)