Commit 3c8eef0d authored by TheTechRobo's avatar TheTechRobo
Browse files

Add API docs

parent cf049fa5
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -5,6 +5,23 @@ from findmedia import *

app = Flask(__name__)

try:
    config.ccen
except NameError:
    config.ccen = False
    config.ccod = "a"

#@app.route(f"/cc/{config.ccod}")
async def cc():
    global GCACHE, FILCACHE, YACACHE, WBMCACHE, IACACHE
    GCACHE = {}
    FILCACHE = {}
    YACACHE = {}
    WBMCACHE = {}
    IACACHE = {}
    abort(404)


@app.route("/find/<id>")
async def find(id):
    if not re.match(r"^[A-Za-z0-9_-]{10}[AEIMQUYcgkosw048]$", id):
@@ -25,6 +42,10 @@ async def find(id):
async def ui():
    return render_template("init.html")

@app.route("/api")
async def api():
    return render_template("api.html", fields={"id": "The interpreted video ID.", "status": "bad.id if invalid ID.", "keys": "Array of all the service keys."}, services={"archived": "Whether the video is archived or not.", "available": "A link to the archived material if it can be produced; False otherwise.", "capcount": "The number of captures; on everything except #youtubearchive, it is 1 if archived, 0 if not. In the case of #youtubearchive, it is the count reported by the server.", "lastupdated": "The timestamp the data was retrieved from the server. Used internally to expire cache entries.", "name": "The name of the service. Used in the UI.", "note": "A footnote about the service. This could be different depending on conditions. For example, the Internet Archive has an extra passage if the item is dark.", "rawraw": "The data used to check whether the video is archived on that particular service. For example, for GhostArchive, it would be the HTTP status code.", "suppl": "Supplemental error message. Not used and currently inconsistent with what it returns and when."})

@app.route("/nojs")
async def formsubmit():
    vid = request.args.get("vid") or abort(400)
+1 −0
Original line number Diff line number Diff line
@@ -5,3 +5,4 @@ class ya:

class filmot:
    key = "fill this in"
+1 −1
Original line number Diff line number Diff line
@@ -32,7 +32,7 @@ def filmot(vid):
    FILAST = time.time()
    data = res.json()
    archived = bool(data)
    ret = {"archived": archived, "suppl": None, "rawraw": res.text, "lastupdated": time.time(), "note": FILNOTE, "name": FILNAME, "available": False}
    ret = {"capcount": 1 if archived else 0, "archived": archived, "suppl": None, "rawraw": res.text, "lastupdated": time.time(), "note": FILNOTE, "name": FILNAME, "available": False}
    FILCACHE[vid] = ret
    return ret

templates/api.html

0 → 100644
+34 −0
Original line number Diff line number Diff line
<!DOCTYPE html>
<html>
  <head>
<style>
body {
  font-family: Ubuntu, Arial, sans-serif;
}
</style>
  </head>
  <body>
    <h1>API Documentation</h1>
    <h3>Call: GET <code>/find/$videoid</code></h3>
    <p>
    <b>Fields</b>
    <br>
    <dl>
      {% for field, value in fields.items() %}
        <dt><code>
            {{ field }}
        </code></dt>
        <dd>{{value}}
        </dd>
      {% endfor %}
    </dl>
    <b>Service Keys</b>
    <p>One object for every service searched.</p>
    <dl>
      {% for field, value in services.items() %}
        <dt><code>{{field}}</code></dt>
        <dd>{{value}}</dd>
      {%endfor%}
    </dl>
  </body>
</html>