Commit 0d00f06e authored by TheTechRobo's avatar TheTechRobo
Browse files

Many quality-of-life updates

- Move the list of used keys to an array sent in the JSON response,
    rather than inside the HTML template
- Allow entering a URL rather than a video ID
- Allow loading results by hitting Enter in addition to pressing the
  button
parent 6c62cb6f
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -13,7 +13,8 @@ async def find(id):
            "wbm": wbm(id),
            "ia": iai(id),
            "filmot": filmot(id),
            "ghostarchive": ghostget(id)
            "ghostarchive": ghostget(id),
            "keys": ["wbm", "ia", "ghostarchive", "ya", "filmot"]
    }

@app.route("/")
+42 −7
Original line number Diff line number Diff line
@@ -14,7 +14,7 @@
#data {
  position: absolute;
  left: 49%;
  top: 60%;
  top: 70%;
  -webkit-transform: translate(-50%, -50%);
  transform: translate(-50%, -50%);
}
@@ -52,7 +52,39 @@ button {
}
</style>
    <script>
      function finish(vid) {
      function coerceToVid(vid) {
        // Regexes here are based on the ones from https://github.com/mattwright324/youtube-metadata/blob/master/js/shared.js#L8-L14
        let 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 = vid.replace(pattern, function(match, newVid) {
            return newVid;
          });
          if (newVid.match(/^[A-Za-z0-9_-]{10}[AEIMQUYcgkosw048]$/)) {
            return newVid;
          }
        }
        return false;
      }
      function finish(vid1) {
        document.getElementById("int").innerHTML = ""
        var vid = vid1;
        if (!vid.match(/^[A-Za-z0-9_-]{10}[AEIMQUYcgkosw048]$/)) {
          let newVid = coerceToVid(vid);
          console.log(newVid);
          if (!newVid) {
            document.getElementById("data").innerHTML = `<span style="color:red;">That doesn't look like a valid video ID.</span>`;
            return false;
          }
          document.getElementById("int").innerHTML = `<br>Interpreting that URL as video ID ${newVid}`;
          document.getElementById("texting").value = vid1;
          vid = newVid;
        }
        let url = "{{ url_for('static', filename='ab79a231234507.564a1d23814ef.gif') }}";
        let src = "https://www.behance.net/gallery/31234507/Open-source-Loading-GIF-Icons-Vol-1/modules/199929391";
        document.getElementById("data").innerHTML = `<img src="${url}" width="25" height="25" /> Loading could take up to 30 seconds.`;
@@ -60,7 +92,7 @@ button {
          .then((response) => response.json())
          .then((data) => {
            let write = "<ul>";
            let keys = ["wbm", "ia", "ghostarchive", "ya", "filmot"]
            let keys = data.keys;
            keys.forEach((key) => {
              let wbm = data[key];
              let archived = wbm.archived ? "<span class='grn'>Archived</span>" : "<span class='red'>Not Archived</span>";
@@ -100,8 +132,11 @@ button {
  I am sorry for any inconvenience this causes you.
    </noscript>
    <div id="contenu">
      <form onsubmit="finishWrpa(document.getElementById('texting').value); return false;">
        <input type="text" id="texting" placeholder="Enter video ID here..."/>
      <button id="but" class="btn btn-primary" onclick="finishWrpa(document.getElementById('texting').value)">Search for Captures</button>
        <button action="submit" id="but" class="btn btn-primary">Search for Captures</button>
      </form>
      <span id="int"></span>
    </div>
    <div id="data">
      <i>website created by TheTechRobo</i>