Update code

This commit is contained in:
larsenv 2022-04-07 16:36:49 -05:00
commit bbb397b1d2
No known key found for this signature in database
GPG key ID: A392A43695F3A8AD
5 changed files with 117 additions and 9 deletions

View file

@ -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.
3. Uses yt-dlp to download video file, and proxies that to the Wii.

View file

@ -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)

49
video/wii/index_old.cgi Normal file
View file

@ -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)

View file

@ -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

26
wiimc/vimeo/index.cgi Normal file
View file

@ -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