Unverified Commit 81edb462 authored by TheTechRobo's avatar TheTechRobo Committed by GitHub
Browse files

Merge pull request #19 from TheTechRobo/documentation-lol

parents 610a1e9a 9d412e6a
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
config.py
README.md.backup
*.pyc
nohup.out
+21 −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.

Instead of modiying the gunicorn config, use `GUNICORN_<VARIABLE_NAME>`; the config is setup to work with that. For example `GUNICORN_WORKERS`

## Licence

Copyright (c) 2022 TheTechRobo

+4 −0
Original line number Diff line number Diff line
# Convert environment variables to configuration
# e.g. GUNICORN_WORKERS=4
# The GUNICORN_  must be capatalised

import os

for k,v in os.environ.items():
+16 −10
Original line number Diff line number Diff line
"""
The CLI interface of LostMediaFinder.
None of this is public API!
"""

import sys

import click
from switch import Switch

from . import Response
from . import YouTubeResponse

@click.group(help="CLI tool to search for lost media")
def main():
    """
    Error codes:
        - 0: All operations (seem) successful.
        - 1: A fatal error was thrown.
        - 2: One or more operations failed.
    """

@click.command
@click.option("--format", default="text", help="Selects which format to output to stdout.", type=click.Choice(["json", "text"]))
@click.argument("id")
@click.pass_context
def main(ctx, id: str, format: str) -> int:
def youtube(ctx, id: str, format: str) -> int:
    """
    Parses CLI arguments and returns the Response for the video ID <IDENT>.

    Error codes:
        - 0: All operations (seem) successful.
        - 1: A fatal error was thrown.
        - 2: One or more operations failed.
    """
    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)
    if response.status == "bad.id":
        raise ValueError("Bad video ID - does not match regex")
    with Switch(format) as case:
        if case("json"):
            click.echo(response.json())
@@ -36,4 +41,5 @@ def main(ctx, id: str, format: str) -> int:
    code = 2 if errors else 0
    ctx.exit(code)

main.add_command(youtube)
main() # pylint: disable=no-value-for-parameter
+10 −10
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.
    """
@@ -117,8 +117,8 @@ class Ya(Service):
    @classmethod
    def _run(cls, id, includeRaw=True, asynchronous=False):
        vid = id
        assert cls._getFromConfig("enabled"), "#youtubearchive API access is not enabled"
        auth = HTTPBasicAuth(cls._getFromConfig("username"), cls._getFromConfig("password"))
        assert cls._getFromConfig("ya", "enabled"), "#youtubearchive API access is not enabled"
        auth = HTTPBasicAuth(cls._getFromConfig("ya", "username"), cls._getFromConfig("ya", "password"))
        comments = False
        count = requests.get("https://ya.borg.xyz/cgi-bin/capture-count?v=" + vid, auth=auth, timeout=5).text
        if not count:
@@ -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.
    """
@@ -142,9 +142,9 @@ class Filmot(Service):

    @classmethod
    def _run(cls, id, includeRaw=True, asynchronous=False) -> T:
        enabled = cls._getFromConfig("enabled")
        enabled = cls._getFromConfig("filmot", "enabled")
        assert enabled, "Filmot API access is not enabled."
        key = cls._getFromConfig("key")
        key = cls._getFromConfig("filmot", "key")
        while time.time() - cls.lastretrieved < cls.cooldown:
            time.sleep(0.1)
        lastupdated = time.time()
Loading