private async Task <string> CreateUrl(DownloadOption option) { if (JSRuntime is IJSUnmarshalledRuntime webAssemblyJsRuntime) { return(webAssemblyJsRuntime.InvokeUnmarshalled <string?, string, byte[], string>("$.bb_create_url_wasm", option.FileName, option.Mime, option.FileContent)); } else { return(await JSRuntime.InvokeAsync <string>(identifier : "$.bb_create_url", option.FileName, option.Mime, option.FileContent)); } }
private async Task DownloadFile(DownloadOption option) { if (JSRuntime is IJSUnmarshalledRuntime webAssemblyJsRuntime) { webAssemblyJsRuntime.InvokeUnmarshalled <string?, string, byte[], bool>("$.bb_download_wasm", option.FileName, option.Mime, option.FileContent); } else { await JSRuntime.InvokeVoidAsync(identifier : "$.bb_download", option.FileName, option.Mime, option.FileContent); } }
private void DownloadNowMenuItem_OnClick(object sender, RoutedEventArgs e) { DownloadOption option = null; if (BrowsingUser() && IsAtUploadCheckerPosition()) { option = new DownloadOption { CreateNewWhenFromUser = Settings.Global.CreateNewFolderWhenDownloadFromUser }; } DownloadManager.EnqueueDownloadItem(sender.GetDataContext <Illustration>(), option); MessageQueue.Enqueue(AkaI18N.QueuedDownload); }
private void SearchBox_VideoSelected(string title, object id, string type) { DownloadOption downloadOption = ShowDownloadOption(); switch (type) { case "aid": downloadOption.ShowParts(title, (uint)(long)id, false); break; case "bvid": downloadOption.ShowPartsBv(title, (string)id); break; } }
public async Task DownloadVideoAsync(DownloadOption downloadOption, string filePath, IProgress <double> progress, CancellationToken cancellationToken) { await EnsureThrottlingAsync(cancellationToken); try { await _youtubeConverter.DownloadAndProcessMediaStreamsAsync(downloadOption.StreamInfos, filePath, downloadOption.Format, ConversionPreset.Medium, progress, cancellationToken); } finally { Interlocked.Decrement(ref _concurrentDownloadCount); } }
public async Task <IReadOnlyList <DownloadOption> > GetDownloadOptionsAsync(string videoId) { var options = new Dictionary <string, DownloadOption>(StringComparer.OrdinalIgnoreCase); var streamManifest = await _youtube.Videos.Streams.GetManifestAsync(videoId); // Audio doar var bestAudioOnlyStreamInfo = streamManifest .GetAudio() .OrderByDescending(s => s.Container == Container.WebM) .ThenByDescending(s => s.Bitrate) .FirstOrDefault(); // Video+Autio var videoStreams = streamManifest .GetVideo() .GroupBy(v => v.VideoQualityLabel, StringComparer.OrdinalIgnoreCase) .Select(g => g.OrderByDescending(v => v.Framerate).First()) .OrderByDescending(v => v.VideoQuality) .ThenByDescending(v => v.Framerate); foreach (var streamInfo in videoStreams) { var format = streamInfo.Container.Name; var label = streamInfo.VideoQualityLabel; // Video doar if (streamInfo is VideoOnlyStreamInfo && bestAudioOnlyStreamInfo != null) { options[label] = new DownloadOption(format, label, streamInfo, bestAudioOnlyStreamInfo); } else { options[label] = new DownloadOption(format, label, streamInfo); } } // Format if (bestAudioOnlyStreamInfo != null) { options["audio/mp3"] = new DownloadOption("mp3", "Audio", bestAudioOnlyStreamInfo); options["audio/ogg"] = new DownloadOption("ogg", "Audio", bestAudioOnlyStreamInfo); } return(options.Values.ToArray()); }
public static async Task<StorageFile> DownloadAsync(string version, DownloadOption option = DownloadOption.Default) { if (!MinecraftAPI.IsInitialized) { Debug.WriteLine($"MinecraftService is not initialized. Proceeds to initialize it."); await InitializeAsync(); } if (!MinecraftAPI.Contains(version)) { Debug.WriteLine($"Version {version} does not exist in available links."); return null; } if (await ContainsZip(version)) { Debug.WriteLine($"Version {version} is already downloaded. No further steps required."); return null; } var uri = new Uri(MinecraftAPI.Get(version)?.Downloads.Client?.Url); var root = await GetOrCreateRootFolderAsync(); var file = await root?.CreateFileAsync(version + ".zip", CreationCollisionOption.ReplaceExisting); try { BackgroundDownloader downloader = new BackgroundDownloader(); DownloadOperation download = downloader?.CreateDownload(uri, file); Debug.WriteLine($"Downloading: {uri?.AbsolutePath}..."); await download.StartAsync(); Debug.WriteLine($"...Download completed: {uri?.AbsolutePath}"); } catch (Exception e) { Debug.WriteLine($"Error when downloading {uri.AbsolutePath}:\n{e.Message}"); return null; } await CreateResourceListAsync(version); if (option == DownloadOption.ExtractFiles) await Extract(version); return file; }
public async Task DownloadVideoAsync(string videoId, string filePath, DownloadOption downloadOption, IProgress <double> progress, CancellationToken cancellationToken) { // Ensure throttling and increment concurrent download count await EnsureThrottlingAsync(cancellationToken); try { // Download the video await _youtubeConverter.DownloadAndProcessMediaStreamsAsync(downloadOption.MediaStreamInfos, filePath, downloadOption.Format, progress, cancellationToken); } finally { // Decrement concurrent download count Interlocked.Decrement(ref _concurrentDownloadCount); } }
/// <summary> /// 下载文件 /// </summary> /// <param name="filePath">文件路径</param> /// <param name="option">下载方式</param> public static void Download(string filePath, DownloadOption option = DownloadOption.Narmol) { switch (option) { case DownloadOption.Narmol: DownloadByNormal(filePath); break; case DownloadOption.Chunk: DownloadByChunk(filePath); break; case DownloadOption.Stream: DownloadByStream(filePath); break; default: DownloadByNormal(filePath); break; } }
public async Task DownloadVideoAsync(DownloadOption downloadOption, string filePath, IProgress <double> progress, CancellationToken cancellationToken) { await EnsureThrottlingAsync(cancellationToken); try { var conversion = new ConversionRequestBuilder(filePath) .SetFormat(downloadOption.Format) .SetPreset(ConversionPreset.Medium) .Build(); await _youtube.Videos.DownloadAsync( downloadOption.StreamInfos, conversion, progress, cancellationToken ); } finally { Interlocked.Decrement(ref _concurrentDownloadCount); } }
public static DownloadViewModel CreateDownloadViewModel(this IViewModelFactory factory, Video video, string filePath, string format, DownloadOption downloadOption = null) { var viewModel = factory.CreateDownloadViewModel(); viewModel.Video = video; viewModel.FilePath = filePath; viewModel.Format = format; viewModel.DownloadOption = downloadOption; return(viewModel); }
public void OnViewLoaded() { SelectedDownloadOption = AvailableDownloadOptions.FirstOrDefault(o => o.Format == _settingsService.LastFormat) ?? AvailableDownloadOptions.OrderByDescending(o => !string.IsNullOrWhiteSpace(o.Label)).FirstOrDefault(); }
private void SearchBox_SeasonSelected(string title, long id) { DownloadOption downloadOption = ShowDownloadOption(); downloadOption.ShowParts(title, (uint)id, true); }
private void FavList_VideoSelected(string title, long id) { DownloadOption downloadOption = ShowDownloadOption(); downloadOption.ShowParts(title, (uint)id, false); }
private void SearchBox_SeasonSelected(string title, object id, string type) { DownloadOption downloadOption = ShowDownloadOption(); downloadOption.ShowParts(title, (uint)(long)id, true); }
/// <summary>Download subtitle for the selected file.</summary> /// <param name="option">The download option.</param> private void DownloadSubtitle(DownloadOption option) { var currentPath = Path.GetDirectoryName(Assembly.GetExecutingAssembly().Location) ?? string.Empty; currentPath = Path.GetFullPath(currentPath); var executable = Path.GetFullPath(Path.Combine(currentPath, "SubSearch.App.exe")); if (!File.Exists(executable)) { MessageBox.Show( "SubSearch application was not properly installed. Please try restarting the computer and reinstall SubSearch!", "Corrupted Installation", MessageBoxButton.OK, MessageBoxImage.Error); return; } var queuePath = Path.Combine(currentPath, "Queue"); Directory.CreateDirectory(queuePath); var newQueue = Path.Combine(queuePath, Guid.NewGuid().ToString()); using (var queueFile = File.CreateText(newQueue)) { queueFile.WriteLine(option.Language); queueFile.WriteLine(option.IsLuckyMode ? Constants.SilentModeIdentifier : Constants.NormalModeIdentifier); foreach (var selectedFile in this.SelectedItemPaths) { queueFile.WriteLine(selectedFile); } } Process.Start(executable, newQueue); }
public static async Task DownloadLatestAsync(DownloadOption option = DownloadOption.Default) { await DownloadAsync(MinecraftAPI.LatestRelease.Id, option); }
public static async Task DownloadAllAsync(DownloadOption option = DownloadOption.Default) { foreach (Minecraft.Version version in MinecraftAPI.Versions) await DownloadAsync(version.Id, option); }
/// <summary>Get menu item.</summary> /// <param name="isLuckyMode">Is lucky mode.</param> /// <returns>Menu item.</returns> private ToolStripMenuItem GetLanguageItems(bool isLuckyMode) { var option = new DownloadOption { Language = SupportedLanguage.FirstOrDefault(), IsLuckyMode = isLuckyMode }; var topMenu = new ToolStripMenuItem { Text = isLuckyMode ? Literals.ShellExtension_CreateMenu_Download_subtitle_lucky : Literals.ShellExtension_CreateMenu_Download_subtitle, Image = isLuckyMode ? Icons.SubSearchLucky : Icons.SubSearch, Tag = option }; topMenu.Click += (sender, args) => this.DownloadSubtitle(option); foreach (var language in SupportedLanguage) { var subOption = new DownloadOption { Language = language, IsLuckyMode = isLuckyMode }; var newLanguageItem = new ToolStripMenuItem { Text = language.ToString(), Image = GetLanguageIcon(language.ToString()), Tag = subOption }; newLanguageItem.Click += (sender, args) => this.DownloadSubtitle(subOption); topMenu.DropDownItems.Add(newLanguageItem); } return topMenu; }