├── icons ├── icon.ico └── youtube_8kc6k.png ├── YouTubeWindows ├── Resources │ ├── icon.ico │ ├── Staff.txt │ └── youtube_splash_screen.html ├── packages.config ├── App.config ├── Properties │ ├── Settings.settings │ ├── Settings.Designer.cs │ ├── AssemblyInfo.cs │ ├── Resources.Designer.cs │ └── Resources.resx ├── Program.cs ├── MainForm.Designer.cs ├── app.manifest ├── Resource.Designer.cs ├── MainForm.resx ├── YouTubeWindows.csproj ├── Resource.resx └── MainForm.cs ├── YouTubeWindows.sln ├── README.md └── .gitignore /icons/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGSAN/YouTubeWindows/HEAD/icons/icon.ico -------------------------------------------------------------------------------- /icons/youtube_8kc6k.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGSAN/YouTubeWindows/HEAD/icons/youtube_8kc6k.png -------------------------------------------------------------------------------- /YouTubeWindows/Resources/icon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/TGSAN/YouTubeWindows/HEAD/YouTubeWindows/Resources/icon.ico -------------------------------------------------------------------------------- /YouTubeWindows/packages.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | -------------------------------------------------------------------------------- /YouTubeWindows/App.config: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | -------------------------------------------------------------------------------- /YouTubeWindows/Resources/Staff.txt: -------------------------------------------------------------------------------- 1 | YouTube Leanback for Windows <--%PROGRAM_VERSION%--> 2 | By TGSAN 3 | 4 | Windows Cobalt on EBWebView2 5 | Microsoft Edge (Chromium) Runtime 6 | Version: <--%WEBVIEW_VERSION%--> 7 | 8 | YouTube 9 | 10 | YouTube 是 Google 的子公司 -------------------------------------------------------------------------------- /YouTubeWindows/Properties/Settings.settings: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | -------------------------------------------------------------------------------- /YouTubeWindows/Program.cs: -------------------------------------------------------------------------------- 1 | using System; 2 | using System.Collections.Generic; 3 | using System.Linq; 4 | using System.Threading.Tasks; 5 | using System.Windows.Forms; 6 | 7 | namespace YouTubeWindows 8 | { 9 | static class Program 10 | { 11 | /// 12 | /// 应用程序的主入口点。 13 | /// 14 | [STAThread] 15 | static void Main(string[] args) 16 | { 17 | Application.EnableVisualStyles(); 18 | Application.SetCompatibleTextRenderingDefault(false); 19 | Application.Run(new MainForm(args)); 20 | } 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /YouTubeWindows/Properties/Settings.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace YouTubeWindows.Properties { 12 | 13 | 14 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 15 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "17.7.0.0")] 16 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase { 17 | 18 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings()))); 19 | 20 | public static Settings Default { 21 | get { 22 | return defaultInstance; 23 | } 24 | } 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /YouTubeWindows/Properties/AssemblyInfo.cs: -------------------------------------------------------------------------------- 1 | using System.Reflection; 2 | using System.Runtime.CompilerServices; 3 | using System.Runtime.InteropServices; 4 | 5 | // 有关程序集的一般信息由以下 6 | // 控制。更改这些特性值可修改 7 | // 与程序集关联的信息。 8 | [assembly: AssemblyTitle("YouTube Leanback for Windows")] 9 | [assembly: AssemblyDescription("")] 10 | [assembly: AssemblyConfiguration("")] 11 | [assembly: AssemblyCompany("")] 12 | [assembly: AssemblyProduct("YouTube Leanback for Windows")] 13 | [assembly: AssemblyCopyright("Copyright © CloudMoe 2025")] 14 | [assembly: AssemblyTrademark("TGSAN")] 15 | [assembly: AssemblyCulture("")] 16 | 17 | // 将 ComVisible 设置为 false 会使此程序集中的类型 18 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型 19 | //请将此类型的 ComVisible 特性设置为 true。 20 | [assembly: ComVisible(false)] 21 | 22 | // 如果此项目向 COM 公开,则下列 GUID 用于类型库的 ID 23 | [assembly: Guid("cbe7ef20-1c8b-4593-9ab2-c0368aeff7b8")] 24 | 25 | // 程序集的版本信息由下列四个值组成: 26 | // 27 | // 主版本 28 | // 次版本 29 | // 生成号 30 | // 修订号 31 | // 32 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值 33 | //通过使用 "*",如下所示: 34 | // [assembly: AssemblyVersion("1.0.*")] 35 | [assembly: AssemblyVersion("1.2.3.0")] 36 | [assembly: AssemblyFileVersion("1.2.3.0")] 37 | -------------------------------------------------------------------------------- /YouTubeWindows.sln: -------------------------------------------------------------------------------- 1 | 2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 16 4 | VisualStudioVersion = 16.0.30907.101 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "YouTubeWindows", "YouTubeWindows\YouTubeWindows.csproj", "{CBE7EF20-1C8B-4593-9AB2-C0368AEFF7B8}" 7 | EndProject 8 | Global 9 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 10 | Debug|Any CPU = Debug|Any CPU 11 | Release|Any CPU = Release|Any CPU 12 | EndGlobalSection 13 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 14 | {CBE7EF20-1C8B-4593-9AB2-C0368AEFF7B8}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 15 | {CBE7EF20-1C8B-4593-9AB2-C0368AEFF7B8}.Debug|Any CPU.Build.0 = Debug|Any CPU 16 | {CBE7EF20-1C8B-4593-9AB2-C0368AEFF7B8}.Release|Any CPU.ActiveCfg = Release|Any CPU 17 | {CBE7EF20-1C8B-4593-9AB2-C0368AEFF7B8}.Release|Any CPU.Build.0 = Release|Any CPU 18 | EndGlobalSection 19 | GlobalSection(SolutionProperties) = preSolution 20 | HideSolutionNode = FALSE 21 | EndGlobalSection 22 | GlobalSection(ExtensibilityGlobals) = postSolution 23 | SolutionGuid = {D91928F1-003A-4B29-929C-829D4BC47FFA} 24 | EndGlobalSection 25 | EndGlobal 26 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # YouTube Leanback for Windows 2 | 3 | ## Requirements 4 | 5 | **Operating System** 6 | - Windows 7/8.1/10/11 7 | - Windows Server 2008 R2/2012 R2/2012/2016/2019/2022/2025 8 | 9 | **Processor** 10 | - x86/x64/arm64 11 | 12 | **Runtime** 13 | 1. Install WebView2 Runtime: [https://go.microsoft.com/fwlink/p/?LinkId=2124703](https://go.microsoft.com/fwlink/p/?LinkId=2124703) 14 | OR place the WebView2 Shared Runtime in the runtime directory (PlayReady DRM will not be available). 15 | 16 | 2. .NET 4.5.2 or later 17 | 18 | ## Control 19 | 20 | - `Mice Right Button` `Esc` - Back 21 | - `Mice Left Button` `Enter` - Confirm 22 | - `Arrow Keys` - Move Cursor 23 | - `F11` - Fullscreen 24 | - `F5` `Ctrl + R` - Reload App 25 | 26 | ## Advanced 27 | 28 | **Command Line Parameters** 29 | 30 | ``` 31 | --allow-auto-hdr Allows stretching SDR content to HDR (e.g., NVIDIA RTX HDR) 32 | --proxy-server="http://proxy-ip:proxy-port" Access via proxy 33 | --enable-features={Feature1,Feature2,...} Enable features such as Feature1, Feature2, etc. (Refer to Microsoft Edge documentation) 34 | ``` 35 | 36 | ## 要求 37 | 38 | **操作系统** 39 | 40 | Windows 7/8.1/10/11 41 | Windows Server 2008 R2/2012 R2/2012/2016/2019/2022 42 | 43 | **处理器** 44 | 45 | x86/x64/arm64 46 | 47 | **运行时** 48 | 49 | 1. 安装 WebView2 Runtime:https://go.microsoft.com/fwlink/p/?LinkId=2124703 50 | 或将 WebView2 Shared Runtime 放入 runtime 目录(PlayReady DRM 将不可用) 51 | 52 | 2. .Net 4.5.2+ 53 | 54 | ## 控制 55 | 56 | - `鼠标右键` `Esc` - 返回 57 | - `鼠标左键` `Enter` - 确认 58 | - `方向键` - 移动光标 59 | - `F11` - Fullscreen 60 | - `F5` `Ctrl + R` - Reload App 61 | 62 | ## 高级 63 | 64 | **命令行参数** 65 | 66 | ``` 67 | --allow-auto-hdr 允许将 SDR 内容拉伸到 HDR(比如 NVIDIA RTX HDR) 68 | --proxy-server="http://proxy-ip:proxy-port" 使用代理访问 69 | --enable-features={Feature1,Feature2,...} 使用Feature1,Feature2,...等特性(参考 Microsoft Edge 文档) 70 | ``` 71 | -------------------------------------------------------------------------------- /YouTubeWindows/MainForm.Designer.cs: -------------------------------------------------------------------------------- 1 | 2 | namespace YouTubeWindows 3 | { 4 | partial class MainForm 5 | { 6 | /// 7 | /// 必需的设计器变量。 8 | /// 9 | private System.ComponentModel.IContainer components = null; 10 | 11 | /// 12 | /// 清理所有正在使用的资源。 13 | /// 14 | /// 如果应释放托管资源,为 true;否则为 false。 15 | protected override void Dispose(bool disposing) 16 | { 17 | if (disposing && (components != null)) 18 | { 19 | components.Dispose(); 20 | } 21 | base.Dispose(disposing); 22 | } 23 | 24 | #region Windows 窗体设计器生成的代码 25 | 26 | /// 27 | /// 设计器支持所需的方法 - 不要修改 28 | /// 使用代码编辑器修改此方法的内容。 29 | /// 30 | private void InitializeComponent() 31 | { 32 | this.SuspendLayout(); 33 | // 34 | // MainForm 35 | // 36 | this.AutoScaleDimensions = new System.Drawing.SizeF(96F, 96F); 37 | this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Dpi; 38 | this.BackColor = System.Drawing.Color.FromArgb(((int)(((byte)(24)))), ((int)(((byte)(24)))), ((int)(((byte)(24))))); 39 | this.ClientSize = new System.Drawing.Size(1264, 711); 40 | this.Font = new System.Drawing.Font("微软雅黑", 9F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((byte)(134))); 41 | this.ForeColor = System.Drawing.Color.White; 42 | this.Margin = new System.Windows.Forms.Padding(3, 4, 3, 4); 43 | this.Name = "MainForm"; 44 | this.Text = "YouTube"; 45 | this.Activated += new System.EventHandler(this.MainForm_Activated); 46 | this.Load += new System.EventHandler(this.MainForm_Load); 47 | this.ResizeBegin += new System.EventHandler(this.MainForm_ResizeBegin); 48 | this.ResizeEnd += new System.EventHandler(this.MainForm_ResizeEnd); 49 | this.Resize += new System.EventHandler(this.MainForm_Resize); 50 | this.ResumeLayout(false); 51 | 52 | } 53 | 54 | #endregion 55 | } 56 | } 57 | 58 | -------------------------------------------------------------------------------- /YouTubeWindows/Properties/Resources.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace YouTubeWindows.Properties { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resources { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resources() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("YouTubeWindows.Properties.Resources", typeof(Resources).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /YouTubeWindows/app.manifest: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | 6 | 7 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 28 | 29 | 30 | 31 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 | 51 | 52 | 53 | 54 | true 55 | 56 | 57 | 58 | 59 | 60 | 74 | 75 | 76 | -------------------------------------------------------------------------------- /YouTubeWindows/Resource.Designer.cs: -------------------------------------------------------------------------------- 1 | //------------------------------------------------------------------------------ 2 | // 3 | // 此代码由工具生成。 4 | // 运行时版本:4.0.30319.42000 5 | // 6 | // 对此文件的更改可能会导致不正确的行为,并且如果 7 | // 重新生成代码,这些更改将会丢失。 8 | // 9 | //------------------------------------------------------------------------------ 10 | 11 | namespace YouTubeWindows { 12 | using System; 13 | 14 | 15 | /// 16 | /// 一个强类型的资源类,用于查找本地化的字符串等。 17 | /// 18 | // 此类是由 StronglyTypedResourceBuilder 19 | // 类通过类似于 ResGen 或 Visual Studio 的工具自动生成的。 20 | // 若要添加或移除成员,请编辑 .ResX 文件,然后重新运行 ResGen 21 | // (以 /str 作为命令选项),或重新生成 VS 项目。 22 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "17.0.0.0")] 23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()] 24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()] 25 | internal class Resource { 26 | 27 | private static global::System.Resources.ResourceManager resourceMan; 28 | 29 | private static global::System.Globalization.CultureInfo resourceCulture; 30 | 31 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")] 32 | internal Resource() { 33 | } 34 | 35 | /// 36 | /// 返回此类使用的缓存的 ResourceManager 实例。 37 | /// 38 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 39 | internal static global::System.Resources.ResourceManager ResourceManager { 40 | get { 41 | if (object.ReferenceEquals(resourceMan, null)) { 42 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("YouTubeWindows.Resource", typeof(Resource).Assembly); 43 | resourceMan = temp; 44 | } 45 | return resourceMan; 46 | } 47 | } 48 | 49 | /// 50 | /// 重写当前线程的 CurrentUICulture 属性,对 51 | /// 使用此强类型资源类的所有资源查找执行重写。 52 | /// 53 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] 54 | internal static global::System.Globalization.CultureInfo Culture { 55 | get { 56 | return resourceCulture; 57 | } 58 | set { 59 | resourceCulture = value; 60 | } 61 | } 62 | 63 | /// 64 | /// 查找类似于 (图标) 的 System.Drawing.Icon 类型的本地化资源。 65 | /// 66 | internal static System.Drawing.Icon icon { 67 | get { 68 | object obj = ResourceManager.GetObject("icon", resourceCulture); 69 | return ((System.Drawing.Icon)(obj)); 70 | } 71 | } 72 | 73 | /// 74 | /// 查找类似 YouTube For Windows Client By TGSAN 75 | /// 76 | ///Base EBWebview2 - Microsoft Edge (Chromium) Runtime 77 | /// 78 | /// 79 | ///YouTube 80 | /// 81 | ///YouTube 是 Google 的子公司 的本地化字符串。 82 | /// 83 | internal static string Staff { 84 | get { 85 | return ResourceManager.GetString("Staff", resourceCulture); 86 | } 87 | } 88 | 89 | /// 90 | /// 查找类似 <!DOCTYPE html> 91 | ///<!-- 92 | /// Copyright 2020 Google LLC. All Rights Reserved. 93 | /// 94 | /// Licensed under the Apache License, Version 2.0 (the "License"); 95 | /// you may not use this file except in compliance with the License. 96 | /// You may obtain a copy of the License at 97 | /// 98 | /// http://www.apache.org/licenses/LICENSE-2.0 99 | /// 100 | /// Unless required by applicable law or agreed to in writing, software 101 | /// distributed under the License is distributed on an "AS IS" BASIS, 102 | /// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express o [字符串的其余部分被截断]"; 的本地化字符串。 103 | /// 104 | internal static string youtube_splash_screen { 105 | get { 106 | return ResourceManager.GetString("youtube_splash_screen", resourceCulture); 107 | } 108 | } 109 | } 110 | } 111 | -------------------------------------------------------------------------------- /YouTubeWindows/Properties/Resources.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | text/microsoft-resx 107 | 108 | 109 | 2.0 110 | 111 | 112 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 113 | 114 | 115 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | -------------------------------------------------------------------------------- /YouTubeWindows/MainForm.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | -------------------------------------------------------------------------------- /YouTubeWindows/YouTubeWindows.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Debug 6 | AnyCPU 7 | {CBE7EF20-1C8B-4593-9AB2-C0368AEFF7B8} 8 | WinExe 9 | YouTubeWindows 10 | YouTubeWindows 11 | v4.5.2 12 | 512 13 | true 14 | true 15 | 16 | 17 | 18 | 19 | 20 | AnyCPU 21 | true 22 | full 23 | false 24 | bin\Debug\ 25 | DEBUG;TRACE 26 | prompt 27 | 4 28 | false 29 | 30 | 31 | AnyCPU 32 | pdbonly 33 | true 34 | bin\Release\ 35 | TRACE 36 | prompt 37 | 4 38 | false 39 | 40 | 41 | Resources\icon.ico 42 | 43 | 44 | app.manifest 45 | 46 | 47 | 48 | ..\packages\Microsoft.Web.WebView2.1.0.1518.46\lib\net45\Microsoft.Web.WebView2.Core.dll 49 | 50 | 51 | ..\packages\Microsoft.Web.WebView2.1.0.1518.46\lib\net45\Microsoft.Web.WebView2.WinForms.dll 52 | 53 | 54 | ..\packages\Microsoft.Web.WebView2.1.0.1518.46\lib\net45\Microsoft.Web.WebView2.Wpf.dll 55 | False 56 | 57 | 58 | C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.5.2\System.dll 59 | 60 | 61 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | Form 74 | 75 | 76 | MainForm.cs 77 | 78 | 79 | 80 | 81 | True 82 | True 83 | Resource.resx 84 | 85 | 86 | MainForm.cs 87 | 88 | 89 | ResXFileCodeGenerator 90 | Resources.Designer.cs 91 | Designer 92 | 93 | 94 | True 95 | Resources.resx 96 | True 97 | 98 | 99 | ResXFileCodeGenerator 100 | Resource.Designer.cs 101 | 102 | 103 | 104 | 105 | SettingsSingleFileGenerator 106 | Settings.Designer.cs 107 | 108 | 109 | True 110 | Settings.settings 111 | True 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | 这台计算机上缺少此项目引用的 NuGet 程序包。使用“NuGet 程序包还原”可下载这些程序包。有关更多信息,请参见 http://go.microsoft.com/fwlink/?LinkID=322105。缺少的文件是 {0}。 131 | 132 | 133 | 134 | -------------------------------------------------------------------------------- /YouTubeWindows/Resource.resx: -------------------------------------------------------------------------------- 1 | 2 | 3 | 62 | 63 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | text/microsoft-resx 110 | 111 | 112 | 2.0 113 | 114 | 115 | System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 116 | 117 | 118 | System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 119 | 120 | 121 | 122 | Resources\icon.ico;System.Drawing.Icon, System.Drawing, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a 123 | 124 | 125 | Resources\Staff.txt;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312 126 | 127 | 128 | Resources\youtube_splash_screen.html;System.String, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089;gb2312 129 | 130 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.vspscc 94 | *.vssscc 95 | .builds 96 | *.pidb 97 | *.svclog 98 | *.scc 99 | 100 | # Chutzpah Test files 101 | _Chutzpah* 102 | 103 | # Visual C++ cache files 104 | ipch/ 105 | *.aps 106 | *.ncb 107 | *.opendb 108 | *.opensdf 109 | *.sdf 110 | *.cachefile 111 | *.VC.db 112 | *.VC.VC.opendb 113 | 114 | # Visual Studio profiler 115 | *.psess 116 | *.vsp 117 | *.vspx 118 | *.sap 119 | 120 | # Visual Studio Trace Files 121 | *.e2e 122 | 123 | # TFS 2012 Local Workspace 124 | $tf/ 125 | 126 | # Guidance Automation Toolkit 127 | *.gpState 128 | 129 | # ReSharper is a .NET coding add-in 130 | _ReSharper*/ 131 | *.[Rr]e[Ss]harper 132 | *.DotSettings.user 133 | 134 | # TeamCity is a build add-in 135 | _TeamCity* 136 | 137 | # DotCover is a Code Coverage Tool 138 | *.dotCover 139 | 140 | # AxoCover is a Code Coverage Tool 141 | .axoCover/* 142 | !.axoCover/settings.json 143 | 144 | # Coverlet is a free, cross platform Code Coverage Tool 145 | coverage*.json 146 | coverage*.xml 147 | coverage*.info 148 | 149 | # Visual Studio code coverage results 150 | *.coverage 151 | *.coveragexml 152 | 153 | # NCrunch 154 | _NCrunch_* 155 | .*crunch*.local.xml 156 | nCrunchTemp_* 157 | 158 | # MightyMoose 159 | *.mm.* 160 | AutoTest.Net/ 161 | 162 | # Web workbench (sass) 163 | .sass-cache/ 164 | 165 | # Installshield output folder 166 | [Ee]xpress/ 167 | 168 | # DocProject is a documentation generator add-in 169 | DocProject/buildhelp/ 170 | DocProject/Help/*.HxT 171 | DocProject/Help/*.HxC 172 | DocProject/Help/*.hhc 173 | DocProject/Help/*.hhk 174 | DocProject/Help/*.hhp 175 | DocProject/Help/Html2 176 | DocProject/Help/html 177 | 178 | # Click-Once directory 179 | publish/ 180 | 181 | # Publish Web Output 182 | *.[Pp]ublish.xml 183 | *.azurePubxml 184 | # Note: Comment the next line if you want to checkin your web deploy settings, 185 | # but database connection strings (with potential passwords) will be unencrypted 186 | *.pubxml 187 | *.publishproj 188 | 189 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 190 | # checkin your Azure Web App publish settings, but sensitive information contained 191 | # in these scripts will be unencrypted 192 | PublishScripts/ 193 | 194 | # NuGet Packages 195 | *.nupkg 196 | # NuGet Symbol Packages 197 | *.snupkg 198 | # The packages folder can be ignored because of Package Restore 199 | **/[Pp]ackages/* 200 | # except build/, which is used as an MSBuild target. 201 | !**/[Pp]ackages/build/ 202 | # Uncomment if necessary however generally it will be regenerated when needed 203 | #!**/[Pp]ackages/repositories.config 204 | # NuGet v3's project.json files produces more ignorable files 205 | *.nuget.props 206 | *.nuget.targets 207 | 208 | # Microsoft Azure Build Output 209 | csx/ 210 | *.build.csdef 211 | 212 | # Microsoft Azure Emulator 213 | ecf/ 214 | rcf/ 215 | 216 | # Windows Store app package directories and files 217 | AppPackages/ 218 | BundleArtifacts/ 219 | Package.StoreAssociation.xml 220 | _pkginfo.txt 221 | *.appx 222 | *.appxbundle 223 | *.appxupload 224 | 225 | # Visual Studio cache files 226 | # files ending in .cache can be ignored 227 | *.[Cc]ache 228 | # but keep track of directories ending in .cache 229 | !?*.[Cc]ache/ 230 | 231 | # Others 232 | ClientBin/ 233 | ~$* 234 | *~ 235 | *.dbmdl 236 | *.dbproj.schemaview 237 | *.jfm 238 | *.pfx 239 | *.publishsettings 240 | orleans.codegen.cs 241 | 242 | # Including strong name files can present a security risk 243 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 244 | #*.snk 245 | 246 | # Since there are multiple workflows, uncomment next line to ignore bower_components 247 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 248 | #bower_components/ 249 | 250 | # RIA/Silverlight projects 251 | Generated_Code/ 252 | 253 | # Backup & report files from converting an old project file 254 | # to a newer Visual Studio version. Backup files are not needed, 255 | # because we have git ;-) 256 | _UpgradeReport_Files/ 257 | Backup*/ 258 | UpgradeLog*.XML 259 | UpgradeLog*.htm 260 | ServiceFabricBackup/ 261 | *.rptproj.bak 262 | 263 | # SQL Server files 264 | *.mdf 265 | *.ldf 266 | *.ndf 267 | 268 | # Business Intelligence projects 269 | *.rdl.data 270 | *.bim.layout 271 | *.bim_*.settings 272 | *.rptproj.rsuser 273 | *- [Bb]ackup.rdl 274 | *- [Bb]ackup ([0-9]).rdl 275 | *- [Bb]ackup ([0-9][0-9]).rdl 276 | 277 | # Microsoft Fakes 278 | FakesAssemblies/ 279 | 280 | # GhostDoc plugin setting file 281 | *.GhostDoc.xml 282 | 283 | # Node.js Tools for Visual Studio 284 | .ntvs_analysis.dat 285 | node_modules/ 286 | 287 | # Visual Studio 6 build log 288 | *.plg 289 | 290 | # Visual Studio 6 workspace options file 291 | *.opt 292 | 293 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 294 | *.vbw 295 | 296 | # Visual Studio LightSwitch build output 297 | **/*.HTMLClient/GeneratedArtifacts 298 | **/*.DesktopClient/GeneratedArtifacts 299 | **/*.DesktopClient/ModelManifest.xml 300 | **/*.Server/GeneratedArtifacts 301 | **/*.Server/ModelManifest.xml 302 | _Pvt_Extensions 303 | 304 | # Paket dependency manager 305 | .paket/paket.exe 306 | paket-files/ 307 | 308 | # FAKE - F# Make 309 | .fake/ 310 | 311 | # CodeRush personal settings 312 | .cr/personal 313 | 314 | # Python Tools for Visual Studio (PTVS) 315 | __pycache__/ 316 | *.pyc 317 | 318 | # Cake - Uncomment if you are using it 319 | # tools/** 320 | # !tools/packages.config 321 | 322 | # Tabs Studio 323 | *.tss 324 | 325 | # Telerik's JustMock configuration file 326 | *.jmconfig 327 | 328 | # BizTalk build output 329 | *.btp.cs 330 | *.btm.cs 331 | *.odx.cs 332 | *.xsd.cs 333 | 334 | # OpenCover UI analysis results 335 | OpenCover/ 336 | 337 | # Azure Stream Analytics local run output 338 | ASALocalRun/ 339 | 340 | # MSBuild Binary and Structured Log 341 | *.binlog 342 | 343 | # NVidia Nsight GPU debugger configuration file 344 | *.nvuser 345 | 346 | # MFractors (Xamarin productivity tool) working folder 347 | .mfractor/ 348 | 349 | # Local History for Visual Studio 350 | .localhistory/ 351 | 352 | # BeatPulse healthcheck temp database 353 | healthchecksdb 354 | 355 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 356 | MigrationBackup/ 357 | 358 | # Ionide (cross platform F# VS Code tools) working folder 359 | .ionide/ 360 | 361 | # Fody - auto-generated XML schema 362 | FodyWeavers.xsd -------------------------------------------------------------------------------- /YouTubeWindows/MainForm.cs: -------------------------------------------------------------------------------- 1 | using Microsoft.Web.WebView2.Core; 2 | using Microsoft.Web.WebView2.WinForms; 3 | using System; 4 | using System.Collections.Generic; 5 | using System.Drawing; 6 | using System.IO; 7 | using System.Runtime.InteropServices; 8 | using System.Text; 9 | using System.Threading; 10 | using System.Threading.Tasks; 11 | using System.Windows.Forms; 12 | 13 | namespace YouTubeWindows 14 | { 15 | public struct WebView2RuntimeInfo 16 | { 17 | public string Version; 18 | public string Path; 19 | } 20 | 21 | public partial class MainForm : Form 22 | { 23 | [DllImport("dwmapi.dll")] 24 | private static extern int DwmSetWindowAttribute(IntPtr hwnd, int attr, ref int attrValue, int attrSize); 25 | 26 | private string lang = System.Globalization.CultureInfo.InstalledUICulture.Name; 27 | public bool allowAutoHDR = false; 28 | public string webview2StartupArgs = ""; 29 | WebView2RuntimeInfo? webview2RuntimeInfo = null; 30 | private CoreWebView2Environment coreWebView2Environment; 31 | public WebView2 splashScreenWebView; 32 | public WebView2 screenWebView; 33 | public Panel splashScreenWebViewPanel = new Panel(); 34 | public Panel screenWebViewPanel = new Panel(); 35 | private int titleHeight 36 | { 37 | get 38 | { 39 | Rectangle screenRectangle = this.RectangleToScreen(this.ClientRectangle); 40 | return screenRectangle.Top - this.Top; 41 | } 42 | } 43 | 44 | private bool _fullscreen = false; 45 | public bool fullscreen 46 | { 47 | get 48 | { 49 | return _fullscreen; 50 | } 51 | set 52 | { 53 | _fullscreen = value; 54 | if (_fullscreen) 55 | { 56 | FormBorderStyle = FormBorderStyle.None; 57 | WindowState = FormWindowState.Maximized; 58 | } 59 | else 60 | { 61 | FormBorderStyle = FormBorderStyle.Sizable; 62 | WindowState = FormWindowState.Normal; 63 | } 64 | } 65 | } 66 | 67 | private bool _cursorShown = true; 68 | public bool cursorShown 69 | { 70 | get 71 | { 72 | return _cursorShown; 73 | } 74 | set 75 | { 76 | if (value == _cursorShown) 77 | { 78 | return; 79 | } 80 | 81 | if (value) 82 | { 83 | TryInvoke(() => 84 | { 85 | System.Windows.Forms.Cursor.Show(); 86 | }); 87 | } 88 | else 89 | { 90 | TryInvoke(() => 91 | { 92 | System.Windows.Forms.Cursor.Hide(); 93 | }); 94 | } 95 | 96 | _cursorShown = value; 97 | } 98 | } 99 | 100 | private const int DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1 = 19; 101 | private const int DWMWA_USE_IMMERSIVE_DARK_MODE = 20; 102 | 103 | private static bool UseImmersiveDarkMode(IntPtr handle, bool enabled) 104 | { 105 | if (IsWindows10OrGreater(17763)) 106 | { 107 | var attribute = DWMWA_USE_IMMERSIVE_DARK_MODE_BEFORE_20H1; 108 | if (IsWindows10OrGreater(18985)) 109 | { 110 | attribute = DWMWA_USE_IMMERSIVE_DARK_MODE; 111 | } 112 | 113 | int useImmersiveDarkMode = enabled ? 1 : 0; 114 | return DwmSetWindowAttribute(handle, (int)attribute, ref useImmersiveDarkMode, sizeof(int)) == 0; 115 | } 116 | 117 | return false; 118 | } 119 | 120 | private static bool IsWindows10OrGreater(int build = -1) 121 | { 122 | return Environment.OSVersion.Version.Major >= 10 && Environment.OSVersion.Version.Build >= build; 123 | } 124 | 125 | private WebView2RuntimeInfo? ReadRuntime(string path) 126 | { 127 | try 128 | { 129 | var availableBrowserVersionString = CoreWebView2Environment.GetAvailableBrowserVersionString(path); 130 | if (availableBrowserVersionString != null) 131 | { 132 | WebView2RuntimeInfo info = new WebView2RuntimeInfo() 133 | { 134 | Version = availableBrowserVersionString, 135 | Path = path 136 | }; 137 | return info; 138 | } 139 | } 140 | catch { } 141 | return null; 142 | } 143 | 144 | public void TryInvoke(Action action) 145 | { 146 | if (InvokeRequired) 147 | { 148 | Invoke(action); 149 | } 150 | else 151 | { 152 | action(); 153 | } 154 | } 155 | 156 | public MainForm(string[] args) 157 | { 158 | string[] runtimePaths = { 159 | // Fixed Version 固定版本 160 | AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "runtime", 161 | // Evergreen 长青版 162 | null 163 | }; 164 | 165 | foreach (string runtimePath in runtimePaths) 166 | { 167 | webview2RuntimeInfo = ReadRuntime(runtimePath); 168 | if (webview2RuntimeInfo != null) 169 | { 170 | break; 171 | } 172 | } 173 | 174 | if (webview2RuntimeInfo != null) 175 | { 176 | #if DEBUG 177 | var availableBrowserVersionString = CoreWebView2Environment.GetAvailableBrowserVersionString(); 178 | MessageBox.Show("当前 WebView2 Runtime:\n" + (webview2RuntimeInfo.Value.Path == null ? "Evergreen Runtime" : "Fixed Version Runtime: " + webview2RuntimeInfo.Value.Path) + "\nVersion: " + availableBrowserVersionString, "YouTube"); 179 | #endif 180 | } 181 | else 182 | { 183 | if (lang.StartsWith("zh-")) 184 | { 185 | MessageBox.Show("缺少 WebView2 Runtime,无法运行。\n可以通过以下任意一种方式安装:\n\n1. 安装任意非稳定通道 Microsoft Edge (Chromium) 浏览器。\n2. 安装 WebView2 Runtime Evergreen 版本。\n3. 将 WebView2 Runtime Fixed Version 版本放入 YouTube For Windows 的 runtime 文件夹下。", "YouTube"); 186 | } 187 | else 188 | { 189 | MessageBox.Show("The application cannot run because the WebView2 Runtime is missing.\nYou can resolve this by choosing one of the following methods:\n\n1. Install any non-stable channel version of Microsoft Edge (Chromium).\n2. Install the WebView2 Runtime Evergreen version.\n3. Place the WebView2 Runtime Fixed Version in the runtime folder of YouTube For Windows.", "YouTube"); 190 | } 191 | Close(); 192 | Application.Exit(); 193 | return; 194 | } 195 | 196 | StringBuilder webview2StartupArgsBuilder = new StringBuilder(); 197 | 198 | foreach (var arg in args) 199 | { 200 | switch (arg) 201 | { 202 | case "--allow-auto-hdr": 203 | { 204 | allowAutoHDR = true; 205 | } 206 | break; 207 | default: 208 | { 209 | webview2StartupArgsBuilder.Append(arg + " "); 210 | } 211 | break; 212 | } 213 | 214 | } 215 | 216 | webview2StartupArgs = webview2StartupArgsBuilder.ToString(); 217 | 218 | InitializeComponent(); 219 | 220 | UseImmersiveDarkMode(this.Handle, true); 221 | 222 | this.Icon = Resource.icon; 223 | 224 | screenWebViewPanel.Dock = DockStyle.Fill; 225 | screenWebViewPanel.BackColor = Color.Transparent; 226 | splashScreenWebViewPanel.Dock = DockStyle.Fill; 227 | splashScreenWebViewPanel.BackColor = Color.Transparent; 228 | 229 | Controls.Add(splashScreenWebViewPanel); // 放置闪屏承载层(顶部) 230 | Controls.Add(screenWebViewPanel); // 放置App承载层(底部) 231 | } 232 | 233 | protected override void WndProc(ref Message m) 234 | { 235 | switch (m.Msg) 236 | { 237 | case 0x0210 /* WM_PARENTNOTIFY */: 238 | if (m.WParam == (IntPtr)0x0204 /* WM_RBUTTONDOWN */) 239 | { 240 | SendKeys.Send("{ESC}"); 241 | } 242 | break; 243 | } 244 | base.WndProc(ref m); 245 | } 246 | 247 | private void MainForm_Load(object sender, EventArgs e) 248 | { 249 | var userDataDir = AppDomain.CurrentDomain.SetupInformation.ApplicationBase + "User Data"; 250 | var ua = "TV (PLATFORM_DETAILS_OTT), Cobalt/" + webview2RuntimeInfo.Value.Version + "-CloudMoe (unlike Gecko) Starboard/14, SystemIntegratorName_OTT_CloudMoeSubsystem_2025/FirmwareVersion (Windows NT " + Environment.OSVersion.Version.ToString() + ")"; 251 | webview2StartupArgs = webview2StartupArgs + "--single-process --allow-failed-policy-fetch-for-test --allow-running-insecure-content --disable-web-security --user-agent=\"" + ua + "\""; 252 | 253 | if (!allowAutoHDR) 254 | { 255 | webview2StartupArgs += " --disable_vp_auto_hdr"; 256 | } 257 | 258 | var options = new CoreWebView2EnvironmentOptions(webview2StartupArgs); 259 | coreWebView2Environment = CoreWebView2Environment.CreateAsync(webview2RuntimeInfo.Value.Path, userDataDir, options).Result; 260 | 261 | splashScreenWebView = new WebView2(); 262 | splashScreenWebView.DefaultBackgroundColor = Color.Transparent; 263 | screenWebView = new WebView2(); 264 | screenWebView.DefaultBackgroundColor = Color.Transparent; 265 | 266 | screenWebView.Enabled = false; 267 | 268 | screenWebViewPanel.Visible = false; 269 | splashScreenWebViewPanel.Visible = false; 270 | 271 | screenWebViewPanel.Controls.Add(screenWebView); 272 | splashScreenWebViewPanel.Controls.Add(splashScreenWebView); 273 | 274 | InitializeSplashScreenAsync(); 275 | 276 | Task.Run(async () => 277 | { 278 | const int stepMs = 100; 279 | int hideMs = 2000; 280 | int currentMs = 0; 281 | Point lastMousePos = System.Windows.Forms.Cursor.Position; 282 | while (true) 283 | { 284 | await Task.Delay(stepMs); 285 | int x = lastMousePos.X; 286 | int y = lastMousePos.Y; 287 | Point pos = System.Windows.Forms.Cursor.Position; 288 | if (pos.X == x && pos.Y == y) 289 | { 290 | if (currentMs >= hideMs) 291 | { 292 | cursorShown = false; 293 | } 294 | else 295 | { 296 | currentMs += stepMs; 297 | //Console.WriteLine("Mouse Stop: " + currentMs); 298 | } 299 | } 300 | else 301 | { 302 | currentMs = 0; 303 | cursorShown = true; 304 | lastMousePos = pos; 305 | //Console.WriteLine("Mouse Moved"); 306 | } 307 | } 308 | }); 309 | } 310 | 311 | private static Stream GenerateStreamFromString(string s) 312 | { 313 | var stream = new MemoryStream(); 314 | var writer = new StreamWriter(stream); 315 | writer.Write(s); 316 | writer.Flush(); 317 | stream.Position = 0; 318 | return stream; 319 | } 320 | 321 | private async Task NativeBridgeRegister(WebView2 webView2) 322 | { 323 | webView2.CoreWebView2.AddHostObjectToScript("NativeBridge", new Bridge(this)); 324 | // 简化 NativeBridge 325 | await webView2.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.NativeBridge = window?.chrome?.webview?.hostObjects?.NativeBridge;"); 326 | // 替换 Close 327 | await webView2.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.close = window?.chrome?.webview?.hostObjects?.NativeBridge?.Close;"); 328 | // 全屏和重载监听 329 | await webView2.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.addEventListener('keydown', (event) => { if (event.keyCode === 122) { event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); event.returnValue = false; NativeBridge.ToggleFullscreen(); } if(event.keyCode == 116 || (event.ctrlKey && event.keyCode == 82)) { event.preventDefault(); event.stopPropagation(); event.stopImmediatePropagation(); event.returnValue = false; NativeBridge.ReloadApp(); } }, true);"); 330 | // Video 标签 Hook 331 | await webView2.CoreWebView2.AddScriptToExecuteOnDocumentCreatedAsync("window.HTMLVideoElement.prototype.playOriginal = window.HTMLVideoElement.prototype.play; window.HTMLVideoElement.prototype.play = function (...args) { this.msVideoProcessing = \"msGraphicsDriverEnhancement\"; return this.playOriginal(...args); }"); 332 | } 333 | 334 | private async void InitializeSplashScreenAsync() 335 | { 336 | splashScreenWebView.Dock = DockStyle.Fill; 337 | await splashScreenWebView.EnsureCoreWebView2Async(coreWebView2Environment); 338 | await splashScreenWebView.ExecuteScriptAsync("document.body.style.backgroundColor = '#181818'"); 339 | await NativeBridgeRegister(splashScreenWebView); 340 | _ = splashScreenWebView.CoreWebView2.CallDevToolsProtocolMethodAsync("Emulation.setEmitTouchEventsForMouse", "{\"enabled\": true}"); 341 | splashScreenWebView.CoreWebView2.Settings.AreDevToolsEnabled = false; 342 | splashScreenWebView.CoreWebView2.Settings.IsStatusBarEnabled = false; 343 | splashScreenWebView.CoreWebView2.Settings.IsZoomControlEnabled = false; 344 | splashScreenWebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; 345 | InitializeMainAppAsync(); 346 | } 347 | 348 | private async void InitializeMainAppAsync() 349 | { 350 | await screenWebView.EnsureCoreWebView2Async(coreWebView2Environment); 351 | await NativeBridgeRegister(screenWebView); 352 | _ = screenWebView.CoreWebView2.CallDevToolsProtocolMethodAsync("Emulation.setEmitTouchEventsForMouse", "{\"enabled\": true}"); 353 | _ = screenWebView.CoreWebView2.CallDevToolsProtocolMethodAsync("Emulation.setDeviceMetricsOverride", "{\"width\": 0, \"height\": 0, \"deviceScaleFactor\": 1, \"scale\": 0.1, \"screenWidth\": 7680,\"screenHeight\": 4320, \"mobile\": false, \"dontSetVisibleSize\": false}"); 354 | screenWebView.CoreWebView2.DOMContentLoaded += CoreWebView2_DOMContentLoaded; 355 | screenWebView.CoreWebView2.AddWebResourceRequestedFilter("https://www.gstatic.com/ytlr/txt/licenses_*", CoreWebView2WebResourceContext.All); 356 | screenWebView.CoreWebView2.WebResourceRequested += CoreWebView2_WebResourceRequested; 357 | screenWebView.CoreWebView2.WindowCloseRequested += CoreWebView2_WindowCloseRequested; 358 | screenWebView.CoreWebView2.PermissionRequested += CoreWebView2_PermissionRequested; 359 | screenWebView.CoreWebView2.Settings.AreDevToolsEnabled = false; 360 | screenWebView.CoreWebView2.Settings.IsStatusBarEnabled = false; 361 | screenWebView.CoreWebView2.Settings.IsZoomControlEnabled = false; 362 | screenWebView.CoreWebView2.Settings.AreDefaultContextMenusEnabled = false; 363 | #if DEBUG 364 | screenWebView.CoreWebView2.OpenDevToolsWindow(); 365 | #endif 366 | ReloadApp(); 367 | } 368 | 369 | private void CoreWebView2_WindowCloseRequested(object sender, object e) 370 | { 371 | Close(); 372 | } 373 | 374 | private void CoreWebView2_PermissionRequested(object sender, CoreWebView2PermissionRequestedEventArgs e) 375 | { 376 | e.Handled = true; 377 | } 378 | 379 | private void CoreWebView2_WebResourceRequested(object sender, CoreWebView2WebResourceRequestedEventArgs e) 380 | { 381 | Console.WriteLine(e.Request.Uri); 382 | if (e.Request.Uri.StartsWith("https://www.gstatic.com/ytlr/txt/licenses_")) 383 | { 384 | var stream = GenerateStreamFromString( 385 | Resource.Staff 386 | .Replace("\n", "\n\u200B") 387 | .Replace("<--%WEBVIEW_VERSION%-->", webview2RuntimeInfo.Value.Version) 388 | .Replace("<--%PROGRAM_VERSION%-->", Version.Parse(Application.ProductVersion).ToString(3))); 389 | e.Response = coreWebView2Environment.CreateWebResourceResponse(stream, 200, "OK", "Access-Control-Allow-Origin: *\r\nContent-Type: text/html"); 390 | new Thread(() => 391 | { 392 | Thread.Sleep(3000); // 流资源 3000ms 后释放 393 | var action = new Action(() => 394 | { 395 | stream.Close(); 396 | }); 397 | 398 | TryInvoke(action); 399 | }).Start(); 400 | } 401 | } 402 | 403 | public void ReloadApp() 404 | { 405 | screenWebView.Enabled = false; 406 | splashScreenWebView.CoreWebView2.NavigateToString(Resource.youtube_splash_screen); 407 | screenWebView.CoreWebView2.Navigate("https://www.youtube.com/tv"); 408 | screenWebViewPanel.Visible = false; 409 | splashScreenWebViewPanel.Visible = true; 410 | } 411 | 412 | private void CoreWebView2_DOMContentLoaded(object sender, CoreWebView2DOMContentLoadedEventArgs e) 413 | { 414 | if (screenWebView.Source.ToString().StartsWith("https://www.youtube.com")) 415 | { 416 | // 破解分辨率新版用 DeviceMetricsOverride 替代 417 | screenWebView.ExecuteScriptAsync("{ setTimeout(() => { NativeBridge.ActiveScreen(); }, 0); }"); 418 | // 后台播放 419 | screenWebView.ExecuteScriptAsync("for (event_name of ['visibilitychange', 'webkitvisibilitychange', 'blur']) { window.addEventListener(event_name, function(event) { event.stopImmediatePropagation(); }, true); }"); 420 | // 注入动画 421 | screenWebView.ExecuteScriptAsync("document.body.style.opacity = 0; document.body.style.transition = 'opacity 333ms';"); 422 | // 修改设备型号 423 | screenWebView.ExecuteScriptAsync("window.environment.brand = \"Apple\";"); 424 | screenWebView.ExecuteScriptAsync("window.environment.model = \"AppleTV\";"); 425 | // 修改功能开关 426 | screenWebView.ExecuteScriptAsync("window.environment.has_touch_support = true;"); 427 | screenWebView.ExecuteScriptAsync("window.environment.feature_switches.disable_client_side_app_quality_logic = false;"); 428 | string deviceName = "YouTube on Windows"; 429 | if (!String.IsNullOrEmpty(System.Environment.MachineName)) 430 | { 431 | deviceName += $" ({System.Environment.MachineName})"; 432 | } 433 | screenWebView.ExecuteScriptAsync("window.environment.feature_switches.mdx_device_label = \"" + deviceName + "\";"); 434 | } 435 | else 436 | { 437 | screenWebView.Dock = DockStyle.Fill; 438 | } 439 | } 440 | 441 | private void MainForm_Activated(object sender, EventArgs e) 442 | { 443 | screenWebView.Focus(); 444 | } 445 | 446 | private void MainForm_Resize(object sender, EventArgs e) 447 | { 448 | if (WindowState == FormWindowState.Normal) 449 | { 450 | var aspect = (double)16 / 9; 451 | var height = this.ClientSize.Width / aspect; 452 | var width = height * aspect; 453 | this.ClientSize = new Size((int)width, (int)height); 454 | } 455 | } 456 | 457 | private void MainForm_ResizeBegin(object sender, EventArgs e) 458 | { 459 | this.SuspendLayout(); 460 | } 461 | 462 | private void MainForm_ResizeEnd(object sender, EventArgs e) 463 | { 464 | this.ResumeLayout(); 465 | } 466 | } 467 | 468 | [ClassInterface(ClassInterfaceType.AutoDual)] 469 | [ComVisible(true)] 470 | public class BridgeAnotherClass 471 | { 472 | // Sample property. 473 | public string Prop { get; set; } = "Example"; 474 | } 475 | 476 | [ClassInterface(ClassInterfaceType.AutoDual)] 477 | [ComVisible(true)] 478 | public class Bridge 479 | { 480 | private MainForm ctxMainForm; 481 | 482 | public Bridge(MainForm mainForm) 483 | { 484 | ctxMainForm = mainForm; 485 | } 486 | 487 | public string Func(string param) 488 | { 489 | Console.WriteLine(param); 490 | return "Example: " + param; 491 | } 492 | 493 | public void Close() 494 | { 495 | ctxMainForm.Close(); 496 | } 497 | 498 | public void ReloadApp() 499 | { 500 | ctxMainForm.ReloadApp(); 501 | } 502 | 503 | public void ToggleFullscreen() 504 | { 505 | ctxMainForm.fullscreen = !ctxMainForm.fullscreen; 506 | } 507 | 508 | public void ActiveScreen() 509 | { 510 | new Thread(() => 511 | { 512 | var action1 = new Action(() => 513 | { 514 | ctxMainForm.screenWebView.Dock = DockStyle.Fill; 515 | }); 516 | 517 | ctxMainForm.TryInvoke(action1); 518 | 519 | Thread.Sleep(3000); 520 | 521 | var action2 = new Action(() => 522 | { 523 | ctxMainForm.splashScreenWebView.ExecuteScriptAsync("document.getElementById('background').style.opacity = 0;"); 524 | ctxMainForm.screenWebViewPanel.Visible = true; 525 | }); 526 | 527 | ctxMainForm.TryInvoke(action2); 528 | 529 | Thread.Sleep(500); 530 | 531 | var action3 = new Action(() => 532 | { 533 | ctxMainForm.splashScreenWebViewPanel.Visible = false; 534 | ctxMainForm.splashScreenWebView.CoreWebView2.Navigate("about:blank"); 535 | ctxMainForm.splashScreenWebView.ExecuteScriptAsync("document.body.style.backgroundColor = '#181818'"); 536 | ctxMainForm.screenWebView.Enabled = true; 537 | ctxMainForm.screenWebView.ExecuteScriptAsync("document.body.style.opacity = 1;"); 538 | if (ctxMainForm.Focused) 539 | { 540 | ctxMainForm.screenWebView.Focus(); 541 | } 542 | }); 543 | 544 | ctxMainForm.TryInvoke(action3); 545 | }).Start(); 546 | } 547 | 548 | public BridgeAnotherClass AnotherObject { get; set; } = new BridgeAnotherClass(); 549 | 550 | // Sample indexed property. 551 | [System.Runtime.CompilerServices.IndexerName("Items")] 552 | public string this[int index] 553 | { 554 | get { return m_dictionary[index]; } 555 | set { m_dictionary[index] = value; } 556 | } 557 | private Dictionary m_dictionary = new Dictionary(); 558 | } 559 | } 560 | -------------------------------------------------------------------------------- /YouTubeWindows/Resources/youtube_splash_screen.html: -------------------------------------------------------------------------------- 1 | 2 | 17 | 18 | 19 | 20 | 175 | 176 | 177 | 178 |
179 |
180 |
181 |
182 |
183 |
184 |
185 |
186 |
187 |
188 |
189 |
190 |
191 |
192 | 193 | 194 | --------------------------------------------------------------------------------