From 9bdb1c77c0bce55a26f85fec17465a9bfcb3cd28 Mon Sep 17 00:00:00 2001 From: nilaoda Date: Wed, 31 Aug 2022 00:20:49 +0800 Subject: [PATCH] =?UTF-8?q?=E5=B0=9D=E8=AF=95=E4=BB=8EURL=E6=88=96?= =?UTF-8?q?=E6=96=87=E4=BB=B6=E8=AF=BB=E5=8F=96=E6=96=87=E4=BB=B6=E5=90=8D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/N_m3u8DL-RE/Program.cs | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) diff --git a/src/N_m3u8DL-RE/Program.cs b/src/N_m3u8DL-RE/Program.cs index 3acd6d3..05e7ea8 100644 --- a/src/N_m3u8DL-RE/Program.cs +++ b/src/N_m3u8DL-RE/Program.cs @@ -276,19 +276,43 @@ namespace N_m3u8DL_RE Console.ReadKey(); #endif + //尝试从URL或文件读取文件名 + if (string.IsNullOrEmpty(option.SaveName)) + { + if (File.Exists(option.Input)) + { + option.SaveName = Path.GetFileNameWithoutExtension(option.Input) + "_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); + } + else + { + var uri = new Uri(option.Input); + var name = uri.GetLeftPart(UriPartial.Path).Split('/').Last(); + name = string.Join(".", name.Split('.').SkipLast(1)).Trim('.'); + option.SaveName = ConvertUtil.GetValidFileName(name) + "_" + DateTime.Now.ToString("yyyy-MM-dd_HH-mm-ss"); + } + } + //下载配置 var downloadConfig = new DownloaderConfig() { MyOptions = option, Headers = parserConfig.Headers, //使用命令行解析得到的Headers }; - //开始下载 - var sdm = new SimpleDownloadManager(downloadConfig); - var result = await sdm.StartDownloadAsync(selectedStreams); - if (result) - Logger.InfoMarkUp("[white on green]Done[/]"); + + if (!livingFlag) + { + //开始下载 + var sdm = new SimpleDownloadManager(downloadConfig); + var result = await sdm.StartDownloadAsync(selectedStreams); + if (result) + Logger.InfoMarkUp("[white on green]Done[/]"); + else + Logger.ErrorMarkUp("[white on red]Faild[/]"); + } else - Logger.ErrorMarkUp("[white on red]Faild[/]"); + { + throw new NotSupportedException("Live not supported yet."); + } } catch (Exception ex) {