internal static DownloadDetail GetDownloadDetails(MovieInfo movie, Trailer trailer, Dictionary <string, string> downloadOptions) { var downloadDetails = new DownloadDetail(); // get preferred quality for download var qualityOptions = GetPreferredQualityOption(downloadOptions, PluginSettings.AutoDownloadQuality); if (qualityOptions.Key == null) { return(null); } // set source url for download downloadDetails.SourceUrl = qualityOptions.Key; // create local filename for download string folder = string.Format("{0} ({1}) [{2}]", movie.Title, movie.Year ?? string.Empty, movie.IMDbID ?? string.Empty); string directory = Path.Combine(PluginSettings.AutoDownloadDirectory, folder.ToCleanFileName()); string filename = string.Format("{0}{1} [{2}]{3}.mp4", trailer.Name.ReplaceMultiSpaceWithSingleWhiteSpace(), trailer.Name.Contains(trailer.Type) ? string.Empty : " " + trailer.Type, qualityOptions.Value, PluginSettings.PreferredLanguage != "en" ? " [" + trailer.Language + "]" : string.Empty); downloadDetails.DestinationFilename = string.Format(@"{0}\{1}", directory, filename.ToCleanFileName()); return(downloadDetails); }
IEnumerator Start() { DownloadDetail currentLoad = null; HttpDownLoad httpDownLoad = new HttpDownLoad(); while (true) { if (currentLoad != null) { if (currentLoad.url.StartsWith("https")) { ///请求https不会返回下载的总大小(在gitee上测试的) ///因此不返回下载进度 if (currentLoad.downloadingCallback != null) { currentLoad.downloadingCallback(1); } UnityWebRequest unityWebRequest = new UnityWebRequest(currentLoad.url) { downloadHandler = new DownloadHandlerBuffer() }; yield return(unityWebRequest.Send()); if (currentLoad.downloadingCallback != null) { currentLoad.downloadingCallback(1); } System.IO.File.WriteAllBytes(string.Format("{0}/{1}", currentLoad.savePath, currentLoad.fileName), unityWebRequest.downloadHandler.data); unityWebRequest.downloadHandler.Dispose(); if (currentLoad.callback != null) { currentLoad.callback(); } currentLoad = null; } else { httpDownLoad.DownLoad(currentLoad.url, currentLoad.savePath, currentLoad.fileName, currentLoad.callback); while (!httpDownLoad.isDone) { if (currentLoad.downloadingCallback != null) { currentLoad.downloadingCallback(httpDownLoad.progress); } yield return(GameData.EndOfFrame); } if (currentLoad.callback != null) { currentLoad.callback(); } currentLoad = null; } } else { lock (lockObject) { if (_downList.Count > 0) { currentLoad = _downList[0]; _downList.RemoveAt(0); } } } yield return(GameData.EndOfFrame); } }