├── M3U8URL2File.sln
├── M3U8URL2File
├── App.xaml
├── App.xaml.cs
├── M3U8URL2File.csproj
├── MainWindow.xaml
├── MainWindow.xaml.cs
└── Properties
│ ├── AssemblyInfo.cs
│ ├── Resources.Designer.cs
│ ├── Resources.resx
│ ├── Settings.Designer.cs
│ └── Settings.settings
└── README.md
/M3U8URL2File.sln:
--------------------------------------------------------------------------------
1 |
2 | Microsoft Visual Studio Solution File, Format Version 12.00
3 | # Visual Studio Version 16
4 | VisualStudioVersion = 16.0.29009.5
5 | MinimumVisualStudioVersion = 10.0.40219.1
6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "M3U8URL2File", "M3U8URL2File\M3U8URL2File.csproj", "{753810B9-2D2D-44FC-A808-BC7009E0AE9A}"
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 | {753810B9-2D2D-44FC-A808-BC7009E0AE9A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
15 | {753810B9-2D2D-44FC-A808-BC7009E0AE9A}.Debug|Any CPU.Build.0 = Debug|Any CPU
16 | {753810B9-2D2D-44FC-A808-BC7009E0AE9A}.Release|Any CPU.ActiveCfg = Release|Any CPU
17 | {753810B9-2D2D-44FC-A808-BC7009E0AE9A}.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 = {701E45A1-B135-43D7-BA73-1E0295E4CD32}
24 | EndGlobalSection
25 | EndGlobal
26 |
--------------------------------------------------------------------------------
/M3U8URL2File/App.xaml:
--------------------------------------------------------------------------------
1 |
6 |
7 |
8 |
9 |
10 |
--------------------------------------------------------------------------------
/M3U8URL2File/App.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Configuration;
4 | using System.Data;
5 | using System.Linq;
6 | using System.Windows;
7 |
8 | namespace M3U8URL2File
9 | {
10 | ///
11 | /// App.xaml 的交互逻辑
12 | ///
13 | public partial class App : Application
14 | {
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/M3U8URL2File/M3U8URL2File.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | Debug
6 | AnyCPU
7 | {753810B9-2D2D-44FC-A808-BC7009E0AE9A}
8 | WinExe
9 | M3U8URL2File
10 | M3U8URL2File
11 | v4.0
12 | 512
13 | {60dc8134-eba5-43b8-bcc9-bb4bc16c2548};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}
14 | 4
15 | true
16 |
17 |
18 | AnyCPU
19 | true
20 | full
21 | false
22 | bin\Debug\
23 | DEBUG;TRACE
24 | prompt
25 | 4
26 |
27 |
28 | AnyCPU
29 | pdbonly
30 | true
31 | bin\Release\
32 | TRACE
33 | prompt
34 | 4
35 |
36 |
37 |
38 |
39 |
40 |
41 |
42 |
43 |
44 |
45 |
46 | 4.0
47 |
48 |
49 |
50 |
51 |
52 |
53 |
54 | MSBuild:Compile
55 | Designer
56 |
57 |
58 | MSBuild:Compile
59 | Designer
60 |
61 |
62 | App.xaml
63 | Code
64 |
65 |
66 | MainWindow.xaml
67 | Code
68 |
69 |
70 |
71 |
72 | Code
73 |
74 |
75 | True
76 | True
77 | Resources.resx
78 |
79 |
80 | True
81 | Settings.settings
82 | True
83 |
84 |
85 | ResXFileCodeGenerator
86 | Resources.Designer.cs
87 |
88 |
89 | SettingsSingleFileGenerator
90 | Settings.Designer.cs
91 |
92 |
93 |
94 |
--------------------------------------------------------------------------------
/M3U8URL2File/MainWindow.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
30 |
31 |
32 |
33 |
34 |
35 |
--------------------------------------------------------------------------------
/M3U8URL2File/MainWindow.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections;
3 | using System.Collections.Generic;
4 | using System.IO;
5 | using System.Linq;
6 | using System.Net;
7 | using System.Text;
8 | using System.Text.RegularExpressions;
9 | using System.Threading;
10 | using System.Windows;
11 | using System.Windows.Controls;
12 | using System.Windows.Data;
13 | using System.Windows.Documents;
14 | using System.Windows.Forms;
15 | using System.Windows.Input;
16 | using System.Windows.Media;
17 | using System.Windows.Media.Imaging;
18 | using System.Windows.Navigation;
19 | using System.Windows.Shapes;
20 | using MessageBox = System.Windows.MessageBox;
21 |
22 | namespace M3U8URL2File
23 | {
24 | ///
25 | /// MainWindow.xaml 的交互逻辑
26 | ///
27 | public partial class MainWindow : Window
28 | {
29 | public MainWindow()
30 | {
31 | InitializeComponent();
32 | TextBox_Regex.Text = "(https?|ftp|file)://[-A-Za-z0-9+&@#/%?=~_|!:,.;]+[-A-Za-z0-9+&@#/%=~_|]";
33 | TextBox_Input.Focus();
34 | }
35 |
36 | private void TextBox_PreviewTextInput(object sender, TextCompositionEventArgs e)
37 | {
38 | Regex re = new Regex("[^0-9]+");
39 | e.Handled = re.IsMatch(e.Text);
40 | }
41 |
42 | private void Button_Match_Click(object sender, RoutedEventArgs e)
43 | {
44 | if (TextBox_StartIndex.Text == "")
45 | TextBox_StartIndex.Text = "1";
46 |
47 | Regex regex = new Regex(@TextBox_Regex.Text);
48 | TextBox_MatchCount.Text = regex.Matches(TextBox_Input.Text).Count.ToString();
49 | if (TextBox_MatchCount.Text == "0")
50 | Button_Down.IsEnabled = false;
51 | MatchCollection mc = Regex.Matches(TextBox_Input.Text, @TextBox_Regex.Text, RegexOptions.IgnoreCase);
52 | StringBuilder sb = new StringBuilder();
53 | foreach (Match m in mc)
54 | {
55 | sb.Append(m.Value + "\r\n");
56 | }
57 | TextBox_Input.Text = sb.ToString().Trim();
58 |
59 | if (TextBox_Input.Text.Trim() == "")
60 | return;
61 |
62 | Button_Down.IsEnabled = true;
63 | }
64 |
65 | private void Button_Down_Click(object sender, RoutedEventArgs e)
66 | {
67 | FolderBrowserDialog openFileDialog = new FolderBrowserDialog(); //选择文件夹
68 | openFileDialog.Description = "选择一个目录,M3U8文件们将会下载到此处";
69 | string dir = "";
70 | if (openFileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK)
71 | {
72 | dir = openFileDialog.SelectedPath;
73 | }
74 |
75 | if (dir == "")
76 | return;
77 |
78 | int startIndex = Convert.ToInt32(TextBox_StartIndex.Text);
79 | int initIndex = startIndex;
80 | int total = Convert.ToInt32(TextBox_MatchCount.Text);
81 | string input = TextBox_Input.Text;
82 | Button_Down.IsEnabled = false;
83 | Button_Match.IsEnabled = false;
84 |
85 | try
86 | {
87 | ThreadPool.QueueUserWorkItem((object state) =>
88 | {
89 | foreach (var url in input.Split('\n'))
90 | {
91 | WebClient down = new WebClient();
92 | down.Encoding = Encoding.UTF8;
93 | string outpath = "";
94 | string m3u8_baseUrl = GetBaseUrl(url);
95 | string m3u8_temp = down.DownloadString(url);
96 |
97 | ArrayList lines = new ArrayList();
98 | lines.Clear();
99 | using (StringReader sr = new StringReader(m3u8_temp)) //判断m3u8是否需要增加baseurl
100 | {
101 | string line;
102 | while ((line = sr.ReadLine()) != null)
103 | {
104 | lines.Add(line);
105 | if (lines.Count > 1 && lines[lines.Count - 2].ToString().StartsWith("#EXTINF:"))
106 | {
107 | if (!lines[lines.Count - 1].ToString().StartsWith("http"))
108 | {
109 | lines[lines.Count - 1] = CombineURL(m3u8_baseUrl, lines[lines.Count - 1].ToString());
110 | }
111 | }
112 | }
113 | }
114 |
115 | double time = 0;
116 | //计算时长
117 | if (m3u8_temp.Contains("#EXTINF:"))
118 | {
119 | Regex regex = new Regex("#EXTINF:(.*),");
120 | MatchCollection matches = regex.Matches(m3u8_temp);
121 | foreach (Match match in matches)
122 | {
123 | time += Convert.ToDouble(match.Groups[1].Value);
124 | }
125 | }
126 | if (time < 0)
127 | time = 0;
128 | this.Dispatcher.BeginInvoke(new Action(() =>
129 | {
130 | if (time != 0)
131 | outpath = dir + "\\" + TextBox_Prefix.Text + "_" + (startIndex++).ToString("000") + "_" + FormatTime(Convert.ToInt32(time)) + ".m3u8";
132 | else
133 | outpath = dir + "\\" + TextBox_Prefix.Text + "_" + FormatTime(Convert.ToInt32(time)) + ".m3u8";
134 | StreamWriter writer = new StreamWriter(outpath, false); //false代表替换而不是追加
135 | for (int j = 0; j < lines.Count; j++)
136 | {
137 | writer.WriteLine(lines[j]);
138 | }
139 | writer.Close();
140 | TextBox_MatchCount.Text = (startIndex - 1) + "/" + (total + initIndex - 1);
141 | }));
142 | }
143 |
144 | this.Dispatcher.BeginInvoke(new Action(() =>
145 | {
146 | TextBox_MatchCount.Text = "0";
147 | Button_Match.IsEnabled = true;
148 | }));
149 | MessageBox.Show("下载完成!");
150 | }, null);
151 | }
152 | catch (Exception)
153 | {
154 | TextBox_MatchCount.Text = "0";
155 | Button_Match.IsEnabled = true;
156 | }
157 | }
158 |
159 | //此函数用于格式化输出时长
160 | public static String FormatTime(Int32 time)
161 | {
162 | TimeSpan ts = new TimeSpan(0, 0, time);
163 | string str = "";
164 | str = (ts.Hours.ToString("00") == "00" ? "" : ts.Hours.ToString("00") + "h") + ts.Minutes.ToString("00") + "m" + ts.Seconds.ToString("00") + "s";
165 | return str;
166 | }
167 |
168 | ///
169 | /// 从url中截取字符串充当baseurl
170 | ///
171 | ///
172 | ///
173 | public string GetBaseUrl(string m3u8url)
174 | {
175 | string url = m3u8url;
176 | if (url.Contains("?"))
177 | url = url.Remove(url.LastIndexOf('?'));
178 | url = url.Substring(0, url.LastIndexOf('/') + 1);
179 | return url;
180 | }
181 |
182 | ///
183 | /// 拼接Baseurl和RelativeUrl
184 | ///
185 | /// Baseurl
186 | /// RelativeUrl
187 | ///
188 | public string CombineURL(string baseurl, string url)
189 | {
190 | if (baseurl == "")
191 | baseurl = url;
192 |
193 | Uri uri1 = new Uri(baseurl); //这里直接传完整的URL即可
194 | Uri uri2 = new Uri(uri1, url);
195 | url = uri2.ToString();
196 |
197 | return url;
198 | }
199 | }
200 | }
201 |
--------------------------------------------------------------------------------
/M3U8URL2File/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using System.Reflection;
2 | using System.Resources;
3 | using System.Runtime.CompilerServices;
4 | using System.Runtime.InteropServices;
5 | using System.Windows;
6 |
7 | // 有关程序集的一般信息由以下
8 | // 控制。更改这些特性值可修改
9 | // 与程序集关联的信息。
10 | [assembly: AssemblyTitle("M3U8URL2File")]
11 | [assembly: AssemblyDescription("")]
12 | [assembly: AssemblyConfiguration("")]
13 | [assembly: AssemblyCompany("")]
14 | [assembly: AssemblyProduct("M3U8URL2File")]
15 | [assembly: AssemblyCopyright("Copyright © 2019")]
16 | [assembly: AssemblyTrademark("")]
17 | [assembly: AssemblyCulture("")]
18 |
19 | // 将 ComVisible 设置为 false 会使此程序集中的类型
20 | //对 COM 组件不可见。如果需要从 COM 访问此程序集中的类型
21 | //请将此类型的 ComVisible 特性设置为 true。
22 | [assembly: ComVisible(false)]
23 |
24 | //若要开始生成可本地化的应用程序,请设置
25 | //.csproj 文件中的 CultureYouAreCodingWith
26 | //例如,如果您在源文件中使用的是美国英语,
27 | //使用的是美国英语,请将 设置为 en-US。 然后取消
28 | //对以下 NeutralResourceLanguage 特性的注释。 更新
29 | //以下行中的“en-US”以匹配项目文件中的 UICulture 设置。
30 |
31 | //[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
32 |
33 |
34 | [assembly: ThemeInfo(
35 | ResourceDictionaryLocation.None, //主题特定资源词典所处位置
36 | //(未在页面中找到资源时使用,
37 | //或应用程序资源字典中找到时使用)
38 | ResourceDictionaryLocation.SourceAssembly //常规资源词典所处位置
39 | //(未在页面中找到资源时使用,
40 | //、应用程序或任何主题专用资源字典中找到时使用)
41 | )]
42 |
43 |
44 | // 程序集的版本信息由下列四个值组成:
45 | //
46 | // 主版本
47 | // 次版本
48 | // 生成号
49 | // 修订号
50 | //
51 | //可以指定所有这些值,也可以使用“生成号”和“修订号”的默认值
52 | //通过使用 "*",如下所示:
53 | // [assembly: AssemblyVersion("1.0.*")]
54 | [assembly: AssemblyVersion("1.0.0.0")]
55 | [assembly: AssemblyFileVersion("1.0.0.0")]
56 |
--------------------------------------------------------------------------------
/M3U8URL2File/Properties/Resources.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // 此代码由工具生成。
4 | // 运行时版本: 4.0.30319.42000
5 | //
6 | // 对此文件的更改可能导致不正确的行为,如果
7 | // 重新生成代码,则所做更改将丢失。
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace M3U8URL2File.Properties
12 | {
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", "4.0.0.0")]
23 | [global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
24 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
25 | internal class Resources
26 | {
27 |
28 | private static global::System.Resources.ResourceManager resourceMan;
29 |
30 | private static global::System.Globalization.CultureInfo resourceCulture;
31 |
32 | [global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
33 | internal Resources()
34 | {
35 | }
36 |
37 | ///
38 | /// 返回此类使用的缓存 ResourceManager 实例。
39 | ///
40 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
41 | internal static global::System.Resources.ResourceManager ResourceManager
42 | {
43 | get
44 | {
45 | if ((resourceMan == null))
46 | {
47 | global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("M3U8URL2File.Properties.Resources", typeof(Resources).Assembly);
48 | resourceMan = temp;
49 | }
50 | return resourceMan;
51 | }
52 | }
53 |
54 | ///
55 | /// 覆盖当前线程的 CurrentUICulture 属性
56 | /// 使用此强类型的资源类的资源查找。
57 | ///
58 | [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
59 | internal static global::System.Globalization.CultureInfo Culture
60 | {
61 | get
62 | {
63 | return resourceCulture;
64 | }
65 | set
66 | {
67 | resourceCulture = value;
68 | }
69 | }
70 | }
71 | }
72 |
--------------------------------------------------------------------------------
/M3U8URL2File/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 |
--------------------------------------------------------------------------------
/M3U8URL2File/Properties/Settings.Designer.cs:
--------------------------------------------------------------------------------
1 | //------------------------------------------------------------------------------
2 | //
3 | // This code was generated by a tool.
4 | // Runtime Version:4.0.30319.42000
5 | //
6 | // Changes to this file may cause incorrect behavior and will be lost if
7 | // the code is regenerated.
8 | //
9 | //------------------------------------------------------------------------------
10 |
11 | namespace M3U8URL2File.Properties
12 | {
13 |
14 |
15 | [global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
16 | [global::System.CodeDom.Compiler.GeneratedCodeAttribute("Microsoft.VisualStudio.Editors.SettingsDesigner.SettingsSingleFileGenerator", "11.0.0.0")]
17 | internal sealed partial class Settings : global::System.Configuration.ApplicationSettingsBase
18 | {
19 |
20 | private static Settings defaultInstance = ((Settings)(global::System.Configuration.ApplicationSettingsBase.Synchronized(new Settings())));
21 |
22 | public static Settings Default
23 | {
24 | get
25 | {
26 | return defaultInstance;
27 | }
28 | }
29 | }
30 | }
31 |
--------------------------------------------------------------------------------
/M3U8URL2File/Properties/Settings.settings:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # M3U8URL2File
2 | m3u8链接批量下载器
3 |
4 | ## 功能如下
5 | 
6 |
--------------------------------------------------------------------------------