Beispiel #1
0
 protected void addFavorite(VideoInfo video)
 {
     if (CheckUsernameAndPassword())
     {
         Login();
         YouTubeEntry entry = ((MyYouTubeEntry)video.Other).YouTubeEntry;
         service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(accountname)), entry);
     }
 }
        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 !");
            }
        }
Beispiel #3
0
        public override int DiscoverDynamicCategories()
        {
            // walk the categories and see if there are user's playlists - they need to be set to have subcategories
            foreach (Category link in Settings.Categories)
            {
                if (link is RssLink)
                {
                    if (Regex.Match(((RssLink)link).Url, USER_PLAYLISTS_FEED).Success)
                    {
                        link.HasSubCategories        = true;
                        link.SubCategoriesDiscovered = false;
                    }
                }
                else
                {
                    // static Categories with static Subcategories
                    if (link.HasSubCategories && link.SubCategories != null)
                    {
                        foreach (var subLink in link.SubCategories)
                        {
                            if (subLink is RssLink && Regex.Match(((RssLink)subLink).Url, USER_PLAYLISTS_FEED).Success)
                            {
                                subLink.HasSubCategories        = true;
                                subLink.SubCategoriesDiscovered = false;
                            }
                        }
                        link.SubCategoriesDiscovered = true;
                    }
                }
            }

            // add categories defined by YouTube
            if (useDynamicCategories)
            {
                Dictionary <String, String> categories = getYoutubeCategories();
                foreach (KeyValuePair <String, String> cat in categories)
                {
                    RssLink item = new RssLink();
                    item.Name = cat.Key;
                    YouTubeQuery query = new YouTubeQuery(YouTubeQuery.DefaultVideoUri);
                    query.Categories.Add(new QueryCategory(cat.Value, QueryCategoryOperator.AND));
                    item.Url = query.Uri.ToString();
                    Settings.Categories.Add(item);
                }
            }

            // if a username was set add categories for a user on YouTube
            if (!string.IsNullOrEmpty(accountname) && !string.IsNullOrEmpty(password) && !string.IsNullOrEmpty(accountname))
            {
                Settings.Categories.Add(new RssLink()
                {
                    Name = string.Format("{0}'s {1}", accountname, Translation.Instance.Favourites), Url = YouTubeQuery.CreateFavoritesUri(accountname), Other = "Login"
                });
                Settings.Categories.Add(new RssLink()
                {
                    Name = string.Format("{0}'s {1}", accountname, Translation.Instance.Recommendations), Url = USER_RECOMMENDATIONS_FEED, Other = "Login"
                });
                Settings.Categories.Add(new RssLink()
                {
                    Name = string.Format("{0}'s {1}", accountname, "Watch Later Playlist"), Url = USER_WATCH_LATER_FEED, Other = "Login"
                });
                Settings.Categories.Add(new RssLink()
                {
                    Name = string.Format("{0}'s {1}", accountname, "Watch History Feed"), Url = USER_WATCH_HISTORY_FEED, Other = "Login"
                });
                Settings.Categories.Add(new Category()
                {
                    Name = string.Format("{0}'s {1}", accountname, Translation.Instance.Subscriptions), HasSubCategories = true
                });
                Settings.Categories.Add(new Category()
                {
                    Name = string.Format("{0}'s {1}", accountname, Translation.Instance.Playlists), HasSubCategories = true
                });
            }

            Settings.DynamicCategoriesDiscovered = true;
            return(Settings.Categories.Count);
        }
        /// <summary>
        /// Called when [show context menu].
        /// </summary>
        protected override void OnShowContextMenu()
        {
            GUIListItem selectedItem = listControl.SelectedListItem;

            YouTubeEntry    videoEntry;
            LocalFileStruct file = selectedItem.MusicTag as LocalFileStruct;

            if (file != null)
            {
                Uri   videoEntryUrl = new Uri("http://gdata.youtube.com/feeds/api/videos/" + file.VideoId);
                Video video         = Youtube2MP.request.Retrieve <Video>(videoEntryUrl);
                videoEntry = video.YouTubeEntry;
            }
            else
            {
                videoEntry = selectedItem.MusicTag as YouTubeEntry;
            }

            if (videoEntry == null)
            {
                return;
            }
            GUIDialogMenu dlg = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }
            dlg.Reset();
            dlg.SetHeading(498); // menu
            dlg.Add("Related Videos");
            dlg.Add("Video responses for this video");
            dlg.Add("All videos from this user : "******"Add to playlist");
            dlg.Add("Add All to playlist");
            dlg.Add("Add to favorites");
            dlg.Add("Options");
            dlg.Add("Download Video");
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }
            switch (dlg.SelectedLabel)
            {
            case 0: //relatated
            {
                if (videoEntry.RelatedVideosUri != null)
                {
                    YouTubeQuery query = new YouTubeQuery(videoEntry.RelatedVideosUri.Content);
                    YouTubeFeed  vidr  = service.Query(query);
                    if (vidr.Entries.Count > 0)
                    {
                        SaveListState(true);
                        addVideos(vidr, false, query);
                        UpdateGui();
                    }
                    else
                    {
                        Err_message("No item was found !");
                    }
                }
            }
            break;

            case 1: //respponse
            {
                if (videoEntry.VideoResponsesUri != null)
                {
                    YouTubeQuery query = new YouTubeQuery(videoEntry.VideoResponsesUri.Content);
                    YouTubeFeed  vidr  = service.Query(query);
                    if (vidr.Entries.Count > 0)
                    {
                        SaveListState(true);
                        addVideos(vidr, false, query);
                        UpdateGui();
                    }
                    else
                    {
                        Err_message("No response was found !");
                    }
                }
            }
            break;

            case 2: //relatated
            {
                if (videoEntry.RelatedVideosUri != null)
                {
                    Video        video = Youtube2MP.request.Retrieve <Video>(new Uri("http://gdata.youtube.com/feeds/api/videos/" + videoEntry.VideoId));
                    YouTubeQuery query = new YouTubeQuery(string.Format("http://gdata.youtube.com/feeds/api/users/{0}/uploads", video.Author));
                    YouTubeFeed  vidr  = service.Query(query);
                    if (vidr.Entries.Count > 0)
                    {
                        SaveListState(true);
                        addVideos(vidr, false, query);
                        UpdateGui();
                    }
                    else
                    {
                        Err_message("No item was found !");
                    }
                }
            }
            break;

            case 3:
            {
                VideoInfo inf = SelectQuality(videoEntry);
                if (inf.Quality != VideoQuality.Unknow)
                {
                    AddItemToPlayList(selectedItem, inf);
                }
            }
            break;

            case 4:
            {
                VideoInfo inf = SelectQuality(videoEntry);
                inf.Items = new Dictionary <string, string>();
                foreach (GUIListItem item in listControl.ListView.ListItems)
                {
                    AddItemToPlayList(item, new VideoInfo(inf));
                }
            }
            break;

            case 5:
            {
                try
                {
                    service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry);
                }
                catch (Exception)
                {
                    Err_message("Wrong request or wrong user identification");
                }
            }
            break;

            case 6:
                DoOptions();
                break;

            case 7: // download
            {
                if (Youtube2MP._settings.LocalFile.Get(videoEntry.VideoId) != null)
                {
                    Err_message("Item already downloaded !");
                }
                else
                {
                    if (VideoDownloader.IsBusy)
                    {
                        Err_message("Another donwnload is in progress");
                        dlgProgress = (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);
                        if (dlgProgress != null)
                        {
                            dlgProgress.Reset();
                            dlgProgress.SetHeading("Download progress");
                            dlgProgress.SetLine(1, "");
                            dlgProgress.SetLine(2, "");
                            dlgProgress.SetPercentage(0);
                            dlgProgress.Progress();
                            dlgProgress.ShowProgressBar(true);
                            dlgProgress.DoModal(GetID);
                        }
                    }
                    else
                    {
                        VideoInfo inf       = SelectQuality(videoEntry);
                        string    streamurl = Youtube2MP.StreamPlaybackUrl(videoEntry, inf);
                        VideoDownloader.AsyncDownload(streamurl,
                                                      Youtube2MP._settings.DownloadFolder + "\\" +
                                                      Utils.GetFilename(videoEntry.Title.Text + "{" + videoEntry.VideoId + "}") +
                                                      Path.GetExtension(streamurl));
                        VideoDownloader.Entry = videoEntry;
                    }
                }
            }
            break;
            }
        }
        private void ShowHome(int poz)
        {
            switch (poz)
            {
            case 0:
                GetTimeOpt();
                InitList(YouTubeQuery.MostViewedVideo);
                break;

            case 1:
                GetTimeOpt();
                InitList(YouTubeQuery.TopRatedVideo);
                break;

            case 2:
                InitList(YouTubeQuery.RecentlyFeaturedVideo);
                break;

            case 3:
                GetTimeOpt();
                InitList(YouTubeQuery.MostDiscussedVideo);
                break;

            case 4:
                GetTimeOpt();
                InitList(YouTubeQuery.FavoritesVideo);
                break;

            case 5:
                InitList(YouTubeQuery.MostLinkedVideo);
                break;

            case 6:
                InitList(YouTubeQuery.MostRespondedVideo);
                break;

            case 7:
                InitList(YouTubeQuery.MostRecentVideo);
                break;

            case 8:
                InitList(YouTubeQuery.CreateFavoritesUri(null));
                break;

            case 9:
                if (Youtube2MP._settings.LocalFile.Items.Count == 0)
                {
                    Err_message("No downloded item was found !");
                }
                else
                {
                    SaveListState(true);
                    foreach (LocalFileStruct entry in Youtube2MP._settings.LocalFile.Items)
                    {
                        GUIListItem item = new GUIListItem();
                        // and add station name & bitrate
                        item.Label    = entry.Title;
                        item.Label2   = "";
                        item.IsFolder = false;

                        string imageFile = Path.GetDirectoryName(entry.LocalFile) + "\\" + Path.GetFileNameWithoutExtension(entry.LocalFile) + ".png";
                        if (File.Exists(imageFile))
                        {
                            item.ThumbnailImage = imageFile;
                            //item.IconImage = "defaultVideoBig.png";
                            item.IconImage    = imageFile;
                            item.IconImageBig = imageFile;
                        }
                        item.MusicTag        = entry;
                        item.OnItemSelected += new GUIListItem.ItemSelectedHandler(item_OnItemSelected);
                        listControl.Add(item);
                    }
                    GUIPropertyManager.SetProperty("#header.title", Youtube2MP._settings.Cats[9]);
                    UpdateGui();
                }
                break;
            }
        }
Beispiel #6
0
        protected override void OnShowContextMenu()
        {
            if (listControl == null || listControl.SelectedListItem == null)
            {
                return;
            }
            GUIListItem   selectedItem = listControl.SelectedListItem;
            YouTubeEntry  videoEntry   = selectedItem.MusicTag as YouTubeEntry;
            GUIDialogMenu dlg          = (GUIDialogMenu)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }
            dlg.Reset();
            dlg.SetHeading(498); // menu
            if (Youtube2MP.player.CurrentSong > -1 || Youtube2MP.temp_player.CurrentSong > -1)
            {
                dlg.Add(Translation.PlayNext);
            }
            dlg.Add(Translation.ShowPreviousWindow);
            dlg.Add(Translation.Fullscreen);
            if (videoEntry != null)
            {
                dlg.Add(Translation.AddPlaylist);
                dlg.Add(Translation.AddAllPlaylist);
                dlg.Add(Translation.Info);
                if (Youtube2MP.service.Credentials != null)
                {
                    dlg.Add(Translation.AddFavorites);
                    dlg.Add(Translation.AddWatchLater);
                }
            }
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }
            if (dlg.SelectedLabelText == Translation.ShowPreviousWindow)
            {
                GUIWindowManager.ShowPreviousWindow();
            }
            else if (dlg.SelectedLabelText == Translation.Fullscreen)
            {
                g_Player.ShowFullScreenWindow();
            }
            else if (dlg.SelectedLabelText == Translation.AddPlaylist)
            {
                VideoInfo inf = SelectQuality(videoEntry);
                if (inf.Quality != VideoQuality.Unknow)
                {
                    AddItemToPlayList(selectedItem, inf);
                }
            }
            else if (dlg.SelectedLabelText == Translation.AddAllPlaylist)
            {
                VideoInfo inf = SelectQuality(videoEntry);
                inf.Items = new Dictionary <string, string>();
                if (inf.Quality != VideoQuality.Unknow)
                {
                    GUIDialogProgress dlgProgress =
                        (GUIDialogProgress)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_PROGRESS);
                    if (dlgProgress != null)
                    {
                        dlgProgress.Reset();
                        dlgProgress.SetHeading(Translation.AddAllPlaylist);
                        dlgProgress.SetLine(1, "");
                        dlgProgress.SetLine(2, "");
                        dlgProgress.SetPercentage(0);
                        dlgProgress.Progress();
                        dlgProgress.ShowProgressBar(true);
                        dlgProgress.StartModal(GetID);
                    }
                    int i = 0;
                    for (int j = 0; j < listControl.Count; j++)
                    {
                        GUIListItem item = listControl[j];
                        if (dlgProgress != null)
                        {
                            double pr = ((double)i / (double)listControl.Count) * 100;
                            dlgProgress.SetLine(1, item.Label);
                            dlgProgress.SetLine(2, i.ToString() + "/" + listControl.Count.ToString());
                            dlgProgress.SetPercentage((int)pr);
                            dlgProgress.Progress();
                            if (dlgProgress.IsCanceled)
                            {
                                break;
                            }
                        }
                        i++;
                        AddItemToPlayList(item, new VideoInfo(inf));
                    }
                    if (dlgProgress != null)
                    {
                        dlgProgress.Close();
                    }
                }
            }
            else if (dlg.SelectedLabelText == Translation.AddFavorites)
            {
                try
                {
                    Youtube2MP.service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry);
                }
                catch (Exception)
                {
                    Err_message(Translation.WrongRequestWrongUser);
                }
            }
            else if (dlg.SelectedLabelText == Translation.AddWatchLater)
            {
                PlayListMember pm = new PlayListMember();
                pm.Id = videoEntry.VideoId;
                Youtube2MP.request.Insert(new Uri("https://gdata.youtube.com/feeds/api/users/default/watch_later"), pm);
            }
            else if (dlg.SelectedLabelText == Translation.Info)
            {
                YoutubeGuiInfoEx scr = (YoutubeGuiInfoEx)GUIWindowManager.GetWindow(29053);
                scr.YouTubeEntry = videoEntry;
                //if (entry!=null)
                //{
                //  ArtistItem artistItem=ent
                //}
                GUIWindowManager.ActivateWindow(29053);
            }
            else if (dlg.SelectedLabelText == Translation.PlayNext)
            {
                PlayNext(videoEntry);
            }
        }
        /// <summary>
        /// returns a Feed of favorite videos for a given username
        /// </summary>
        /// <param name="user">the username</param>
        /// <returns>a feed of Videos</returns>
        public Feed <Video> GetFavoriteFeed(string user)
        {
            YouTubeQuery q = PrepareQuery <YouTubeQuery>(YouTubeQuery.CreateFavoritesUri(user));

            return(PrepareFeed <Video>(q));
        }
Beispiel #8
0
        protected override void OnShowContextMenu()
        {
            if (Youtube2MP.NowPlayingEntry == null)
            {
                base.OnShowContextMenu();
                return;
            }
            YouTubeEntry  videoEntry = Youtube2MP.NowPlayingEntry;
            GUIDialogMenu dlg        = (GUIDialogMenu)GUIWindowManager.GetWindow((int)Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }
            dlg.Reset();
            dlg.SetHeading(Translation.ContextMenu); // menu
            dlg.AddLocalizedString(941);
            dlg.AddLocalizedString(970);
            dlg.Add(Translation.Info);
            if (Youtube2MP.service.Credentials != null)
            {
                dlg.Add(Translation.AddFavorites);
            }
            dlg.Add(Translation.DownloadVideo);
            dlg.DoModal(GetID);
            if (dlg.SelectedId == -1)
            {
                return;
            }
            if (dlg.SelectedLabelText == Translation.Info)
            {
                YoutubeGuiInfoEx scr = (YoutubeGuiInfoEx)GUIWindowManager.GetWindow(29053);
                scr.YouTubeEntry = videoEntry;
                GUIWindowManager.ActivateWindow(29053);
            }
            if (dlg.SelectedLabelText == Translation.AddFavorites)
            {
                try
                {
                    Youtube2MP.service.Insert(new Uri(YouTubeQuery.CreateFavoritesUri(null)), videoEntry);
                }
                catch (Exception)
                {
                    Youtube2MP.Err_message(Translation.WrongRequestWrongUser);
                }
            }

            if (dlg.SelectedLabelText == Translation.DownloadVideo)
            {
                LocalFileStruct fil = Youtube2MP._settings.LocalFile.Get(Youtube2MP.GetVideoId(videoEntry));
                if (fil != null && File.Exists(fil.LocalFile))
                {
                    Youtube2MP.Err_message(Translation.ItemAlreadyDownloaded);
                }
                else
                {
                    if (Youtube2MP.VideoDownloader.IsBusy)
                    {
                        Youtube2MP.Err_message(Translation.AnotherDonwnloadProgress);
                    }
                    else
                    {
                        VideoInfo inf       = Youtube2MP.SelectQuality(videoEntry);
                        string    streamurl = Youtube2MP.StreamPlaybackUrl(videoEntry, inf);
                        Youtube2MP.VideoDownloader.AsyncDownload(streamurl,
                                                                 Youtube2MP._settings.DownloadFolder + "\\" +
                                                                 Utils.MakeFileName(Utils.GetFilename(videoEntry.Title.Text + "{" +
                                                                                                      Youtube2MP.GetVideoId(videoEntry) + "}")) +
                                                                 Path.GetExtension(streamurl) + ".___");
                        GUIPropertyManager.SetProperty("#Youtube.fm.IsDownloading", "true");
                        GUIPropertyManager.SetProperty("#Youtube.fm.Download.Progress", "0");
                        GUIPropertyManager.SetProperty("#Youtube.fm.Download.Item", videoEntry.Title.Text);
                        DatabaseProvider.InstanInstance.Save(videoEntry);
                        Youtube2MP.VideoDownloader.Entry = videoEntry;
                    }
                }
            }

            if (dlg.SelectedId == 941)
            {
                ShowAspectRatioMenu();
            }
            if (dlg.SelectedId == 970)
            {
                GUIWindowManager.IsOsdVisible        = false;
                GUIGraphicsContext.IsFullScreenVideo = false;
                GUIWindowManager.ShowPreviousWindow();
            }
        }