Beispiel #1
0
 def test_parse_release(self):
     args = [
         [
             u"f1-{}".format(datetime.now().isocalendar()[1]),
             u"F1.2012.Canadian.Grand.Prix.Qualifying.720p.HDTV.x264-XX",
             parser.TVSingleReleaseKey
         ],
         [
             u"first.snow-2006", u'First Snow 2006 BRRip XvidHD 720p-XX',
             parser.MovieReleaseKey
         ],
         [
             u"conan-2013_04_15",
             u"Conan.2013.4.15.Chelsea.Handler.HDTV.x264-XX",
             parser.TVDailyReleaseKey
         ],
         [
             u"conan-2013_04_15",
             u"Conan.2013.04.15.Chelsea.Handler.HDTV.x264-XX",
             parser.TVDailyReleaseKey
         ],
         [
             u"game.of.kitties-3_3",
             u"Game.of.Kitties.S03E03.720p.HDTV.x264-XX",
             parser.TVReleaseKey
         ],
         [
             u"homeland-2", "Homeland.S02.HDTV.x264-EVOLVE",
             parser.TVSeasonReleaseKey
         ],
     ]
     for i in args:
         release = parser.parse_release(i[1])
         self.assertEqual(release.release_key, i[0])
         self.assertEqual(type(release.release_key), i[2])
Beispiel #2
0
    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
Beispiel #3
0
 def test_parse_release(self):
     args = [
         [u"f1-{}".format(datetime.now().isocalendar()[1]),
          u"F1.2012.Canadian.Grand.Prix.Qualifying.720p.HDTV.x264-XX", parser.TVSingleReleaseKey],
         [u"first.snow-2006", u'First Snow 2006 BRRip XvidHD 720p-XX', parser.MovieReleaseKey],
         [u"conan-2013_04_15", u"Conan.2013.4.15.Chelsea.Handler.HDTV.x264-XX", parser.TVDailyReleaseKey],
         [u"conan-2013_04_15", u"Conan.2013.04.15.Chelsea.Handler.HDTV.x264-XX", parser.TVDailyReleaseKey],
         [u"game.of.kitties-3_3", u"Game.of.Kitties.S03E03.720p.HDTV.x264-XX", parser.TVReleaseKey],
         [u"homeland-2", "Homeland.S02.HDTV.x264-EVOLVE", parser.TVSeasonReleaseKey],
     ]
     for i in args:
         release = parser.parse_release(i[1])
         self.assertEqual(release.release_key, i[0])
         self.assertEqual(type(release.release_key), i[2])
Beispiel #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
Beispiel #5
0
    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
Beispiel #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