Ejemplo n.º 1
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
Ejemplo n.º 2
0
def _get_request(method, *args, **kwargs):
    params = kwargs.get('params', None)
    args = [i for i in args if i]
    key = config.get_default('service_trakt', 'api_key', None)
    if not key:
        return {}
    full_url = "".join([_make_url(method, key), '/' if args else "", '/'.join(map(unicode, args))])
    return net.http_request(full_url, params=params, method='get')
Ejemplo n.º 3
0
def _get_request(method, *args, **kwargs):
    params = kwargs.get('params', None)
    args = [i for i in args if i]
    key = config.get_default('service_trakt', 'api_key', None)
    if not key:
        return {}
    full_url = "".join([
        _make_url(method, key), '/' if args else "", '/'.join(map(str, args))
    ])
    return net.http_request(full_url, params=params, method='get')
Ejemplo n.º 4
0
def fetch_update(download=True, url=_db_url):
    tmp_dir = join(config.config_path, 'geoip_temp')
    util.mkdirp(tmp_dir)
    tmp_dir_file = join(tmp_dir, 'geolite2.zip')
    if download:
        data_set = net.http_request(url, json=False)
        if data_set:
            with open(tmp_dir_file, 'wb') as out:
                out.write(data_set)
    return tmp_dir_file
Ejemplo n.º 5
0
def _post_request(method, data):
    key = config.get_default('service_trakt', 'api_key', None)
    if not key:
        return {}
    username = config.get("service_trakt", "username")
    password = config.get("service_trakt", "password")
    url = _make_url(method, key, json=False)
    data['username'] = username
    data['password'] = hashlib.sha1(password).hexdigest()
    results = net.http_request(url, data=data, method='post')
    return results
Ejemplo n.º 6
0
def _post_request(method, data):
    key = config.get_default('service_trakt', 'api_key', None)
    if not key:
        return {}
    username = config.get("service_trakt", "username")
    password = config.get("service_trakt", "password")
    url = _make_url(method, key, json=False)
    data['username'] = username
    data['password'] = hashlib.sha1(password).hexdigest()
    results = net.http_request(url, data=data, method='post')
    return results
Ejemplo n.º 7
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
Ejemplo n.º 8
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
Ejemplo n.º 9
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
Ejemplo n.º 10
0
 def test_http_request_post(self):
     with tapedeck.use_cassette(self.track("test_http_request_post")):
         resp = net.http_request('https://posttestserver.com/post.php', data={'test': 1}, method='post')
     self.assertTrue("dumped 1" in resp.content)