Commit 991e8352 authored by Matthew Wright's avatar Matthew Wright
Browse files

replace innertube method with thumbnail method

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

methods:
  youtubei:
  youtube:
    title: YouTube
    enabled: true

@@ -28,9 +28,9 @@ methods:
    password:

  distributed_youtube_archive:
    title: "Distributed YouTube Archive"
    title: Distributed YouTube Archive
    enabled: false
    key: ""
    key:

  hobune_stream:
    title: Hobune.stream
+10 −11
Original line number Diff line number Diff line
@@ -2,30 +2,29 @@
All the Service implementations live here.
"""

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

youtubei = innertube.InnerTube("WEB")

class YouTubeI(YouTubeService):
class YouTube(YouTubeService):
    """
    Queries innertube to see if the video is still available on YouTube.
    Checks if the video is still available on YouTube.
    Thumbnail method has a few edge cases but seems the most reliable for all tested cases.
    """
    name = methods["youtubei"]["title"]
    configId = "youtubei"
    name = methods["youtube"]["title"]
    configId = "youtube"

    @classmethod
    async def _run(cls, id, session: aiohttp.ClientSession, includeRaw=True) -> T:
        data = youtubei.player(id)
        code = 200
        lien = f"https://i.ytimg.com/vi/{id}/hqdefault.jpg"
        async with session.head(lien, allow_redirects=False, timeout=15) as response:
            code = response.status

        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"])
        if code == 200:
            archived = True
        else:
            archived = False