Unverified Commit 08fe1891 authored by TheTechRobo's avatar TheTechRobo
Browse files

Small refactoring in the module (this is why it's not published yet)

Also add some details to the README
parent a8cc50fb
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
config.py
README.md.backup
*.pyc
nohup.out
+19 −1
Original line number Diff line number Diff line
# youtubevideofinder
# lostmediafinder

Currently YouTube is the only supported site, but that might change.

Contributions are welcome!

## CLI tool
Currently no documentation exists for the CLI tool.

## Usage as a module
There are docstrings included in the module (it is contained in `lostmediafinder`), but no `setup.py` or PyPI package is currently included. This is because it is not yet 100% stable (and I plan on adding support for more websites soon).

## Frontend
### Running in Docker(recommended):
There is an included Dockerfile that should work 100% fine.
  
If it doesn't work that is considered a bug, as it is the only supported method of running the site.

## Licence

Copyright (c) 2022 TheTechRobo

+2 −4
Original line number Diff line number Diff line
@@ -2,12 +2,10 @@
The CLI interface of LostMediaFinder.
"""

import sys

import click
from switch import Switch

from . import Response
from . import YouTubeResponse

@click.command
@click.option("--format", default="text", help="Selects which format to output to stdout.", type=click.Choice(["json", "text"]))
@@ -24,7 +22,7 @@ def main(ctx, id: str, format: str) -> int:
    """
    click.echo("\033[1m\033[4m\033[1;31mUsing LostMediaFinder from the command-line is unstable!\033[0m", err=True)
    click.echo("Generating report, this could take some time...", err=True)
    response = Response.generate(id)
    response = YouTubeResponse.generate(id)
    with Switch(format) as case:
        if case("json"):
            click.echo(response.json())
+6 −6
Original line number Diff line number Diff line
@@ -9,9 +9,9 @@ import requests
from requests.auth import HTTPBasicAuth
from switch import Switch

from .types import Service, T
from .types import YouTubeService, T

class WaybackMachine(Service):
class WaybackMachine(YouTubeService):
    """
    Queries the Wayback Machine for the video you requested.
    """
@@ -40,7 +40,7 @@ class WaybackMachine(Service):
                note="", metaonly=ismeta, comments=False
        )

class InternetArchive(Service):
class InternetArchive(YouTubeService):
    """
    Queries the Internet Archive for the video you requested.
    """
@@ -78,7 +78,7 @@ class InternetArchive(Service):
            rawraw=rawraw, metaonly=False, comments=False
        )

class GhostArchive(Service):
class GhostArchive(YouTubeService):
    """
    Queries GhostArchive for the video you requested.
    """
@@ -105,7 +105,7 @@ class GhostArchive(Service):
            metaonly=False, comments=False
        )

class Ya(Service):
class Ya(YouTubeService):
    """
    Queries #youtubearchive for the video you requested.
    """
@@ -133,7 +133,7 @@ class Ya(Service):
            note=cls.note if archived else "", rawraw=rawraw, metaonly=False
        )

class Filmot(Service):
class Filmot(YouTubeService):
    """
    Queries Filmot for the video you requested.
    """
+13 −7
Original line number Diff line number Diff line
@@ -27,7 +27,7 @@ def update_cnfig(ya, filmot, version):

nest_asyncio.apply()

T = typing.TypeVar("T", bound="Service") # pylint: disable=invalid-name
T = typing.TypeVar("T", bound="YouTubeService") # pylint: disable=invalid-name
# (this name is fine)

@dataclasses.dataclass
@@ -119,25 +119,28 @@ class Service(JSONDataclass):
"""
        return string

class YouTubeService(Service): # pylint: disable=abstract-method
    pass

@dataclasses.dataclass
class Response(JSONDataclass):
class YouTubeResponse(JSONDataclass):
    """
    A response from the server.

    Attributes:
        id (str): The interpreted video ID.
        status (str): bad.id if invalid ID.
        keys (list[Service]): An array with all the server responses. THIS IS DIFFERENT THAN BEFORE! Before, this would be an array of strings. You'd use the strings as keys. Now, this array has the data directly!
        keys (list[YouTubeService]): An array with all the server responses. THIS IS DIFFERENT THAN BEFORE! Before, this would be an array of strings. You'd use the strings as keys. Now, this array has the data directly!
        api_version (int): The API version. Currently set to %s. Breaking API changes are made by incrementing this. There may be a way to request a specific version in the future.
    """
    id: str
    status: str
    keys: list[Service]
    keys: list[YouTubeService]
    api_version: int = 2

    @classmethod
    def _get_services(cls):
        return Service.__subclasses__()
        return YouTubeService.__subclasses__()

    @classmethod
    def generate(cls, id, asyncio=False):
@@ -176,5 +179,8 @@ class Response(JSONDataclass):
{services}"""
        return string

Response.__doc__ = Response.__doc__.replace("%s", str(Response.api_version))
# TODO: Refactor Response a lot into a more generic thing,
# then make YouTubeResponse the same thing but specifying the keys
# and also specifying the subclasses to search

YouTubeResponse.__doc__ = YouTubeResponse.__doc__.replace("%s", str(YouTubeResponse.api_version))