예제 #1
0
    def test_valid_size(self):
        t = Torrent.from_file(get_fixture("linux-iso.torrent"))
        section_name = "section_movie"
        config.set(section_name, "size_min", 1)
        config.set(section_name, "size_max", 10000)
        self.assertTrue(parser.valid_size(t, section_name))

        config.set(section_name, "size_max", 400)
        self.assertFalse(parser.valid_size(t, section_name))

        config.set(section_name, "size_min", 7000)
        config.set(section_name, "size_max", 10000)
        self.assertFalse(parser.valid_size(t, section_name))
예제 #2
0
    def test_valid_size(self):
        t = Torrent.from_file(get_fixture("linux-iso.torrent"))
        section_name = "section_movie"
        config.set(section_name, "size_min", 1)
        config.set(section_name, "size_max", 10000)
        self.assertTrue(parser.valid_size(t, section_name))

        config.set(section_name, "size_max", 400)
        self.assertFalse(parser.valid_size(t, section_name))

        config.set(section_name, "size_min", 7000)
        config.set(section_name, "size_max", 10000)
        self.assertFalse(parser.valid_size(t, section_name))
예제 #3
0
파일: rss.py 프로젝트: kannibalox/tranny
    def parse_entry(self, session, entry):
        """ Parse RSS entry data for qualified torrents to download

        :param session: DB Session
        :type session: sqlalchemy.orm.session.Session
        :param entry: RSS Feed entry data
        :type entry: dict
        :return: A parsed release object ready to load into backend client or None on fail
        :rtype: release.TorrentData, None
        """

        release_name = entry.get('title', "")
        if not release_name:
            self.log.warning("No title parsed from RSS feed. Malformed?")
            return False
        release_info = parser.parse_release(release_name)
        if not release_info.release_key:
            self.log.warning("No release key parsed from release name: {}".format(release_name))
            return False
        release_key = release_info.release_key
        section_name = parser.validate_section(release_info)
        if not section_name or section_name == "section_movie":
            return False
        if self.exists(session, release_key) and not self.is_replacement(release_info):
            return False
        torrent_data = net.http_request(entry['link'], json=False)
        if not torrent_data:
            self.log.error("Failed to download torrent data from server: {0}".format(entry['link']))
            return False
        data = release.TorrentData(bytes(release_name), torrent_data, section_name), release_info
        torrent = Torrent.from_str(torrent_data)
        if not parser.valid_size(torrent, section_name):
            return False
        return data
예제 #4
0
    def fetch_releases(self, session, scene_only=True):
        """ Generator which yields torrent data to be loaded into backend daemons

        :param session:
        :type session: sqlalchemy.orm.session.Session
        :param scene_only: Only fetch scene releases
        :type scene_only: bool
        :return: Matched Downloaded torrents
        :rtype: TorrentData[]
        """
        found = []
        try:
            releases = list(self.get_torrents_browse(50)['torrents'].values())
        except (TypeError, KeyError) as err:
            self.log.debug("Failed to fetch releases")
        else:
            if scene_only:
                releases = [
                    rls for rls in releases if rls['Origin'] == "Scene"
                ]
            for entry in releases:
                release_name = entry['ReleaseName']
                release_info = parser.parse_release(
                    release_name, guess_type=constants.MEDIA_TV)
                if not release_info:
                    continue
                section_name = parser.validate_section(release_info)
                if not section_name:
                    continue
                if self.exists(session, release_info.release_key
                               ) and not self.is_replacement(release_info):
                    continue
                #dl_url = self.get_torrent_url(entry['TorrentID'])
                torrent_data = net.http_request(entry['DownloadURL'],
                                                json=False)
                if not torrent_data:
                    self.log.error(
                        "Failed to download torrent data from server: {0}".
                        format(entry['link']))
                    continue
                data = release.TorrentData(str(release_name), torrent_data,
                                           section_name)
                torrent = Torrent.from_str(torrent_data)
                if not parser.valid_size(torrent, section_name):
                    continue
                yield data, release_info
예제 #5
0
파일: rss.py 프로젝트: bobbintb/tranny
    def parse_entry(self, session, entry):
        """ Parse RSS entry data for qualified torrents to download

        :param session: DB Session
        :type session: sqlalchemy.orm.session.Session
        :param entry: RSS Feed entry data
        :type entry: dict
        :return: A parsed release object ready to load into backend client or None on fail
        :rtype: release.TorrentData, None
        """

        release_name = entry.get('title', "")
        if not release_name:
            self.log.warning("No title parsed from RSS feed. Malformed?")
            return False
        release_info = parser.parse_release(release_name)
        if not release_info.release_key:
            self.log.warning(
                "No release key parsed from release name: {}".format(
                    release_name))
            return False
        release_key = release_info.release_key
        section_name = parser.validate_section(release_info)
        if not section_name or section_name == "section_movie":
            return False
        if self.exists(session,
                       release_key) and not self.is_replacement(release_info):
            return False
        torrent_data = net.http_request(entry['link'], json=False)
        if not torrent_data:
            self.log.error(
                "Failed to download torrent data from server: {0}".format(
                    entry['link']))
            return False
        data = release.TorrentData(bytes(release_name), torrent_data,
                                   section_name), release_info
        torrent = Torrent.from_str(torrent_data)
        if not parser.valid_size(torrent, section_name):
            return False
        return data
예제 #6
0
    def fetch_releases(self, session, scene_only=True):
        """ Generator which yields torrent data to be loaded into backend daemons

        :param session:
        :type session: sqlalchemy.orm.session.Session
        :param scene_only: Only fetch scene releases
        :type scene_only: bool
        :return: Matched Downloaded torrents
        :rtype: TorrentData[]
        """
        found = []
        try:
            releases = self.get_torrents_browse(50)['torrents'].values()
        except (TypeError, KeyError) as err:
            self.log.debug("Failed to fetch releases")
        else:
            if scene_only:
                releases = [rls for rls in releases if rls['Origin'] == "Scene"]
            for entry in releases:
                release_name = entry['ReleaseName']
                release_info = parser.parse_release(release_name, guess_type=constants.MEDIA_TV)
                if not release_info:
                    continue
                section_name = parser.validate_section(release_info)
                if not section_name:
                    continue
                if self.exists(session, release_info.release_key) and not self.is_replacement(release_info):
                    continue
                #dl_url = self.get_torrent_url(entry['TorrentID'])
                torrent_data = net.http_request(entry['DownloadURL'], json=False)
                if not torrent_data:
                    self.log.error("Failed to download torrent data from server: {0}".format(entry['link']))
                    continue
                data = release.TorrentData(str(release_name), torrent_data, section_name)
                torrent = Torrent.from_str(torrent_data)
                if not parser.valid_size(torrent, section_name):
                    continue
                yield data, release_info