diff --git a/README.md b/README.md index fc95ac7..8b74fbd 100644 --- a/README.md +++ b/README.md @@ -3,8 +3,6 @@ A way to watch YouTube on your Wii with WiiMC. The code is extremely simple. All it does is: -1. Use Inviduous API to search for videos, or browse trending or popular videos (probably tech-related because that's what Inviduous tends to grab). +1. For YouTube, uses Inviduous API to search for videos, or browse trending or popular videos (probably tech-related because that's what Inviduous tends to grab). Or uses the Vimeo or Dailymotion API. 2. Returns a playlist file in WiiMC format. -3. Uses the pytube Python module to determine the exact URL of the video file, and proxies that to the Wii. - -It's very simple, and I haven't seen any stuttering of the video or anything like that. \ No newline at end of file +3. Uses yt-dlp to download video file, and proxies that to the Wii. \ No newline at end of file diff --git a/video/wii/index.cgi b/video/wii/index.cgi index fd0e738..c219755 100644 --- a/video/wii/index.cgi +++ b/video/wii/index.cgi @@ -1,19 +1,32 @@ #!/usr/bin/env python3 -from sys import stdout from cgi import FieldStorage from pytube import YouTube +from sys import stdout +import io import requests -import json +import subprocess form = FieldStorage() -url = YouTube("https://www.youtube.com/watch?v=" + form["q"].value).streams.get_lowest_resolution().url +video_url = "https://youtube.com/watch?v=" + form["q"].value + +try: + if form["site"].value == "vimeo": + video_url = "https://vimeo.com/" + form["q"].value + elif form["site"].value == "dailymotion": + video_url = "https://dailymotion.com/video/" + form["q"].value +except: + pass stdout.buffer.write(b"Content-Type:application/octet-stream\n\n") stdout.flush() -r = requests.get(url, stream=True) +if "youtube" in video_url or "vimeo" in video_url: + proc = subprocess.Popen(["yt-dlp", "-f", "[width<=640]", video_url, "-o", "-"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) -for chunk in r.iter_content(chunk_size=2048): +elif "dailymotion" in video_url: + proc = subprocess.Popen(["yt-dlp", "-f", "[tbr<=850]", video_url, "-o", "-"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + +for chunk in iter(proc.stdout): stdout.flush() stdout.buffer.write(chunk) diff --git a/video/wii/index_old.cgi b/video/wii/index_old.cgi new file mode 100644 index 0000000..8126361 --- /dev/null +++ b/video/wii/index_old.cgi @@ -0,0 +1,49 @@ +#!/usr/bin/env python3 +from cgi import FieldStorage +from pytube import YouTube +from sys import stdout +import io +import requests +import subprocess + +form = FieldStorage() + +video_url = "https://youtube.com/watch?v=" + form["q"].value + +try: + if form["site"].value == "vimeo": + video_url = "https://vimeo.com/" + form["q"].value + elif form["site"].value == "dailymotion": + video_url = "https://dailymotion.com/video/" + form["q"].value +except: + pass + +stdout.buffer.write(b"Content-Type:application/octet-stream\n\n") +stdout.flush() + +if "youtube" in video_url: + url = YouTube("https://www.youtube.com/watch?v=" + form["q"].value).streams.get_lowest_resolution().url + + r = requests.get(url, stream=True) + + for chunk in r.iter_content(chunk_size=2048): + stdout.flush() + stdout.buffer.write(chunk) + +else: + if "vimeo" in video_url: + protocol = "https" + + elif "dailymotion" in video_url: + protocol = "http" + + proc = subprocess.Popen(["yt-dlp", "-f", "[width<=640]", "-f", "[protocol=" + protocol + "]", video_url, "-o", "-"], stdout=subprocess.PIPE, stderr=subprocess.PIPE) + + """for line in io.TextIOWrapper(proc.stderr, encoding="utf-8"): + if "Invoking downloader" in line: + url = line.replace("[debug] Invoking downloader on ", "")[1:-2] + break""" + + for chunk in iter(proc.stdout): + stdout.flush() + stdout.buffer.write(chunk) diff --git a/wiimc/dailymotion/index.cgi b/wiimc/dailymotion/index.cgi new file mode 100644 index 0000000..95381c0 --- /dev/null +++ b/wiimc/dailymotion/index.cgi @@ -0,0 +1,22 @@ +#!/usr/bin/env python3 +from cgi import FieldStorage +import dailymotion + +form = FieldStorage() + +d = dailymotion.Dailymotion() + +api = d.get('/videos', params={"search": form["q"].value, "limit": 50})["list"] + +print("Content-Type: text/plain;charset=UTF-8;\n"); + +print("[Playlist]") + +i = 1 + +for entry in api: + print("File" + str(i) + "=" + "http://riitube.rc24.xyz/video/wii/?q=" + entry["id"] + "&site=dailymotion".replace("https://dailymotion.com/", "")) + print("Title" + str(i) + "=" + entry["title"]) + print("Length" + str(i) + "=" + str(0)) + + i += 1 diff --git a/wiimc/vimeo/index.cgi b/wiimc/vimeo/index.cgi new file mode 100644 index 0000000..74cf479 --- /dev/null +++ b/wiimc/vimeo/index.cgi @@ -0,0 +1,26 @@ +#!/usr/bin/env python3 +from cgi import FieldStorage +import vimeo + +v = vimeo.VimeoClient( + token="redacted", + key="redacted", + secret="redacted" +) + +form = FieldStorage() + +api = v.get('/videos', params={"query": form["q"].value, "per_page": 50}).json()["data"] + +print("Content-Type: text/plain;charset=UTF-8;\n"); + +print("[Playlist]") + +i = 1 + +for entry in api: + print("File" + str(i) + "=" + "http://riitube.rc24.xyz/video/wii/?q=" + entry["link"].replace("https://vimeo.com/", "") + "&site=vimeo") + print("Title" + str(i) + "=" + entry["name"]) + print("Length" + str(i) + "=" + str(entry["duration"])) + + i += 1