private void ParseCompleted(Evereal.YoutubeDLPlayer.VideoInfo video) { Debug.Log("youtune title: " + video.title); Debug.Log("youtube url: " + video.url); SetVideo(video.url); }
private void Parse(string url) { if (!isPrepared) { Debug.LogWarningFormat(LOG_FORMAT, "Youtube-dl is not ready for parsing yet!"); return; } status = ProcessingStatus.PARSING; if (options == null) { // default to unity video player option options = UNITY_VIDEO_PLAYER_OPTIONS; } if (Application.platform == RuntimePlatform.Android) { #region ANDROID PARSE SECTION if (AndroidJNI.AttachCurrentThread() != 0) { EnqueueError(new ErrorEvent(ErrorCode.ANDROID_PLUGIN_ERROR, "Android attach current thread failed!")); return; } string output = androidPluginInstance.Call <string>("getVideoInfo", url, options); VideoInfo info = JsonUtility.FromJson <VideoInfo>(output); if (!string.IsNullOrEmpty(info.error)) { EnqueueError(new ErrorEvent(ErrorCode.PARSE_FAILED, info.error)); return; } lock (this) parseCompletedQueue.Enqueue(info); // done status = ProcessingStatus.READY; AndroidJNI.DetachCurrentThread(); #endregion } else { #region STANDALONE & EDITOR PARSE SECTION // parse video url try { string arguments = string.Format(" {0} --no-warnings --dump-json {1}", options, url); Process process = new Process(); process.StartInfo.FileName = Path.ytdlPath; process.StartInfo.Arguments = arguments; process.StartInfo.RedirectStandardOutput = true; process.StartInfo.RedirectStandardError = true; process.StartInfo.CreateNoWindow = true; process.StartInfo.UseShellExecute = false; process.Start(); string output = process.StandardOutput.ReadToEnd().Trim(); string error = process.StandardError.ReadToEnd().Trim(); process.WaitForExit(); process.Close(); if (!string.IsNullOrEmpty(error)) { EnqueueError(new ErrorEvent(ErrorCode.PARSE_FAILED, error)); return; } Debug.LogFormat(LOG_FORMAT, "Success getting video resources!"); VideoInfo info = JsonUtility.FromJson <VideoInfo>(output); lock (this) parseCompletedQueue.Enqueue(info); } catch (Exception e) { EnqueueError(new ErrorEvent(ErrorCode.PARSE_EXCEPTION, e.Message)); return; } // done status = ProcessingStatus.READY; #endregion } }