Skip to content

Commit 677d7ed

Browse files
committed
Fix YTDL shim to use YT-DLP
VRC is now using YT-DLP instead of YT-DL because YT-DL's maintainers went missing. So the paths need to be updated for the exe. Added fallback handling for YTDL just in case VRC ever ends up switching back to YTDL.
1 parent f149c4d commit 677d7ed

File tree

1 file changed

+25
-24
lines changed

1 file changed

+25
-24
lines changed

Assets/USharpVideo/Scripts/Editor/EditorURLResolverShim.cs

Lines changed: 25 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -18,21 +18,24 @@ namespace UdonSharp.Video.Internal
1818
/// </summary>
1919
public static class EditorURLResolverShim
2020
{
21-
static string youtubeDLPath = "";
22-
static HashSet<System.Diagnostics.Process> runningYTDLProcesses = new HashSet<System.Diagnostics.Process>();
23-
static HashSet<MonoBehaviour> registeredBehaviours = new HashSet<MonoBehaviour>();
24-
static DateTime lastRequestTime = DateTime.MinValue;
25-
21+
private static string _youtubeDLPath = "";
22+
private static HashSet<System.Diagnostics.Process> _runningYtdlProcesses = new HashSet<System.Diagnostics.Process>();
23+
private static HashSet<MonoBehaviour> _registeredBehaviours = new HashSet<MonoBehaviour>();
24+
2625
[RuntimeInitializeOnLoadMethod(RuntimeInitializeLoadType.AfterSceneLoad)]
27-
static void SetupURLResolveCallback()
26+
private static void SetupURLResolveCallback()
2827
{
2928
string[] splitPath = Application.persistentDataPath.Split('/', '\\');
30-
youtubeDLPath = string.Join("\\", splitPath.Take(splitPath.Length - 2)) + "\\VRChat\\VRChat\\Tools\\youtube-dl.exe";
31-
//youtubeDLPath = "D:/Merlin/Desktop/youtube-dl.exe";
29+
_youtubeDLPath = string.Join("\\", splitPath.Take(splitPath.Length - 2)) + "\\VRChat\\VRChat\\Tools\\yt-dlp.exe";
30+
31+
if (!File.Exists(_youtubeDLPath))
32+
{
33+
_youtubeDLPath = string.Join("\\", splitPath.Take(splitPath.Length - 2)) + "\\VRChat\\VRChat\\Tools\\youtube-dl.exe";
34+
}
3235

33-
if (!File.Exists(youtubeDLPath))
36+
if (!File.Exists(_youtubeDLPath))
3437
{
35-
Debug.LogWarning("[USharpVideo YTDL] Unable to find VRC YouTube-dl installation, URLs will not be resolved.");
38+
Debug.LogWarning("[USharpVideo YTDL] Unable to find VRC YouTube-DL or YT-DLP installation, URLs will not be resolved in editor test your videos in game.");
3639
return;
3740
}
3841

@@ -49,7 +52,7 @@ private static void PlayModeChanged(PlayModeStateChange change)
4952
{
5053
if (change == PlayModeStateChange.ExitingPlayMode)
5154
{
52-
foreach (var process in runningYTDLProcesses)
55+
foreach (var process in _runningYtdlProcesses)
5356
{
5457
if (!process.HasExited)
5558
{
@@ -58,17 +61,17 @@ private static void PlayModeChanged(PlayModeStateChange change)
5861
}
5962
}
6063

61-
runningYTDLProcesses.Clear();
64+
_runningYtdlProcesses.Clear();
6265

6366
// Apparently the URLResolveCoroutine will run after this method in some cases magically. So don't because the process will throw an exception.
64-
foreach (MonoBehaviour behaviour in registeredBehaviours)
67+
foreach (MonoBehaviour behaviour in _registeredBehaviours)
6568
behaviour.StopAllCoroutines();
6669

67-
registeredBehaviours.Clear();
70+
_registeredBehaviours.Clear();
6871
}
6972
}
7073

71-
static void ResolveURLCallback(VRCUrl url, int resolution, UnityEngine.Object videoPlayer, Action<string> urlResolvedCallback, Action<VideoError> errorCallback)
74+
private static void ResolveURLCallback(VRCUrl url, int resolution, UnityEngine.Object videoPlayer, Action<string> urlResolvedCallback, Action<VideoError> errorCallback)
7275
{
7376
// Broken for some unknown reason, when multiple rate limits fire off, only fires the first callback.
7477
//if ((System.DateTime.UtcNow - lastRequestTime).TotalSeconds < 5.0)
@@ -77,34 +80,32 @@ static void ResolveURLCallback(VRCUrl url, int resolution, UnityEngine.Object vi
7780
// errorCallback(VideoError.RateLimited);
7881
// return;
7982
//}
80-
81-
lastRequestTime = System.DateTime.UtcNow;
82-
83-
System.Diagnostics.Process ytdlProcess = new System.Diagnostics.Process();
83+
84+
var ytdlProcess = new System.Diagnostics.Process();
8485

8586
ytdlProcess.StartInfo.WindowStyle = System.Diagnostics.ProcessWindowStyle.Hidden;
8687
ytdlProcess.StartInfo.CreateNoWindow = true;
8788
ytdlProcess.StartInfo.UseShellExecute = false;
8889
ytdlProcess.StartInfo.RedirectStandardOutput = true;
89-
ytdlProcess.StartInfo.FileName = youtubeDLPath;
90+
ytdlProcess.StartInfo.FileName = _youtubeDLPath;
9091
ytdlProcess.StartInfo.Arguments = $"--no-check-certificate --no-cache-dir --rm-cache-dir -f \"mp4[height<=?{resolution}]/best[height<=?{resolution}]\" --get-url \"{url}\"";
9192

9293
Debug.Log($"[<color=#9C6994>USharpVideo YTDL</color>] Attempting to resolve URL '{url}'");
9394

9495
ytdlProcess.Start();
95-
runningYTDLProcesses.Add(ytdlProcess);
96+
_runningYtdlProcesses.Add(ytdlProcess);
9697

9798
((MonoBehaviour)videoPlayer).StartCoroutine(URLResolveCoroutine(url.ToString(), ytdlProcess, videoPlayer, urlResolvedCallback, errorCallback));
9899

99-
registeredBehaviours.Add((MonoBehaviour)videoPlayer);
100+
_registeredBehaviours.Add((MonoBehaviour)videoPlayer);
100101
}
101102

102-
static IEnumerator URLResolveCoroutine(string originalUrl, System.Diagnostics.Process ytdlProcess, UnityEngine.Object videoPlayer, Action<string> urlResolvedCallback, Action<VideoError> errorCallback)
103+
private static IEnumerator URLResolveCoroutine(string originalUrl, System.Diagnostics.Process ytdlProcess, UnityEngine.Object videoPlayer, Action<string> urlResolvedCallback, Action<VideoError> errorCallback)
103104
{
104105
while (!ytdlProcess.HasExited)
105106
yield return new WaitForSeconds(0.1f);
106107

107-
runningYTDLProcesses.Remove(ytdlProcess);
108+
_runningYtdlProcesses.Remove(ytdlProcess);
108109

109110
string resolvedURL = ytdlProcess.StandardOutput.ReadLine();
110111

0 commit comments

Comments
 (0)