private static void Main(string[] args) { try { #region [.set SecurityProtocol to 'Tls + Tls11 + Tls12 + Ssl3'.] ServicePointManager.SecurityProtocol = (SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12 | SecurityProtocolType.Ssl3); #endregion var M3U8_FILE_URL = ConfigurationManager.AppSettings["M3U8_FILE_URL"]; if (M3U8_FILE_URL.IsNullOrWhiteSpace()) { throw (new ArgumentNullException(nameof(M3U8_FILE_URL))); } var OUTPUT_FILE_DIR = ConfigurationManager.AppSettings["OUTPUT_FILE_DIR"]; if (OUTPUT_FILE_DIR.IsNullOrWhiteSpace()) { OUTPUT_FILE_DIR = @"E:\\"; } var OUTPUT_FILE_EXT = ConfigurationManager.AppSettings["OUTPUT_FILE_EXT"]; if (OUTPUT_FILE_EXT.IsNullOrWhiteSpace()) { OUTPUT_FILE_EXT = ".avi"; } //---v1.run( M3U8_FILE_URL, OUTPUT_FILE_DIR, OUTPUT_FILE_EXT ); //v2.run__v1( M3U8_FILE_URL, OUTPUT_FILE_DIR, OUTPUT_FILE_EXT ); //v2.run__v2( M3U8_FILE_URL, OUTPUT_FILE_DIR, OUTPUT_FILE_EXT ); using (var cts = new CancellationTokenSource()) { var outputFileName = Path.Combine(OUTPUT_FILE_DIR, PathnameCleaner.CleanPathnameAndFilename(M3U8_FILE_URL).TrimStart('-') + OUTPUT_FILE_EXT); v3.run(M3U8_FILE_URL, outputFileName, cts).WaitForTaskEndsOrKeyboardBreak(cts); } } catch (Exception ex) { CONSOLE.WriteLineError("ERROR: " + ex); } CONSOLE.WriteLine("\r\n\r\n[.....finita fusking comedy.....]\r\n\r\n", ConsoleColor.DarkGray); CONSOLE.ReadLine(); }
private static void Main(string[] args) { try { var M3U8_FILE_URL = ConfigurationManager.AppSettings["M3U8_FILE_URL"]; if (M3U8_FILE_URL.IsNullOrWhiteSpace()) { throw (new ArgumentNullException(nameof(M3U8_FILE_URL))); } var OUTPUT_FILE_DIR = ConfigurationManager.AppSettings["OUTPUT_FILE_DIR"]; if (OUTPUT_FILE_DIR.IsNullOrWhiteSpace()) { OUTPUT_FILE_DIR = Environment.CurrentDirectory; } var OUTPUT_FILE_EXT = ConfigurationManager.AppSettings["OUTPUT_FILE_EXT"]; if (OUTPUT_FILE_EXT.IsNullOrWhiteSpace()) { OUTPUT_FILE_EXT = ".avi"; } //----------------------------------------------------------------------------------// CONSOLE.WriteLine($"M3U8-FILE-URL: '{M3U8_FILE_URL}'..."); CONSOLE.WriteLine("(press 'escape' for cancel)\r\n", ConsoleColor.DarkGray); using (var cts = new CancellationTokenSource()) { var outputFileName = Path.Combine(OUTPUT_FILE_DIR, PathnameCleaner.CleanPathnameAndFilename(M3U8_FILE_URL).TrimStart('-') + OUTPUT_FILE_EXT); var ip = new m3u8_processor.DownloadFileAndSaveInputParams() { Cts = cts, m3u8FileUrl = M3U8_FILE_URL, OutputFileName = outputFileName, MaxDegreeOfParallelism = 64, NetParams = new m3u8_client.init_params() { AttemptRequestCount = 3, Timeout = TimeSpan.FromSeconds(30), ConnectionClose = false, }, RequestStepAction = new m3u8_processor.RequestStepActionDelegate(p => { var msg = $"{p.PartOrderNumber} of {p.TotalPartCount}, '{p.Part.RelativeUrlName}'"; if (p.Error != null) { CONSOLE.WriteLineError(msg + $" => {p.Error}"); } else { CONSOLE.WriteLine(msg); } }), ResponseStepAction = new m3u8_processor.ResponseStepActionDelegate(p => { if (p.Part.Error != null) { CONSOLE.WriteLineError($" => {p.Part.Error}"); } }), }; var res = m3u8_processor.DownloadFileAndSave_Async(ip).WaitForTaskEndsOrKeyboardBreak(cts); CONSOLE.WriteLine($"\r\nM3U8-FILE-URL: '{res.m3u8FileUrl}'"); CONSOLE.WriteLine($"OutputFileName: '{res.OutputFileName}'"); CONSOLE.WriteLine($"OutputFileName-Size: {(res.TotalBytes >> 20)}mb"); CONSOLE.WriteLine($"Total-Parts: {res.TotalParts}, Success: {res.PartsSuccessCount}, Error: {res.PartsErrorCount}"); } } catch (Exception ex) { CONSOLE.WriteLineError("ERROR: " + ex); } CONSOLE.WriteLine("\r\n\r\n[.....finita fusking comedy.....]\r\n\r\n", ConsoleColor.DarkGray); CONSOLE.ReadLine(); }