diff --git a/fimfarchive/fetchers.py b/fimfarchive/fetchers.py index 2dcb242..e726b89 100644 --- a/fimfarchive/fetchers.py +++ b/fimfarchive/fetchers.py @@ -147,8 +147,8 @@ class FimfictionFetcher(Fetcher): prefetch_meta = True prefetch_data = False - data_path = 'https://www.fimfiction.net/download_story.php' - meta_path = 'https://www.fimfiction.net/api/story.php' + data_path = 'https://www.fimfiction.net/story/download/{}/html' + meta_path = 'https://www.fimfiction.net/api/story.php?story={}' flavors = frozenset(( StorySource.FIMFICTION, @@ -156,25 +156,28 @@ class FimfictionFetcher(Fetcher): MetaPurity.DIRTY, )) - def get(self, url, **kwargs): + def get(self, url): """ Performs an HTTP GET request. Args: url: Target of the HTTP request. - **kwargs: HTTP query parameters. Returns: Response: A new `Response` object. Raises: - StorySourceError: If the server does not return HTTP 200 OK. + InvalidStoryError: If access to the resource was denied. + StorySourceError: If the request fails for any other reason. """ try: - response = requests.get(url, params=kwargs, timeout=60) + response = requests.get(url, timeout=60) except OSError as e: raise StorySourceError("Could not read from server.") from e + if response.status_code == 403: + raise InvalidStoryError("Access to resource was denied.") + if not response.ok: raise StorySourceError( "Server responded with HTTP {} {}." @@ -184,13 +187,14 @@ class FimfictionFetcher(Fetcher): return response def fetch_data(self, key): - response = self.get(self.data_path, story=key, html=True) + url = self.data_path.format(key) + response = self.get(url) data = response.content if len(data) == 0: raise InvalidStoryError("Server returned empty response body.") - if b'