Commit 756531a5 authored by TheTechRobo's avatar TheTechRobo
Browse files

Document and improve URL param feature, increase contrast on Archived! result

parent 17ef79b3
Loading
Loading
Loading
Loading
+20 −4
Original line number Diff line number Diff line
from quart import Quart, jsonify, render_template, request, Response, redirect, send_from_directory, jsonify
import re, yaml, json, typing
from quart import Quart, render_template, request, Response, redirect, send_from_directory, url_for
import re, yaml, json
import lostmediafinder

app = Quart(__name__)
class EscapingQuart(Quart):
    def select_jinja_autoescape(self, filename: str) -> bool:
        return filename.endswith(".j2") or super().select_jinja_autoescape(filename)

app = EscapingQuart(__name__)

with open('config.yml', 'r') as file:
    config_yml = yaml.safe_load(file)
@@ -132,7 +136,19 @@ async def index():
    """
    default = request.args.get("q") or ""
    default_id = coerce_to_id(default) or ""
    return await render_template("index.j2", default=default, default_id=default_id, methods=get_enabled_methods())
    if default and default_id and default != default_id:
        return redirect(url_for("index", q=default_id))
    absolute_url = url_for(
        "index",
        _external=True
    ) + "?q=https://youtube.com/watch?v=dQw4w9WgXcQ"
    return await render_template(
        "index.j2",
        default=default,
        default_id=default_id,
        methods=get_enabled_methods(),
        absolute_url=absolute_url
    )

# The following code should be taken out and shot
def parse_changelog(changelog):
+20 −20
Original line number Diff line number Diff line
@@ -3,17 +3,17 @@ const getVideoInput = () => document.getElementById("videoInput");
const getSubmitBtn = () => document.getElementById("submit");

function isValidVideoId(videoId) {
    return videoId.match(/^[A-Za-z0-9_-]{10}[AEIMQUYcgkosw048]$/)
    return videoId.match(/^[A-Za-z0-9_-]{10}[AEIMQUYcgkosw048]$/);
}

function getVideoId(videoInput) {
    // Regexes here are based on the ones from https://github.com/mattwright324/youtube-metadata/blob/master/js/shared.js#L8-L14
    let patterns = [
    const patterns = [
        /(?:https?:\/\/)?(?:\w+\.)?youtube\.com\/watch\/?\?(?:[^&#]+&)*v=([A-Za-z0-9_-]{10}[AEIMQUYcgkosw048])(?:[\/&].*)?(?:#.*)?/i,
        /(?:https?:\/\/)?(?:\w+\.)?youtube.com\/(?:v|embed|shorts|video)\/([A-Za-z0-9_-]{10}[AEIMQUYcgkosw048])(?:[\/&].*)?/i,
        /(?:https?:\/\/)?youtu.be\/([A-Za-z0-9_-]{10}[AEIMQUYcgkosw048])(?:\?.*)?/i,
        /(?:https?:\/\/)?filmot.com\/video\/([A-Za-z0-9_-]{10}[AEIMQUYcgkosw048])(?:\?.*)?/i,
    ]
    ];
    for (i = 0; i < patterns.length; i++) {
        let pattern = patterns[i];
        let newVid = videoInput.replace(pattern, function (match, newVid) {
@@ -47,8 +47,8 @@ function makeServiceEntry(result) {
    let archived = `<span class='${colour}'>${isarchived}</span>`;
    let metaonly = (result.metaonly && result.archived) ? " (metadata only) " : " ";
    let comments = (result.archived && result.comments) ? " (incl. comments) " : " ";
    let lien = result.available ? `<a href="${result.available}">(link)</a>` : ""
    return `${archived}${metaonly}${comments}${lien}<br />${result.note}`
    let lien = result.available ? `<a href="${result.available}">(link)</a>` : "";
    return `${archived}${metaonly}${comments}${lien}<br />${result.note}`;
}

// https://stackoverflow.com/a/48054293/9654083
@@ -81,7 +81,7 @@ function finish(vid1) {
        let newVid = getVideoId(vid);
        console.log(newVid);
        if (!newVid) {
            dataDiv.innerHTML = `<span style="color:red;">That doesn't look like a valid video ID.<br />If it is valid, please report the bug on github!</span>`;
            dataDiv.innerHTML = `<span style="color:red;">That doesn't look like a valid video ID.<br />If it is valid, please report the bug on GitHub!</span>`;
            submitBtn.disabled = false;
            submitBtn.innerHTML = "Search for Captures";
            return false;
@@ -96,27 +96,27 @@ function finish(vid1) {
    fetch(`api/v4/youtube/${vid}?stream`)
        .then((response) => {
            if (response.status === 410 || response.status === 404) {
                dataDiv.innerHTML = `<span style="color: red;">API version is not supported - this should never happen, please report this</span>`;
                dataDiv.innerHTML = `<span style="color: red;">API version is not supported - this should never happen, please report this!</span>`;
                return null;
            }
            if (response.status === 500) {
                dataDiv.innerHTML = `<span style="color: red;">Internal server error - this is not your fault, please try again</span>`;
                dataDiv.innerHTML = `<span style="color: red;">Internal server error - this is not your fault, please try again.</span>`;
                return null;
            }
            if (response.status === 429) {
                dataDiv.innerHTML = `<span style="color: red;">You have been rate limited - please slow down</span>`;
                dataDiv.innerHTML = `<span style="color: red;">You have been rate limited - please slow down.</span>`;
                return null;
            }
            if (response.status === 502) {
                dataDiv.innerHTML = `<span style="color: red;">The server is currently down - please wait a minute and try again</span>`;
                dataDiv.innerHTML = `<span style="color: red;">The server is currently down - please wait a minute and try again.</span>`;
                return null;
            }
            if (response.status == 503) {
				dataDiv.innerHTML = `<span style="color: red;">The YouTube Video finder is currently unavailable. Please check back later. More information might be available by refreshing the page.</span>`
                dataDiv.innerHTML = `<span style="color: red;">The YouTube Video Finder is currently unavailable. Please check back later. More information might be available by refreshing the page.</span>`;
                return null;
            }
            if (response.status !== 200) {
                dataDiv.innerHTML = `<span style="color: red;">Received unknown status code ${response.status}</span>`;
                dataDiv.innerHTML = `<span style="color: red;">Received unknown status code ${response.status}</span>.`;
                return null;
            }
            return response.body.getReader();
@@ -196,7 +196,7 @@ function finish(vid1) {
                        return;
                    }
                    default: {
                        throw new Error("unexpected state")
                        throw new Error("unexpected state");
                    }
                }
            }
@@ -205,14 +205,14 @@ function finish(vid1) {
                    if (done) {
                        Object.values(elements).forEach((i) => {
                            if (i.getAttribute("data-status") == "loading") {
                                i.querySelector(".result").innerHTML = `<span class="white">Error</span><br />Did not receive a result from the server.`
                                i.querySelector(".result").innerHTML = `<span class="white">Error</span><br />Did not receive a result from the server.`;
                            }
                        })
                        });
                        return;
                    }
                    let text = new TextDecoder().decode(value);
                    for (const c of text) {
                        currentline += c
                        currentline += c;
                        if (c === "\n") {
                            processLine(currentline);
                            currentline = "";
@@ -256,7 +256,7 @@ function finishWrpa(data) {
    try {
        return finish(data);
    } catch (err) {
        console.error(err)
        console.error(err);
        dataDiv.innerHTML = "<span class='red'>An unknown error occured. Please report this. If possible, provide console output and a way of reproducing.</span>";
    }
}
+1 −1
Original line number Diff line number Diff line
@@ -61,7 +61,7 @@ button[disabled] {
}

.green {
    color: green;
    color: lime;
    background-color: black;
}

+12 −3
Original line number Diff line number Diff line
@@ -30,7 +30,8 @@
            <summary>How do I use this?</summary>
            <p>This is a website that will help you find a private or deleted YouTube video if you have the link.</p>
            <p><b>If you don't have the link, this site won't help you.</b></p>
            <p>Copy the link and paste it into the box above. Then click "Search for Captures".
            <p>
                Copy the link and paste it into the box above. Then click "Search for Captures".
                Some of the services this website queries are slow, so be patient.</p>
            <p>
                Once all the services have been queried, the results will appear. The results section
@@ -38,12 +39,20 @@
                A link to the archived material will be provided if there is one. If there isn't,
                there should be some extra text provided that sheds some light on how to retrieve it.
            </p>
            <p><b>Metadata</b> is information about the video. This might be the title, description, thumbnail, etc.
            <p>
                <b>Metadata</b> is information about the video. This might be the title, description, thumbnail, etc.
                Metadata can be useful for searching further. It's always possible there's a reupload
                of the video that this website simply didn't find, and knowing the title and description
                can be a big help in finding one.
            </p>
            <p>If you have any questions or need further help, contact me! I can be reached by email at
            <p>
                Tip: You can create a link to automatically check a specific video by setting the
                <code>q</code> URL parameter to a video ID or URL.
                If you pass in a URL, the site will shorten it to just the ID. <br />
                Try this one: <a href="{{ absolute_url }}">{{ absolute_url }}</a>.
            </p>
            <p>
                If you have any questions or need further help, contact me! I can be reached by email at
                thetechrobo@proton.me and on IRC with the username TheTechRobo (I'm on Libera.chat,
                hackint, and OFTC).
            </p>