尝试从URL或文件读取文件名

This commit is contained in:
nilaoda 2022-08-31 00:20:49 +08:00
parent 6e59dfd679
commit 9bdb1c77c0
1 changed files with 30 additions and 6 deletions

View File

@ -276,12 +276,31 @@ 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
};
if (!livingFlag)
{
//开始下载
var sdm = new SimpleDownloadManager(downloadConfig);
var result = await sdm.StartDownloadAsync(selectedStreams);
@ -290,6 +309,11 @@ namespace N_m3u8DL_RE
else
Logger.ErrorMarkUp("[white on red]Faild[/]");
}
else
{
throw new NotSupportedException("Live not supported yet.");
}
}
catch (Exception ex)
{
string msg = Logger.LogLevel == LogLevel.DEBUG ? ex.ToString() : ex.Message;