Commit 15a9e6b4 authored by Matthew Wright's avatar Matthew Wright
Browse files

add innertube to check if video still up on youtube

parent f1a6ff59
Loading
Loading
Loading
Loading
+2 −1
Original line number Diff line number Diff line
@@ -7,3 +7,4 @@ cachetools
click
asyncache
pyyaml
innertube
 No newline at end of file
+4 −0
Original line number Diff line number Diff line
version: 3

methods:
  youtubei:
    title: YouTube
    enabled: true

  ia_wayback:
    title: Wayback Machine
    enabled: true
+33 −1
Original line number Diff line number Diff line
@@ -2,10 +2,42 @@
All the Service implementations live here.
"""

import random, time, urllib.parse, aiohttp, asyncio
import random, time, urllib.parse, aiohttp, asyncio, requests, json, innertube
from switch import Switch
from .types import YouTubeService, T, methods

youtubei = innertube.InnerTube("WEB")

class YouTubeI(YouTubeService):
    """
    Queries innertube to see if the video is still available on YouTube.
    """
    name = methods["youtubei"]["title"]
    configId = "youtubei"

    @classmethod
    async def _run(cls, id, session: aiohttp.ClientSession, includeRaw=True) -> T:
        data = youtubei.player(id)
        code = 200

        rawraw = code if includeRaw else None
        archived = None
        link = f"https://youtu.be/{id}"

        if "playabilityStatus" in data and data["playabilityStatus"]["status"] == "OK":
            print(data["playabilityStatus"]["status"])
            archived = True
        else:
            archived = False

        capcount = int(archived)
        available = link if archived else None
        lastupdated = time.time()
        return cls(
            archived=archived, available=available, capcount=capcount, lastupdated=lastupdated, name=cls.getName(), note="", rawraw=rawraw,
            metaonly=False, comments=False
        )

class WaybackMachine(YouTubeService):
    """
    Queries the Wayback Machine for the video you requested.
+1 −1
Original line number Diff line number Diff line
@@ -78,7 +78,7 @@ function finish(vid1) {
                } else {
                    colour = "red";
                }
                var isarchived = wbm.archived ? "Archived" : "Not Archived";
                var isarchived = wbm.archived ? "Available" : "Not Available";
                if (wbm.error !== null) {
                    isarchived = "Unknown";
                    wbm.note = wbm.note + wbm.error;