Example #1
0
        private static bool ParseArgs(string[] arguments)
        {
            bool showKeys = false;

            if (arguments.Length > 0)
            {
                Dictionary <string, string> args = ArgsParser.ParseArgs(arguments, 0, validArgs);
                foreach (KeyValuePair <string, string> kvp in args)
                {
                    string data = kvp.Value;
                    switch (kvp.Key)
                    {
                    case "-h":
                        return(false);

                    case "-i":
                        showURL = true;
                        break;

                    case "-k":
                        showKeys = true;
                        break;

                    case "-w":
                        if (data.Length > 0)
                        {
                            argWindow = "--win \"" + data.Replace("\"", "") + "\"";
                            Helpers.Insert("youtube.conf", "--win", argWindow);
                        }
                        else
                        {
                            Console.WriteLine("Deleting Screen Resolution Settings.");
                            File.Delete("youtube.conf");
                        }
                        break;

                    case "-o":
                        if (data.Length > 0)
                        {
                            argOutType = "-o " + data.Split(' ')[0];
                        }
                        else
                        {
                            argOutType = "-o local";
                        }
                        break;

                    case "-p":
                        TimeSpan ts = new TimeSpan(0, int.Parse(data), 0);
                        argStartTime = "--start=" + ts.ToString("hh\\:mm\\:ss");
                        break;
                    }
                }

                if (argWindow.Length > 0)
                {
                    Console.WriteLine("Saving Window Size. ( " + argWindow + ")");
                }
                if (showKeys)
                {
                    Console.WriteLine(OMX_KEY_INFO);
                    Console.WriteLine("\r\n\tUsage: youtube [URL] [OPTIONS]\r\n");
                }
            }
            return(true);
        }
Example #2
0
        public static void Main(string[] args)
        {
            if (args != null && args.Length > 0)
            {
                if (!ParseArgs(args))
                {
                    ArgsParser.PrintUsedArgs("youtube.exe", validArgs, argInfos);
                    return;
                }
            }
            //else
            //{
            //    ArgsParser.PrintUsedArgs("youtube.exe [URL]", validArgs, argInfos);
            //    return;
            //}
            string tosearch = "";

            if (File.Exists("youtube.conf"))
            {
                Console.WriteLine("Reading \"youtube.conf\"");
                string[] sarr = File.ReadAllLines("youtube.conf");
                foreach (string s in sarr)
                {
                    if (s.StartsWith("--win"))
                    {
                        argWindow = s;
                    }
                    else if (s.StartsWith("last:"))
                    {
                        tosearch = s.Split(':')[1];
                    }
                }
            }
            Console.Clear();
            Console.WriteLine("Enter search term:");
            tosearch = Console.ReadLine();

            string channelName = "";

            VideoInfo[] videos = VideoInfo.Search_YT_Videos(tosearch, out channelName);
            Menue       vMenue = new Menue("Videos for " + channelName, videos.Select(x => x.Title).ToArray());

            Console.Clear();
            int idx = -1;

            idx = vMenue.Update();
            if (idx >= 0)
            {
                Console.Clear();
                if (Helpers.IsLinux || showURL)
                {
                    Console.WriteLine("Loading URL-Dictionary.");
                    URL_Escape.LoadDict();
                }
                string videoURL = "";
                if (Helpers.IsLinux || showURL)
                {
                    Console.WriteLine("Fetching Youtube Video-Url.");

                    videoURL = GetVideoFromUrl(videos[vMenue.Index].Video_Url);
                    videoURL = URL_Escape.ReplaceAll(videoURL);

                    if (showURL)
                    {
                        Console.WriteLine();
                        Console.WriteLine("Video URL:");
                        Console.WriteLine(videoURL);
                        Console.WriteLine();
                    }
                }

                Console.WriteLine("Starting Player.");
                Console.WriteLine();

                Process p = new Process();
                if (Helpers.IsLinux)
                {
                    p.StartInfo.FileName  = "mpv";// "omxplayer";
                    p.StartInfo.Arguments = videoURL + " " + argStartTime;
                    //"--live " + argStartTime + " " + argWindow + " " + argOutType + " " + videoURL;
                }
                else
                {
                    p.StartInfo.FileName  = "mpv.exe";
                    p.StartInfo.Arguments = videos[vMenue.Index].Video_Url + " " + argStartTime;
                }
                p.StartInfo.UseShellExecute = false;
                p.Start();

                while (!p.HasExited)
                {
                    if (Console.KeyAvailable)
                    {
                        Console.Clear();
                        if (Console.ReadKey().Key == ConsoleKey.Escape)
                        {
                            p.Close();
                            return;
                        }
                        Console.SetCursorPosition(0, Console.BufferHeight - 10);
                    }
                    else
                    {
                        System.Threading.Thread.Sleep(100);
                    }
                }
            }
            else if (idx == -2)
            {
                Main(new string[0]);
            }
        }