예제 #1
0
 protected override void OnFinished()
 {
     AppData.save_to_file(apps, _appsFileName);
     DeveloperData.Serialize(developers, _developersFileName);
     SaveExceptions(_exceptionsPath, _exceptions);
     YoutubeData.save_to_file(_videos, _videoFileName);
 }
예제 #2
0
        private void ProcessVideoId(WebClient webClient, string videoId)
        {
            if (videoId != "")
            {
                string       url      = YoutubeData.ConvertIdToUrl(videoId);
                string       html     = webClient.DownloadString(url);
                HtmlDocument document = new HtmlDocument();
                document.LoadHtml(html);
                YoutubeData video = new YoutubeData(document, videoId);
                if (video.publishDate == "" || video.viewsNumber == -1)
                {
                    html     = webClient.DownloadString(url);
                    document = new HtmlDocument();
                    document.LoadHtml(html);
                    video = new YoutubeData(document, videoId);
                    if (!(video.publishDate == "" || video.viewsNumber == -1))
                    {
                        Interlocked.Increment(ref _successfulVideoReloadings);
                    }
                    else
                    {
                        Interlocked.Increment(ref _unsuccessfulVideoReloadings);
                    }
                }

                lock (_videos)
                {
                    _videos.Add(video);
                }
                SavePage(_videoPath, html, videoId);
            }
        }
예제 #3
0
        public static List <YoutubeData> load_from_file(string file_name)
        {
            List <YoutubeData> result = new List <YoutubeData>();

            using (StreamReader file = new StreamReader(file_name))
            {
                string line, header;
                if ((line = file.ReadLine()) != null)
                {
                    header = line;
                }
                while ((line = file.ReadLine()) != null)
                {
                    string[] parts = line.Split(';');
                    if (parts.Length == fields.Count())
                    {
                        YoutubeData video = new YoutubeData();

                        for (int i = 0; i < fields.Count(); ++i)
                        {
                            fields[i].SetValue(video, Convert.ChangeType(parts[i], fields[i].FieldType));
                        }
                        result.Add(video);
                    }
                    else
                    {
                        Debug.Print("YoutubeData: parts.Length != fields.Count()");
                    }
                }
            }
            return(result);
        }
예제 #4
0
        public static void Test(WebClient webClient)
        {
            string       url = @"https://www.youtube.com/watch?v=9bZkp7q19f0";
            HtmlDocument doc = new HtmlDocument();

            doc.LoadHtml(webClient.DownloadString(url));
            YoutubeData youtubeData = new YoutubeData(doc, url);
        }