Ejemplo n.º 1
0
        private static byte[] GetImage(string title, string htmlCode)
        {
            var videoGetter = new YouTubeGetter();

            byte[] image = videoGetter.GetThumbailImage(htmlCode);

            if (image == null)
            {
                Console.WriteLine("Не смогли получить изображение или изменить размер изображения для видео \"{0}\"!",
                                  title);
            }
            return(image);
        }
Ejemplo n.º 2
0
        private static string GetHtmlCode(string htmlCode)
        {
            if (string.IsNullOrEmpty(htmlCode))
            {
                return(htmlCode);
            }

            if (!htmlCode.StartsWith("<iframe", StringComparison.InvariantCultureIgnoreCase))
            {
                //в качестве секции указан только идентификатор видео
                var videoGetter = new YouTubeGetter();
                htmlCode = videoGetter.GetFrameHtmlById(htmlCode);
            }
            return(htmlCode);
        }
Ejemplo n.º 3
0
        public VideoForUser ReadSubtitles()
        {
            string[] lines;
            if (!IsFileValid(out lines))
            {
                return(null);
            }

            if (lines.Length > 2)
            {
                Console.WriteLine("В файле {0} уже есть субтитры", _fileName);
                return(null);
            }

            var videoGetter = new YouTubeGetter();

            StringBuilder rows = videoGetter.GetSubtitles(lines[1]);

            if (rows == null)
            {
                Console.WriteLine("Для файла {0} не удалось получить субтитры", _fileName);
            }

            VideoForUser result = null;

            if (rows != null && rows.Length > 0)
            {
                if (!lines[lines.Length - 1].EndsWith(Environment.NewLine))
                {
                    rows.Insert(0, Environment.NewLine);
                }
                try {
                    rows.Length = rows.Length - Environment.NewLine.Length;
                    string text = rows.ToString();
                    File.AppendAllText(_fileName, text);
                    result = Read();
                    Console.WriteLine("Файл {0} успешно обработан", _fileName);
                } catch (Exception e) {
                    Console.WriteLine("Для файла {0} не удалось записать субтитры. Исключение:\r\n{1}",
                                      _fileName, e);
                }
            }
            return(result);
        }