# Path: fimfarchive/exceptions.py
# class InvalidStoryError(FimfarchiveError):
#     """
#     Story does not exist.
#     """
# 
# class StorySourceError(FimfarchiveError):
#     """
#     Story source is unusable.
#     """
# 
# Path: fimfarchive/flavors.py
# class StorySource(Flavor):
#     """
#     Indicates from where a story was fetched.
#     """
#     FIMFICTION = ()
#     FIMFARCHIVE = ()
# 
# class DataFormat(Flavor):
#     """
#     Indicates the file format of story data.
#     """
#     EPUB = ()
#     FPUB = ()
#     HTML = ()
#     JSON = ()
# 
# class MetaFormat(Flavor):
#     """
#     Indicates the general structure of story meta.
#     """
#     ALPHA = ()
#     BETA = ()
# 
# class MetaPurity(Flavor):
#     """
#     Indicates if story meta has been sanitized.
#     """
#     CLEAN = ()
#     DIRTY = ()
# 
# Path: fimfarchive/fetchers/base.py
# class Fetcher:
#     """
#     Abstract base class for story fetchers.
#     """
#     prefetch_meta = False
#     prefetch_data = False
# 
#     flavors: FrozenSet[Flavor] = frozenset()
# 
#     def __enter__(self):
#         """
#         Returns self for use in with statements.
#         """
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         """
#         Closes the fetcher on exit in with statements.
#         """
#         self.close()
# 
#     def close(self):
#         """
#         Closes file descriptors and frees memory.
#         """
#         pass
# 
#     def fetch(self, key, prefetch_meta=None, prefetch_data=None):
#         """
#         Fetches story information.
# 
#         Args:
#             key: Primary key of the story.
#             prefetch_meta: Force prefetching of meta.
#             prefetch_data: Force prefetching of data.
# 
#         Returns:
#             Story: A new `Story` object.
# 
#         Raises:
#             InvalidStoryError: If a valid story is not found.
#             StorySourceError: If source does not return any data.
#         """
#         if prefetch_meta is None:
#             prefetch_meta = self.prefetch_meta
# 
#         if prefetch_meta:
#             meta = self.fetch_meta(key)
#         else:
#             meta = None
# 
#         if prefetch_data is None:
#             prefetch_data = self.prefetch_data
# 
#         if prefetch_data:
#             data = self.fetch_data(key)
#         else:
#             data = None
# 
#         return Story(key, self, meta, data, self.flavors)
# 
#     def fetch_data(self, key):
#         """
#         Fetches story content data.
# 
#         Args:
#             key: Primary key of the story.
# 
#         Returns:
#             bytes: Story content data.
# 
#         Raises:
#             InvalidStoryError: If a valid story is not found.
#             StorySourceError: If source does not return any data.
#         """
#         raise NotImplementedError()
# 
#     def fetch_meta(self, key):
#         """
#         Fetches story meta information.
# 
#         Args:
#             key: Primary key of the story.
# 
#         Returns:
#             dict: Story meta information.
# 
#         Raises:
#             InvalidStoryError: If a valid story is not found.
#             StorySourceError: If source does not return any data.
#         """
#         raise NotImplementedError()


import requests
from fimfarchive.exceptions import InvalidStoryError, StorySourceError
from fimfarchive.flavors import StorySource, DataFormat, MetaFormat, MetaPurity
from .base import Fetcher
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#






__all__ = (
    'FimfictionFetcher',
)


class FimfictionFetcher(Fetcher):
    """
    Fetcher for Fimfiction.
    """
    prefetch_meta = True
    prefetch_data = False

    data_path = 'https://www.fimfiction.net/story/download/{}/html'
    meta_path = 'https://www.fimfiction.net/api/story.php?story={}'

    flavors = frozenset((
        StorySource.FIMFICTION,
        DataFormat.HTML,
        MetaFormat.ALPHA,

# Path: fimfarchive/exceptions.py
# class InvalidStoryError(FimfarchiveError):
#     """
#     Story does not exist.
#     """
# 
# class StorySourceError(FimfarchiveError):
#     """
#     Story source is unusable.
#     """
# 
# Path: fimfarchive/flavors.py
# class StorySource(Flavor):
#     """
#     Indicates from where a story was fetched.
#     """
#     FIMFICTION = ()
#     FIMFARCHIVE = ()
# 
# class DataFormat(Flavor):
#     """
#     Indicates the file format of story data.
#     """
#     EPUB = ()
#     FPUB = ()
#     HTML = ()
#     JSON = ()
# 
# class MetaFormat(Flavor):
#     """
#     Indicates the general structure of story meta.
#     """
#     ALPHA = ()
#     BETA = ()
# 
# class MetaPurity(Flavor):
#     """
#     Indicates if story meta has been sanitized.
#     """
#     CLEAN = ()
#     DIRTY = ()
# 
# Path: fimfarchive/fetchers/base.py
# class Fetcher:
#     """
#     Abstract base class for story fetchers.
#     """
#     prefetch_meta = False
#     prefetch_data = False
# 
#     flavors: FrozenSet[Flavor] = frozenset()
# 
#     def __enter__(self):
#         """
#         Returns self for use in with statements.
#         """
#         return self
# 
#     def __exit__(self, exc_type, exc_value, traceback):
#         """
#         Closes the fetcher on exit in with statements.
#         """
#         self.close()
# 
#     def close(self):
#         """
#         Closes file descriptors and frees memory.
#         """
#         pass
# 
#     def fetch(self, key, prefetch_meta=None, prefetch_data=None):
#         """
#         Fetches story information.
# 
#         Args:
#             key: Primary key of the story.
#             prefetch_meta: Force prefetching of meta.
#             prefetch_data: Force prefetching of data.
# 
#         Returns:
#             Story: A new `Story` object.
# 
#         Raises:
#             InvalidStoryError: If a valid story is not found.
#             StorySourceError: If source does not return any data.
#         """
#         if prefetch_meta is None:
#             prefetch_meta = self.prefetch_meta
# 
#         if prefetch_meta:
#             meta = self.fetch_meta(key)
#         else:
#             meta = None
# 
#         if prefetch_data is None:
#             prefetch_data = self.prefetch_data
# 
#         if prefetch_data:
#             data = self.fetch_data(key)
#         else:
#             data = None
# 
#         return Story(key, self, meta, data, self.flavors)
# 
#     def fetch_data(self, key):
#         """
#         Fetches story content data.
# 
#         Args:
#             key: Primary key of the story.
# 
#         Returns:
#             bytes: Story content data.
# 
#         Raises:
#             InvalidStoryError: If a valid story is not found.
#             StorySourceError: If source does not return any data.
#         """
#         raise NotImplementedError()
# 
#     def fetch_meta(self, key):
#         """
#         Fetches story meta information.
# 
#         Args:
#             key: Primary key of the story.
# 
#         Returns:
#             dict: Story meta information.
# 
#         Raises:
#             InvalidStoryError: If a valid story is not found.
#             StorySourceError: If source does not return any data.
#         """
#         raise NotImplementedError()


# Path: fimfarchive/fetchers/fimfiction.py
import requests
from fimfarchive.exceptions import InvalidStoryError, StorySourceError
from fimfarchive.flavors import StorySource, DataFormat, MetaFormat, MetaPurity
from .base import Fetcher

# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.
#






__all__ = (
    'FimfictionFetcher',
)


class FimfictionFetcher(Fetcher):
    """
    Fetcher for Fimfiction.
    """
    prefetch_meta = True
    prefetch_data = False

    data_path = 'https://www.fimfiction.net/story/download/{}/html'
    meta_path = 'https://www.fimfiction.net/api/story.php?story={}'

    flavors = frozenset((
        StorySource.FIMFICTION,
        DataFormat.HTML,
        MetaFormat.ALPHA,

        MetaPurity.DIRTY,