Пример #1
0
    def from_file(filename):
        try:
            j = json.load(open(filename, 'r'))
        except IOError as e:
            print "Error opening show:", e
            return None

        name = j['name']
        start = numbering_from_str(j['start'])
        airdates = dict((start.from_str(e), datetime.strptime(d, "%Y/%m/%d").date()) for e, d in j.get('airdates', {}).iteritems())
        name_matcher = NameMatcher(j.get('match', { 'name': name }))

        sources = []
        for source_name, source_params in j['sources'].iteritems():
            params = config.source(source_name)
            params.update(source_params)
            source = get_source(source_name, params)
            if source:
                sources.append(source)

        condition = j.get('condition', config.condition)

        rules = list(flatten(config.bind_rules(j.get('rules'))))
        if not rules:
            rules = [config.rule('default')]
        return Show(name, filename, start, airdates, name_matcher, sources, condition, rules)
Пример #2
0
 def load(show):
     filename = config.hits_dir + '/' + remove_extension(show.from_file) + '.hits.json'
     try:
         j = json.load(open(filename, 'r'))
         j['current'] = numbering_from_str(j['current'])
         j['airdates'] = dict((j['current'].from_str(e), datetime.strptime(d, "%Y/%m/%d").date()) for e, d in j.get('airdates', {}).iteritems())
         if 'torrents' not in j:
             j['torrents'] = {}
         for k, v in j['torrents'].iteritems():
             j['torrents'][k] = [Torrent(**t) for t in v]
         return j
     except IOError as ex:
         return Hits.default_content(show.start)
Пример #3
0
    def download(self):
        "Download the best torrent for the current episode"
        torrent = self.best_candidate()
        if not torrent:
            return
        log.info("  - Downloading %s" % torrent.url)
        try:
            req = fetch(torrent.url)
            with open(config.torrents_dir + '/' + torrent.name + '.torrent', 'wb') as f:
                f.write(req.read())
        except Exception as e:
            torrent.failed_download = torrent.get('failed_download', 0) + 1
            print "  - Failed for the %d time(s) [%s, %s]" % (torrent.failed_download, type(e), e)
            self.hits.save()
            return
        guessed_next = numbering_from_str(torrent.next_episode)

        next, _ = self.get_episodes_after(guessed_next)
        self.hits.current = next if next else guessed_next
        log.info("  - Current episode is now %s" % self.hits.current)
        torrent.downloaded = True

        self.hits.save()
Пример #4
0
 def reset(self, episode):
     episode = numbering_from_str(episode) if episode else self.start
     log.info("Resetting '%s' to '%s'" % (self.name, episode))
     self.hits = Hits.empty(self, episode)
     self.hits.save()