Beispiel #1
0
        public Form1()
        {
            InitializeComponent();

            //textBox1.Text = tester.Tester();
            SubscriptionsFetcher subFetcherObj = new SubscriptionsFetcher();
            Settings settingsObj = new Settings();
            var strO = subFetcherObj.GetListOfSubscriptions(settingsObj);
            textBox1.Text = subFetcherObj.GetTextSubscriptions(strO);

            VideoDownloader vDownObj = new VideoDownloader();
            vDownObj.StartDownloading(strO, settingsObj);
        }
        internal List<KeyValuePair<string, List<Video>>> GetListOfSubscriptions(Settings i_settings)
        {
            List<KeyValuePair<string, List<Video>>> resObj = new  List<KeyValuePair<string, List<Video>>> ();

            YouTubeRequestSettings settings = new YouTubeRequestSettings(
                  i_settings.appName
                , i_settings.devKey
                , i_settings.username
                , i_settings.password);

            YouTubeRequest request = new YouTubeRequest(settings);
            Feed<Subscription> feedOfSubcr = request.GetSubscriptionsFeed(i_settings.userShort);

            string[] stringSeparators = new string[] { "Activity of:" };

            foreach (Subscription subItem in feedOfSubcr.Entries)
            {
                string keyStr = subItem.ToString().Split(stringSeparators, StringSplitOptions.None)[1].Trim();
                List<Video> listOfVideos = new List<Video>();

                string userName = subItem.UserName;
                string url = string.Format(i_settings.urlFormatter, userName);

                Feed<Video> videoFeed = request.Get<Video>(new Uri(url));

                int depth = 0;
                foreach (Video entry in videoFeed.Entries)
                {
                    //strBuilder.AppendLine("    " + entry.Title);
                    listOfVideos.Add(entry);
                    depth++;
                    if (depth >= i_settings.feedDepth)
                    {
                        break;
                    }
                }

                if (listOfVideos.Count > 0)
                {
                    KeyValuePair<string, List<Video>> subscriptionO = new KeyValuePair<string, List<Video>>(keyStr, listOfVideos);
                    resObj.Add(subscriptionO);
                }

            }

            return resObj;
        }
        internal void StartDownloading(List<KeyValuePair<string, List<Google.YouTube.Video>>> i_videosCollection, Settings i_settingsObj)
        {
            string rootPath = i_settingsObj.rootSaveDir;
            string nextSaveDirName = "";
            string nextSaveDirPath = "";

            foreach (var kvPair in i_videosCollection)
            {
                nextSaveDirName = getDirName(kvPair.Key);
                nextSaveDirPath = Path.Combine(rootPath, nextSaveDirName);

                if (!Directory.Exists(nextSaveDirPath)) { Directory.CreateDirectory(nextSaveDirPath); }

                foreach (Video videoItem in kvPair.Value)
                {
                    saveVideo(videoItem, nextSaveDirPath);
                }
            }
        }