Exemple #1
0
        static void Download(string link, string path, Vidlib s)
        {
            string FinalFolder = "";
            string Thumbnail   = "";

            string ID = link.Substring(link.LastIndexOf("=") + 1);

            //   Console.WriteLine(ID);
            if (File.Exists(ID + ".json"))
            {
                File.Delete((ID + ".json"));
            }

            s.MakeVideoRequest(ID);
            while (!File.Exists(ID + ".json") && !error)
            {
                Thread.Sleep(50);
            }
            if (error)
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("Error Encountered while downloading json metadata");
            }
            //    Console.WriteLine("JSON");
            while (IsFileLocked(ID + ".json"))
            {
                Thread.Sleep(50);
            }
            string    JSONdata = File.ReadAllText(ID + ".json");
            VideoJSON Meta     = new JavaScriptSerializer().Deserialize <VideoJSON>(JSONdata);

            s.SaveJSON(Meta, "jsontest.json");
            string ProcessedFolder = ProcessPath(path, Meta, "");

            //  Console.WriteLine(ProcessedFolder);
            // Console.WriteLine(ProcessedFolder);
            Directory.CreateDirectory(ProcessedFolder.Substring(0, ProcessedFolder.LastIndexOf("\\")));
            // Console.WriteLine("Directory Created");
            if (!StringContainsFromList(Archive, ID))
            {
                if (Video)
                {
                    string VideoLink = CDN + ID + "." + Meta.file;
                    if (HQ && s.Check204(VideoLink))
                    {
                        VideoLink += ".720";
                    }
                    VideoLink += ".mp4";
                    //Console.WriteLine("Downloading " + VideoLink);
                    //   Console.WriteLine(ProcessPath(path, Meta, ".mp4"));

                    DownLoadFileBG(VideoLink, ProcessPath(path, Meta, ".mp4"));
                }
                if (Thumb)
                {
                    Thumbnail = s.GetThumbnailLink(link);
                    //   Console.WriteLine(Thumbnail);
                    //   File.WriteAllText("test.txt", Thumbnail);
                    //Console.WriteLine(ProcessPath(path, Meta, ".jpg"));
                    //  Console.WriteLine("Downloading " + Thumbnail);
                    DownLoadFileBG(Thumbnail, ProcessPath(path, Meta, ".jpg"));
                    // Console.WriteLine(ProcessPath(path, Meta, ".jpg"));
                }

                if (saveprogress)
                {
                    Archive.Add(ID);
                }
            }
            else
            {
                Console.WriteLine(Meta.title + " recorded in archive, not necessary to download");
            }
            if (Metadata)
            {
                //  Console.WriteLine(ProcessPath(path, Meta, ".json"));

                if (File.Exists(ProcessPath(path, Meta, ".json")))
                {
                    while (IsFileLocked(ProcessPath(path, Meta, ".json")))
                    {
                        Thread.Sleep(50);
                    }
                    File.Delete(ProcessPath(path, Meta, ".json"));
                }
                File.Copy("jsontest.json", ProcessPath(path, Meta, ".json"));
                //File.Copy("jsontest.json",)
                //  Console.WriteLine("Copied JSON");
            }
            if (saveprogress)
            {
                File.WriteAllLines(Archivefile, Archive);
            }


            if (File.Exists(ID + ".json"))
            {
                while (IsFileLocked(ID + ".json"))
                {
                    Thread.Sleep(50);
                }
                File.Delete(ID + ".json");
            }
        }
Exemple #2
0
        static void Main(string[] args)
        {
            Vidlib s = new Vidlib();

            //    DownLoadFileBG("https://i.r.worldssl.net/usfi/v/dGOn0zLQ9DK.3q8vaXQ5L9csuO7ed4OYhNaeTsLyJN-lkv2bYmmA6um5XzqCkx6js9IZiGAAC9_rOQLgCarvA-3HKLb6.mp4", "x\\Succ.mp4");
            //  Console.ReadLine();
            if (ScreenArguments(args, "-get-thumb"))
            {
                Thumb = true;
                //  Console.WriteLine("Tag");
            }
            if (ScreenArguments(args, "-archive"))
            {
                Archivefile = args[ScreenArgumentsLoc(args, "-archive")];

                saveprogress = true;
                if (File.Exists(Archivefile))
                {
                    using (StreamReader reader = new StreamReader(Archivefile))
                    {
                        while (!reader.EndOfStream)
                        {
                            Archive.Add(reader.ReadLine());
                        }
                    }
                }


                //   if (!File.Exists(Archivefile)) File.Create(Archivefile);
                //  Console.WriteLine("Tag");
            }
            if (ScreenArguments(args, "-help"))
            {
                Metadata = true;
                const int pad = 15;
                //  Console.WriteLine("Tag");
                Console.WriteLine("Usage:   \nVidlib.exe [misc arguments] [-archive <file>] -path <location>\n<Link/path to file with links> \n");
                Console.WriteLine("Arguments:\n");
                Console.Write(PadFormat("-HQ", pad));
                Console.WriteLine("Downloads the 720p version of the video if possible");
                Console.Write(PadFormat("-get-thumb", pad));
                Console.WriteLine("Downloads the thumbnail");
                Console.Write(PadFormat("-save-metadata", pad));
                Console.WriteLine("Saves the json metadata of the video");
                Console.Write(PadFormat("-no-video", pad));
                Console.WriteLine("skips downloading the video file (useful for updating metadata)");
                Console.Write(PadFormat("-path <file>", pad));
                Console.WriteLine("A mandatory argument, followed by the path to the file,");
                Console.Write(PadFormat(" ", pad));
                Console.WriteLine("path takes special arguments to generate the file location");
                Console.Write(PadFormat("   @[url]", pad + 5));
                Console.WriteLine("video id");
                Console.Write(PadFormat("   @[file]", pad + 5));
                Console.WriteLine("CDN server file id");
                Console.Write(PadFormat("   @[title]", pad + 5));
                Console.WriteLine("video title");
                Console.Write(PadFormat("   @[category]", pad + 5));
                Console.WriteLine("Video Category");
                Console.Write(PadFormat("   @[uploaded_by]", pad + 5));
                Console.WriteLine("Uploader");
                Console.Write(PadFormat("   @[uploaded_on]", pad + 5));
                Console.WriteLine("Upload date");
                Console.Write(PadFormat("   @[ext]", pad + 5));
                Console.WriteLine("Extension (MANDATORY)\n");
                Console.Write(PadFormat("-archive <filename>", pad + 5));
                Console.WriteLine("saves the downloaded video id to a file so that you don't download it again.");
                Console.ReadLine();
                return;
            }
            if (ScreenArguments(args, "-save-metadata"))
            {
                Metadata = true;
                //  Console.WriteLine("Tag");
            }
            if (ScreenArguments(args, "-HQ"))
            {
                HQ = true;
                //  Console.WriteLine("Tag");
            }
            if (ScreenArguments(args, "-no-video"))
            {
                Video = false;
                //  Console.WriteLine("Tag");
            }
            string UPath = "";

            if (ScreenArguments(args, "-path"))
            {
                UPath = args[ScreenArgumentsLoc(args, "-path")];
                path  = UPath;

                Console.WriteLine(path);
                if (path.Contains("@["))
                {
                    path = path.Substring(0, path.IndexOf("@["));
                }
                if (!Directory.Exists(path))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Location Does not exist");
                    Console.ReadLine();
                }
                if (!UPath.Contains("@[ext]"))
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("WARNING: PATH NEEDS @[ext] FOR THE PROGRAM TO WORK");
                    Console.ReadLine();
                }
            }
            else
            {
                Console.ForegroundColor = ConsoleColor.Red;
                Console.WriteLine("WARNING: Program needs path argument to work");
                Console.ForegroundColor = ConsoleColor.White;
                Console.WriteLine("Run with -help to print syntax");
                Console.ReadLine();
            }
            string link = args[args.Length - 1];



            //console.ReadLine();
            if (link.Contains("watch") || link.Contains("user"))
            {
                if (link.Contains("vidlii.com"))
                {
                    if (link.Contains("watch") && link.Contains("="))
                    {
                        path = UPath;
                        Download(link, path, s);
                    }
                    else if (link.Contains("user"))
                    {
                        bool finished = false;
                        int  page     = 0;
                        while (!finished)
                        {
                            WebClient client = new WebClient();
                            System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                            client.DownloadFile(link, "channelraw.html");
                            string extractedID = Scanforid("channelraw.html");
                            if (File.Exists(extractedID))
                            {
                                File.Delete((extractedID));
                            }
                            s.MakeRequest(extractedID, page.ToString());
                            //    Console.ReadLine();
                            Console.WriteLine("Requesting Metadata");
                            while (!File.Exists(extractedID))
                            {
                                Thread.Sleep(50);
                            }
                            if (error)
                            {
                                Console.ForegroundColor = ConsoleColor.Red;
                                Console.WriteLine("Error Encountered while downloading json metadata");
                            }
                            Console.WriteLine("File found");
                            foreach (string X in File.ReadAllLines(extractedID))
                            {
                                if (X == "finished")
                                {
                                    finished = true;
                                    break;
                                }
                                path = UPath;
                                if (!string.IsNullOrWhiteSpace(X))
                                {
                                    Download("https://www.vidlii.com/watch?v=" + X, path, s);
                                }
                            }
                            page++;
                        }
                    }
                    else
                    {
                        Console.ForegroundColor = ConsoleColor.Red;
                        Console.WriteLine("This type of vidlii link is not supported");
                        Console.ReadLine();
                    }
                }
            }
            else
            {
                Console.WriteLine(link);

                if (File.Exists(link))
                {
                    foreach (string fileline in File.ReadAllLines(link))
                    {
                        if (!string.IsNullOrWhiteSpace(fileline))
                        {
                            link = fileline;

                            if (link.Contains("vidlii.com"))
                            {
                                if (link.Contains("watch") && link.Contains("="))
                                {
                                    path = UPath;
                                    Download(link, path, s);
                                }
                                else if (link.Contains("user"))
                                {
                                    bool finished = false;
                                    int  page     = 0;
                                    while (!finished)
                                    {
                                        WebClient client = new WebClient();
                                        System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                                        client.DownloadFile(link, "channelraw.html");
                                        string extractedID = Scanforid("channelraw.html");
                                        if (File.Exists(extractedID))
                                        {
                                            File.Delete((extractedID));
                                        }
                                        s.MakeRequest(extractedID, page.ToString());
                                        //    Console.ReadLine();
                                        Console.WriteLine("Requesting Metadata");
                                        while (!File.Exists(extractedID))
                                        {
                                            Thread.Sleep(50);
                                        }
                                        if (error)
                                        {
                                            Console.ForegroundColor = ConsoleColor.Red;
                                            Console.WriteLine("Error Encountered while downloading json metadata");
                                        }
                                        Console.WriteLine("File found");
                                        foreach (string X in File.ReadAllLines(extractedID))
                                        {
                                            if (X == "finished")
                                            {
                                                finished = true;
                                                break;
                                            }
                                            path = UPath;
                                            if (!string.IsNullOrWhiteSpace(X))
                                            {
                                                Download("https://www.vidlii.com/watch?v=" + X, path, s);
                                            }
                                        }
                                        page++;
                                    }
                                }
                                else
                                {
                                    Console.ForegroundColor = ConsoleColor.Red;
                                    Console.WriteLine("This type of vidlii link is not supported");
                                    Console.ReadLine();
                                }
                            }
                        }
                    }
                }
                else
                {
                    Console.ForegroundColor = ConsoleColor.Red;
                    Console.WriteLine("Not a vidlii link/cannotfind file");
                    Console.ReadLine();
                }
            }
            Console.WriteLine("Download Finished");
            if (debug)
            {
                s.MakeRequest("moonman", "0");
                //s.MakeVideoRequest("X5rOJ7IVLaJ");
                s.MakeRequest(Console.ReadLine(), Console.ReadLine());
                string H2;
                H2 = Console.ReadLine();

                return;

                using (var client = new GetClient())
                {
                    System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
                    client.DownloadFile("https://www.vidlii.com/user/DhanesWara", "test");
                }


                Console.WriteLine(s.GetThumbnailLink("https://www.vidlii.com/watch?v=7f9sXjsG4at"));
                Console.WriteLine(s.GetVideoLink("https://www.vidlii.com/watch?v=7f9sXjsG4at", false));
                Console.ReadLine();
            }
            return;
        }