예제 #1
0
        public YoutubeVideo GetVideoById(string videoId)
        {
            YouTubeService service = new YouTubeService(_applicationName, _developerKey);
            string         url     = String.Format("{0}/{1}?v=2&", _videoUrl, videoId);

            YouTubeQuery searchQuery = new YouTubeQuery(url);

            var          result = service.Query(searchQuery);
            YouTubeEntry entry  = result.Entries.FirstOrDefault() as YouTubeEntry;

            var video = entry.ToYoutubeVideo();

            string commentUrl = String.Format("http://gdata.youtube.com/feeds/api/videos/{0}/comments?max-results={1}&start-index={2}", videoId, 50, 1);

            var            youTubeRequestSettings = new YouTubeRequestSettings(_applicationName, _developerKey);
            var            request  = new YouTubeRequest(youTubeRequestSettings);
            Feed <Comment> comments = request.Get <Comment>(new Uri(commentUrl));

            foreach (var item in comments.Entries)
            {
                video.Comments.Add(new YoutubeComment
                {
                    Author    = item.Author,
                    UpdatedOn = item.Updated,
                    Title     = item.Title,
                    Content   = item.Content,
                });
            }

            return(video);
        }
예제 #2
0
        public void YouTubeQueryPrivateTest()
        {
            Tracing.TraceMsg("Entering YouTubeQueryPrivateTest");

            YouTubeQuery   query   = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
            YouTubeService service = new YouTubeService("NETUnittests", this.ytDevKey);

            query.Query            = "Education expertvillage";
            query.NumberToRetrieve = 50;
            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd);
            }

            YouTubeFeed feed = service.Query(query);

            int counter = 0;

            foreach (YouTubeEntry e in feed.Entries)
            {
                Assert.IsTrue(e.Media.Title.Value != null, "There should be a title");
                if (e.Private)
                {
                    counter++;
                }
            }
            Assert.IsTrue(counter == 0, "counter was " + counter);
        }
예제 #3
0
        private void button1_Click(object sender, EventArgs e)
        {
            Uri          ur    = new Uri("http://gdata.youtube.com/feeds/api/videos/fSgGV1llVHM&f=gdata_playlists&c=ytapi-DukaIstvan-MyYouTubeVideosF-d1ogtvf7-0&d=U1YkMvELc_arPNsH4kYosmD9LlbsOl3qUImVMV6ramM");
            YouTubeQuery query = new YouTubeQuery("http://gdata.youtube.com/feeds/api/channels?q=vevo");



            YouTubeFeed  videoFeed = service.Query(query);
            YouTubeEntry en        = (YouTubeEntry)videoFeed.Entries[0];

            Video          video    = request.Retrieve <Video>(new Uri("http://gdata.youtube.com/feeds/api/videos/" + en.VideoId));
            Feed <Comment> comments = request.GetComments(video);
            string         cm       = "";

            foreach (Comment c in comments.Entries)
            {
                cm += c.Content + "\n------------------------------------------\n";
            }

            VideoInfo info = new VideoInfo();

            info.Get("yUHNUjEs7rQ");
            //Video v = request.Retrieve<Video>(videoEntryUrl);



            //Feed<Comment> comments = request.GetComments(v);

            //string cm = "";
            //foreach (Comment c in comments.Entries)
            //{
            //  cm += c.Author + c.Content + "------------------------------------------";
            //}
        }
예제 #4
0
        public static bool GetSongsByArtist(string artist, ref List <Song> songs, ref YouTubeFeed vidr)
        {
            Log.Debug("Youtube GetSongsByArtist for : {0}", artist);
            YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);

            //query.VQ = artist;
            query.Query = artist;
            //order results by the number of views (most viewed first)
            query.OrderBy = "relevance";
            //exclude restricted content from the search
            query.NumberToRetrieve = 20;
            //query.Racy = "exclude";
            query.SafeSearch = YouTubeQuery.SafeSearchValues.Strict;
            query.Categories.Add(new QueryCategory("Music", QueryCategoryOperator.AND));

            vidr = service.Query(query);
            foreach (YouTubeEntry entry in vidr.Entries)
            {
                if (entry.Title.Text.ToUpper().Contains(artist.ToUpper().Trim()) && entry.Title.Text.Contains("-"))
                {
                    songs.Add(YoutubeEntry2Song(entry));
                }
            }
            return(true);
        }
        private static YouTubeFeed GetYouTubeFeed(YouTubeQuery query)
        {
            var service = new YouTubeService(YouTubeConfiguration.Settings.Application.Name);

            service.setUserCredentials(YouTubeConfiguration.Settings.Authentication.Username, YouTubeConfiguration.Settings.Authentication.Password);

            return(service.Query(query));
        }
예제 #6
0
        private static void update(string queryTemplate, List <Item> videos, ref int counter, string category)
        {
            if (videos.Count != 0 || (counter % 20 != 0 && counter != 0))
            {
                counter = counter + 1;
                return;
            }

            counter = counter + 1;

            videos.Clear();
            int maxResults = 50;
            int startIndex = 1;

            string feedUrl = String.Format(queryTemplate, startIndex, maxResults);

            YouTubeQuery query     = new YouTubeQuery(feedUrl);
            YouTubeFeed  videoFeed = null;

            try
            {
                videoFeed = service.Query(query);
                while (videoFeed.Entries.Count > 0)
                {
                    parseFeed(videoFeed, videos);

                    startIndex += maxResults;
                    feedUrl     = String.Format(queryTemplate, startIndex, maxResults);
                    query       = new YouTubeQuery(feedUrl);
                    videoFeed   = service.Query(query);
                }
                startIndex = 1;
                Log <Youtube> .Debug("Finished updating {0} videos", category);
            }
            catch (Exception e)
            {
                Log <Youtube> .Error("Error getting {0} videos - {1}", category, e.Message);

                Log <Youtube> .Debug(e.StackTrace);
            }
        }
예제 #7
0
        private void button1_Click(object sender, EventArgs e)
        {
            Uri ur =
                new Uri(
                    "http://gdata.youtube.com/feeds/api/videos/fSgGV1llVHM&f=gdata_playlists&c=ytapi-DukaIstvan-MyYouTubeVideosF-d1ogtvf7-0&d=U1YkMvELc_arPNsH4kYosmD9LlbsOl3qUImVMV6ramM");
            YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);

            //order results by the number of views (most viewed first)
            query.OrderBy = "viewCount";

            //exclude restricted content from the search
            query.SafeSearch = YouTubeQuery.SafeSearchValues.None;
            //string ss = YouTubeQuery.TopRatedVideo;
            //http://gdata.youtube.com/feeds/api/standardfeeds/top_rated
            //search for puppies!
            query.Query = textBox1.Text;
            query.Categories.Add(new QueryCategory("Music", QueryCategoryOperator.AND));

            YouTubeFeed  videoFeed = service.Query(query);
            YouTubeEntry en        = (YouTubeEntry)videoFeed.Entries[0];
            string       s         = en.Summary.Text;
            string       s1        = en.Media.Description.Value;

            Google.GData.YouTube.MediaGroup gr = en.Media;

            Uri            videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + en.VideoId);
            Video          video         = request.Retrieve <Video>(videoEntryUrl);
            Feed <Comment> comments      = request.GetComments(video);
            string         cm            = "";

            foreach (Comment c in comments.Entries)
            {
                cm += c.Content + "\n------------------------------------------\n";
            }

            VideoInfo info = new VideoInfo();

            info.Get("yUHNUjEs7rQ");
            //Video v = request.Retrieve<Video>(videoEntryUrl);



            //Feed<Comment> comments = request.GetComments(v);

            //string cm = "";
            //foreach (Comment c in comments.Entries)
            //{
            //  cm += c.Author + c.Content + "------------------------------------------";
            //}
        }
예제 #8
0
        public void YouTubeReadOnlyTest()
        {
            Tracing.TraceMsg("Entering YouTubeReadOnlyTest");

            YouTubeQuery   query   = new YouTubeQuery(YouTubeQuery.TopRatedVideo);
            YouTubeService service = new YouTubeService("NETUnittests");

            query.Formats.Add(YouTubeQuery.VideoFormat.RTSP);
            query.Time = YouTubeQuery.UploadTime.ThisWeek;

            YouTubeFeed feed = service.Query(query);

            foreach (YouTubeEntry e in feed.Entries)
            {
                Assert.IsTrue(e.Media.Title.Value != null, "There should be a title");
            }
        }
예제 #9
0
        public void YouTubeGetActivitiesTest()
        {
            ActivitiesQuery query = new ActivitiesQuery();

            query.ModifiedSince = new DateTime(1980, 12, 1);
            YouTubeService service = new YouTubeService("NETUnittests", this.ytDevKey);

            if (!string.IsNullOrEmpty(this.ytUser))
            {
                service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd);
            }
            ActivitiesFeed feed = service.Query(query) as ActivitiesFeed;

            foreach (ActivityEntry e in feed.Entries)
            {
                Assert.IsTrue(e.VideoId != null, "There should be a videoid");
            }
            service = null;
        }
        private void InitList(string queryuri)
        {
            if (_setting.MusicFilter && queryuri != YouTubeQuery.CreateFavoritesUri(null))
            {
                queryuri += "_Music";
            }
            string reg = GetRegionOpt();

            if (!string.IsNullOrEmpty(reg))
            {
                queryuri = queryuri.Replace("standardfeeds", "standardfeeds/" + reg);
            }
            YouTubeQuery query = new YouTubeQuery(queryuri);

            //if (queryuri == YouTubeQuery.CreateFavoritesUri(null))
            //    query = SetParamToYouTubeQuery(query, true);
            //else
            //{
            //    query = SetParamToYouTubeQuery(query, false);
            //}

            query.NumberToRetrieve = 50;
            query.SafeSearch       = YouTubeQuery.SafeSearchValues.None;
            if (uploadtime != YouTubeQuery.UploadTime.AllTime)
            {
                query.Time = uploadtime;
            }

            YouTubeFeed vidr = service.Query(query);

            if (vidr.Entries.Count > 0)
            {
                SaveListState(true);
                addVideos(vidr, false, query);
                GUIPropertyManager.SetProperty("#header.title", vidr.Title.Text);
                UpdateGui();
            }
            else
            {
                Err_message("No item was found !");
            }
        }
예제 #11
0
        public void YouTubeFeedTest()
        {
            Tracing.TraceMsg("Entering YouTubeFeedTest");

            YouTubeQuery   query   = new YouTubeQuery(YouTubeQuery.TopRatedVideo);
            YouTubeService service = new YouTubeService("NETUnittests", this.ytDevKey);

            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd);
            }

            query.Formats.Add(YouTubeQuery.VideoFormat.RTSP);
            query.Time = YouTubeQuery.UploadTime.ThisWeek;

            YouTubeFeed feed = service.Query(query);

            foreach (YouTubeEntry e in feed.Entries)
            {
                Assert.IsTrue(e.Media.Title.Value != null, "There should be a title");
            }
        }
예제 #12
0
        /////////////////////////////////////////////////////////////////////////////



        [Test] public void YouTubeUploaderTest()
        {
            YouTubeQuery query = new YouTubeQuery();

            query.Uri = new Uri(CreateUri(this.resourcePath + "uploaderyt.xml"));

            YouTubeService service = new YouTubeService("NETUnittests", this.ytDevKey);

            if (this.userName != null)
            {
                service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd);
            }

            YouTubeFeed  feed  = service.Query(query);
            YouTubeEntry entry = feed.Entries[0] as YouTubeEntry;

            YouTube.MediaCredit uploader = entry.Uploader;
            Assert.IsTrue(uploader != null);
            Assert.IsTrue(uploader.Role == "uploader");
            Assert.IsTrue(uploader.Scheme == "urn:youtube");
            Assert.IsTrue(uploader.Value == "GoogleDevelopers");
        }
예제 #13
0
        public List <YoutubeVideo> SearchVideo(string query, int numberToRetrieve, string orderBy)
        {
            YouTubeService service      = new YouTubeService(_applicationName, _developerKey);
            const String   searchFields = "entry(id,title,link[@rel='alternate'],author(name,yt:userId),media:group(media:category(@label),media:credit,yt:videoid,yt:uploaderId),yt:statistics,yt:rating,gd:rating(@average),gd:comments/gd:feedLink(@countHint))";
            String         url          = String.Format("{0}?v=2&fields={1}", _videoUrl, searchFields);

            YouTubeQuery searchQuery = new YouTubeQuery(url);

            searchQuery.Query            = query;
            searchQuery.NumberToRetrieve = numberToRetrieve;
            searchQuery.OrderBy          = orderBy;

            YouTubeFeed searchResults = service.Query(searchQuery);

            List <YoutubeVideo> videos = new List <YoutubeVideo>();

            foreach (YouTubeEntry entry in searchResults.Entries)
            {
                videos.Add(entry.ToYoutubeVideo());
            }

            return(videos);
        }
예제 #14
0
        public void YouTubeUploaderTest()
        {
            Tracing.TraceMsg("Entering YouTubeUploaderTest");

            YouTubeQuery query = new YouTubeQuery();

            query.Uri = new Uri(CreateUri(Path.Combine(this.resourcePath, "uploaderyt.xml")));

            YouTubeService service = new YouTubeService("NETUnittests", this.ytDevKey);

            if (!string.IsNullOrEmpty(this.ytUser))
            {
                service.Credentials = new GDataCredentials(this.ytUser, this.ytPwd);
            }

            YouTubeFeed  feed  = service.Query(query);
            YouTubeEntry entry = feed.Entries[0] as YouTubeEntry;

            YouTube.MediaCredit uploader = entry.Uploader;
            Assert.IsTrue(uploader != null);
            Assert.IsTrue(uploader.Role == "uploader");
            Assert.IsTrue(uploader.Scheme == "urn:youtube");
            Assert.IsTrue(uploader.Value == "GoogleDevelopers");
        }
예제 #15
0
        public override int DiscoverSubCategories(Category parentCategory)
        {
            parentCategory.SubCategories = new List <Category>();
            if (parentCategory is RssLink)
            {
                YouTubeQuery ytq = new YouTubeQuery((parentCategory as RssLink).Url)
                {
                    NumberToRetrieve = pageSize
                };
                YouTubeFeed feed = service.Query(ytq);
                GetPlaylistEntriesAsCategories(parentCategory, feed);
            }
            else
            {
                Login();

                if (parentCategory.Name.EndsWith(Translation.Instance.Playlists))
                {
                    // authenticated user's playlists
                    YouTubeQuery query = new YouTubeQuery()
                    {
                        Uri = new Uri(YouTubeQuery.CreatePlaylistsUri(accountname)), StartIndex = 1, NumberToRetrieve = pageSize
                    };
                    YouTubeFeed feed = null;
                    try
                    {
                        feed = service.Query(query);
                    }
                    catch (Google.GData.Client.GDataRequestException queryEx)
                    {
                        HandleGDataErrorMessage(queryEx);
                    }
                    GetPlaylistEntriesAsCategories(parentCategory, feed);
                }
                else
                {
                    // authenticated user's subscriptions
                    RssLink newVidsLink = new RssLink();
                    newVidsLink.Name = Translation.Instance.NewVideos;
                    newVidsLink.Url  = USER_NEWSUBSCRIPTIONS_FEED;
                    parentCategory.SubCategories.Add(newVidsLink);
                    newVidsLink.ParentCategory = parentCategory;

                    YouTubeQuery query = new YouTubeQuery()
                    {
                        Uri = new Uri(YouTubeQuery.CreateSubscriptionUri(accountname)), StartIndex = 1, NumberToRetrieve = pageSize
                    };
                    YouTubeFeed feed = null;
                    try
                    {
                        feed = service.Query(query);
                    }
                    catch (Google.GData.Client.GDataRequestException queryEx)
                    {
                        HandleGDataErrorMessage(queryEx);
                    }
                    foreach (SubscriptionEntry subScr in feed.Entries)
                    {
                        RssLink subScrLink = new RssLink();
                        subScrLink.Name = subScr.UserName;
                        subScrLink.Url  = YouTubeQuery.CreateUserUri(subScr.UserName);
                        parentCategory.SubCategories.Add(subScrLink);
                        subScrLink.ParentCategory = parentCategory;
                    }
                    // if there are more results add a new NextPageCategory
                    if (feed.NextChunk != null)
                    {
                        parentCategory.SubCategories.Add(new NextPageCategory()
                        {
                            ParentCategory = parentCategory, Url = feed.NextChunk
                        });
                    }
                }
            }
            parentCategory.SubCategoriesDiscovered = true;
            return(parentCategory.SubCategories.Count);
        }