예제 #1
0
        public static void Main(string[] args)
        {
            System.Net.ServicePointManager.UseNagleAlgorithm = true;
            System.Net.ServicePointManager.CheckCertificateRevocationList = false;
            System.Net.ServicePointManager.DefaultConnectionLimit         = 20;
            System.Net.ServicePointManager.Expect100Continue = false;
            try {
                AppDomain.CurrentDomain.UnhandledException += (sender, e) => FatalExceptionObject(e.ExceptionObject);

                try {
                    isRedirected = Console.CursorVisible && false;
                } catch {
                    isRedirected = true;
                }
                if (isRedirected)
                {
                    Console.SetOut(new StreamWriter(Console.OpenStandardError())
                    {
                        AutoFlush = true
                    });
                }

                Check4Redirect2Process(ref args);

                CLI cli = new CLI(args);
                if (cli.ChkParam("help"))
                {
                    cli.DisplayHelpAndQuit();
                }
                if (cli.ChkParam("version"))
                {
                    cli.DisplayVersionAndQuit();
                }
                if (cli.ChkParam("waitkey"))
                {
                    waitkey = true;
                }
                if (cli.ChkParam("nowaitkey"))
                {
                    waitkey = false;
                }
                if (cli.ChkParam("filesize"))
                {
                    uint.TryParse(cli.GetParam("filesize"), out filesize);
                }
                if (cli.ChkParam("threads"))
                {
                    int.TryParse(cli.GetParam("threads"), out threads);
                }
                if (cli.ChkParam("start"))
                {
                    uint.TryParse(cli.GetParam("start"), out start);
                }
                if (cli.ChkParam("auth"))
                {
                    auth = "?" + cli.GetParam("auth");
                }
                if (cli.ChkParam("headers"))
                {
                    headers = cli.GetParam("headers");
                }
                if (cli.ChkParam("urlbase"))
                {
                    baseUrl = cli.GetParam("urlbase");
                }
                if (cli.ChkParam("quality"))
                {
                    quality = cli.GetParam("quality");
                }
                if (cli.ChkParam("manifest"))
                {
                    manifestUrl = cli.GetParam("manifest");
                }
                if (cli.ChkParam("outdir"))
                {
                    outDir = cli.GetParam("outdir");
                }
                if (cli.ChkParam("outfile"))
                {
                    outFile = cli.GetParam("outfile");
                }
                if (cli.ChkParam("logfile"))
                {
                    logfile = cli.GetParam("logfile");
                }
                if (cli.ChkParam("skip"))
                {
                    fromTimestamp = GetTimestampFromString(cli.GetParam("skip"));
                }
                if (cli.ChkParam("duration"))
                {
                    duration = GetTimestampFromString(cli.GetParam("duration"));
                }
                if (cli.ChkParam("debug"))
                {
                    debug = true;
                }
                if (cli.ChkParam("play"))
                {
                    play = true;
                }
                if (cli.ChkParam("showtime"))
                {
                    showtime = true;
                }
                if (cli.ChkParam("fproxy"))
                {
                    fproxy = true;
                }
                if (cli.ChkParam("continue"))
                {
                    fcontinue = true;
                }
                if (cli.ChkParam("verbose"))
                {
                    verbose = true;
                }
                if (cli.ChkParam("testalt"))
                {
                    testalt = true;
                }
                if (cli.ChkParam("quiet"))
                {
                    quiet = true;
                }
                if (cli.ChkParam("postdata"))
                {
                    postData = cli.GetParam("postdata");
                }
                if (cli.ChkParam("referer"))
                {
                    HTTP.Referer = cli.GetParam("referer");
                }
                if (cli.ChkParam("cookies"))
                {
                    HTTP.Cookies = cli.GetParam("cookies");
                }
                if (cli.ChkParam("useragent"))
                {
                    HTTP.Useragent = cli.GetParam("useragent");
                }
                if (cli.ChkParam("username"))
                {
                    HTTP.Username = cli.GetParam("username");
                }
                if (cli.ChkParam("password"))
                {
                    HTTP.Password = cli.GetParam("password");
                }
                if (cli.ChkParam("proxy"))
                {
                    HTTP.Proxy = cli.GetParam("proxy");
                }
                if (cli.ChkParam("proxyuser"))
                {
                    HTTP.ProxyUsername = cli.GetParam("proxyuser");
                }
                if (cli.ChkParam("proxypass"))
                {
                    HTTP.ProxyPassword = cli.GetParam("proxypass");
                }
                if (cli.ChkParam("osproxy"))
                {
                    HTTP.UseSystemProxy = true;
                }
                if (cli.ChkParam("adkey"))
                {
                    sessionKey = AkamaiDecryptor.Unhexlify(cli.GetParam("adkey"));
                }
                if (cli.ChkParam("lang"))
                {
                    lang = cli.GetParam("lang");
                }
                if (cli.ChkParam("alt"))
                {
                    alt = cli.GetParam("alt");
                }

                //if (HTTP.Referer == "") {
                //    var m = Regex.Match(manifestUrl, @"^(.*?://.*?/)");
                //    if (m.Success) HTTP.Referer = m.Groups[1].Value;
                //}

                if (!string.IsNullOrEmpty(headers))
                {
                    foreach (string header in headers.Split(new char[] { '|', '$' }))
                    {
                        Match m = Regex.Match(header, "(.*?):(.*)");
                        if (m.Success)
                        {
                            string name  = m.Groups[1].Value;
                            string value = m.Groups[2].Value;
                            switch (name.ToLower())
                            {
                            case "referer": HTTP.Referer = value; break;

                            case "useragent":
                            case "user-agent": HTTP.Useragent = value; break;

                            default: HTTP.Headers.Set(name, value); break;
                            }
                        }
                    }
                }

                ShowHeader("HDSdump by WendyH v<c:White>" + Version);

                if (manifestUrl == "")
                {
                    Quit("<c:Red>Please specify the manifest. (switch '<c:White>-h</c>' or '<c:White>--help</c>' for help message)");
                }

                if (showtime)
                {
                    ShowTimeElapsed("", true);
                }

                Check4KnownLinks(manifestUrl);
                cli.Params["manifest"] = manifestUrl;
                if (HTTP.Referer.Length > 0)
                {
                    cli.Params["referer"] = HTTP.Referer;
                }

                bool usePipe = outFile.IndexOf(@"\\.\pipe\") == 0;
                cli.Params["threads"] = threads.ToString();
                cli.Params["outfile"] = redir2Prog != null ? redir2Prog.ProcessName : (isRedirected && !usePipe ? "<redirected>" : outFile);
                cli.EchoSetsParameters();

                if (!cli.ChkParam("oldmethod"))
                {
                    HDSDumper HdsDumper = new HDSDumper();
                    HdsDumper.FLVFile.outFile       = outDir + outFile;
                    HdsDumper.FLVFile.play          = play;
                    HdsDumper.FLVFile.usePipe       = usePipe;
                    HdsDumper.Downloader.maxThreads = threads;
                    HdsDumper.duration      = duration;
                    HdsDumper.filesize      = filesize;
                    HdsDumper.start         = start;
                    HdsDumper.auth          = auth;
                    HdsDumper.baseUrl       = baseUrl;
                    HdsDumper.quality       = quality;
                    HdsDumper.postData      = postData;
                    HdsDumper.lang          = lang;
                    HdsDumper.alt           = alt;
                    HdsDumper.testalt       = testalt;
                    HdsDumper.fromTimestamp = fromTimestamp;
                    HdsDumper.sessionKey    = sessionKey;

                    if (fcontinue)
                    {
                        HdsDumper.FLVFile.GetLastTimestampFromExistingFile();
                        HdsDumper.fromTimestamp = HdsDumper.FLVFile.LastTimestamp;
                    }

                    if (ConsolePresent)
                    {
                        Console.CancelKeyPress += delegate {
                            HdsDumper?.ShowMessageAtTheEnd();
                            HdsDumper?.FixFileMetadata();
                        };
                    }

                    try {
                        Message("Processing manifest info...");
                        HdsDumper.StartDownload(manifestUrl);
                    } catch (Exception e) {
                        HdsDumper.DestroyUpdateStatusTimer();
                        Message("\r\n<c:Red>" + e.Message);
                    } finally {
                        HdsDumper.ShowMessageAtTheEnd();
                        HdsDumper.FixFileMetadata();
                    }
                    if (!string.IsNullOrEmpty(HdsDumper.Status))
                    {
                        Quit(HdsDumper.Status);
                    }
                    else
                    {
                        Quit("Done.");
                    }
                }

                // ========== OLD METHOD ==========
                F4FOldMethod f4f = new F4FOldMethod();
                // Disable metadata if it invalidates the stream duration
                if ((f4f.fromTimestamp > 0) || (start > 0) || (duration > 0) || (filesize > 0))
                {
                    f4f.metadata = false;
                }

                f4f.fromTimestamp = fromTimestamp;
                f4f.usePipe       = usePipe;
                f4f.play          = play;
                f4f.threads       = threads;
                f4f.duration      = (int)duration;
                f4f.filesize      = (int)filesize;
                f4f.start         = (int)start;
                f4f.ad.sessionKey = sessionKey;
                f4f.auth          = auth;
                f4f.baseUrl       = baseUrl;
                f4f.quality       = quality;
                f4f.PostData      = postData;
                f4f.Lang          = lang;
                f4f.alt           = alt;
                if (fcontinue)
                {
                    f4f.CheckLastTSExistingFile();
                }

                f4f.DownloadFragments(manifestUrl);
                Quit("Done.");
            } catch (Exception huh) {
                FatalExceptionObject(huh);
            }
        }