Exemplo n.º 1
0
    feeds = [l]
    films = list()
    films_to_base = list()
    downloads_list = list()
    rutracker_agent = RuTrackerAgent()
    for rf in feeds:
        filmsRss = feedparser.parse(rf.url)
        print 'Loaded ' + str(len(filmsRss.entries)) + ' films from "' + rf.title + '"'
        filteredEntries = filter(lambda x: rf.headerFilter(x.title), filmsRss.entries)
        print 'Saved ' + str(len(filteredEntries)) + ' after filtering by title'
        films.extend(map(lambda x: Film(x), filteredEntries))
        films = filter(lambda x: rf.ratingFilter(x), films)
        print 'Saved ' + str(len(films)) + ' after filtering by IMDB rating'

        for film in films:
            print "  %s" % film.title
            json_film = {
                'title': film.title,
                'rus_title': film.rus_title,
                'IMDBrating': film.IMDBrating,
                'size': film.size,
                'topic': film.topicURL + film.topicId,
                'year': film.year
            }
            if not already_downloaded(json_film):
                films_to_base.append(json_film)
                downloads_list.append(rutracker_agent.download_torrent(film.title, film.topicId, True))
            else:
                raise AlreadyDownloaded(json_film['title'])
    run_qbittorrent(downloads_list)
            print 'Authorizing on RuTracker...'
            self.opener.open('http://login.rutracker.org/forum/login.php', self.post_params)
            print 'Authorized'
            self.authorized = True

    def download_torrent(self, name, topic_id, to_rewrite):
        filename = filter(lambda x: x.isalpha() or x.isdigit(), name)
        filename_path = environment.get('downloaded_torrents_location') + filename + '.torrent'

        if (not os.path.exists(filename_path)) or to_rewrite:
            try:
                self.__authorise__()
            except:
                raise CannotAuthorize("RuTracker.org")
            with open(filename_path, 'wb') as torrent_file:
                print 'Downloading ' + filename_path
                web_file = self.opener.open('http://dl.rutracker.org/forum/dl.php?' + topic_id, self.post_params)
                torrent_file.write(web_file.read())
                torrent_file.close()
                print 'Downloaded'
        else:
            raise AlreadyDownloaded(filename_path)
        return filename_path


if __name__ == '__main__':
    a = RuTrackerAgent()
    file_list = list()
    file_list.append(a.download_torrent("The Man from UNCLE", 't=5108226', True))
    run_qbittorrent(file_list)