protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) { //if (GUIBackgroundTask.Instance.IsBusy) return; switch (controlId) { #region SEARCH LIST CONTROL SELECTED case (873008): if (actionType == Action.ActionType.ACTION_SELECT_ITEM) { GUIListItem item = resultListControl.SelectedListItem as GUIListItem; #region SCROBBLEMOVIE if (item.TVTag is TraktMovieSummary) { // Get movie from traktmoviesummary TraktMovie currentMovieSelected = new TraktMovie { Title = ((TraktMovieSummary)item.TVTag).Title, Year = ((TraktMovieSummary)item.TVTag).Year, Ids = ((TraktMovieSummary)item.TVTag).Ids }; var data = new TraktScrobbleMovie { Movie = currentMovieSelected, Progress = EbasicHandler.GetPlayerProgress(EbasicHandler.getCurrentProgram()), AppDate = TraktSettings.BuildDate, AppVersion = TraktSettings.Version }; EPGCache.addOnCache(EbasicHandler.getCurrentProgram().getOriginalTitle(), EPGCache.createData((TraktMovieSummary)item.TVTag)); EbasicHandler.overrideCurrentProgram((TraktMovieSummary)item.TVTag); EbasicHandler.StartScrobble(data); exitGUI(); } #endregion #region SCROBBLESHOW else if (item.TVTag is TraktEpisodeSummary) //found! { TraktLogger.Info("EpisodeSummary Detected"); var data = new TraktScrobbleEpisode { Show = new TraktShow { Title = currentTvShow.Title, Year = currentTvShow.Year, Ids = currentTvShow.Ids }, Episode = new TraktEpisode { Season = ((TraktEpisodeSummary)item.TVTag).Season, Number = ((TraktEpisodeSummary)item.TVTag).Number, Title = ((TraktEpisodeSummary)item.TVTag).Title, Ids = ((TraktEpisodeSummary)item.TVTag).Ids }, Progress = EbasicHandler.GetPlayerProgress(EbasicHandler.getCurrentProgram()), AppDate = TraktSettings.BuildDate, AppVersion = TraktSettings.Version }; EPGCache.addOnCache(EbasicHandler.getCurrentProgram().getOriginalTitle(), EPGCache.createData(currentTvShow)); EbasicHandler.overrideCurrentProgram(currentTvShow, data.Episode); EbasicHandler.StartScrobble(data); exitGUI(); } #endregion else if (item.TVTag is TraktShowSummary) { TraktLogger.Info("TraktShowSummary Detected"); currentTvShow = (TraktShowSummary)item.TVTag; searchStack.Push(currentSearch); PopulateListControl(EbasicHandler.SearchShowSeasons(((TraktShowSummary)item.TVTag).Ids.Slug), searchlevel++); } else if (item.TVTag is TraktSeasonSummary) { searchStack.Push(currentSearch); PopulateListControl(EbasicHandler.SearchSeasonEpisodes(currentTvShow.Ids.Slug, ((TraktSeasonSummary)item.TVTag).Number.ToString()), searchlevel++); } else if (item.TVTag.ToString() == "FirstButton") { if ((item.Label).ToString() == "Manual Search") { //popup the input dialog to search. VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)Window.WINDOW_VIRTUAL_KEYBOARD); keyboard.Reset(); keyboard.Text = EbasicHandler.getCurrentProgram().Title; keyboard.DoModal(GUIWindowManager.ActiveWindow); if (keyboard.IsConfirmed) { PopulateListControl(TraktAPI.TraktAPI.SearchByName(keyboard.Text, "show,movie", "title")); } } else //this handles back button { PopulateListControl(searchStack.Pop(), searchlevel--); } } } break; #endregion default: TraktLogger.Info("I don't know what's the object."); base.OnClicked(controlId, control, actionType); break; } }
protected override void OnClicked(int controlId, GUIControl control, Action.ActionType actionType) { //if (GUIBackgroundTask.Instance.IsBusy) return; switch (controlId) { #region SEARCH LIST CONTROL SELECTED case (3): if (actionType == Action.ActionType.ACTION_SELECT_ITEM) { GUIListItem item = resultListControl.SelectedListItem as GUIListItem; #if DEBUG TraktLogger.Info("The button pressed has a tvTAG as: {0}, ad has a string value of: {1}", item.TVTag.GetType(), item.TVTag.ToString()); #endif #region SCROBBLEMOVIE if (item.TVTag is TraktMovieSummary) { // Get movie from traktmoviesummary TraktMovie currentMovieSelected = new TraktMovie { Title = ((TraktMovieSummary)item.TVTag).Title, Year = ((TraktMovieSummary)item.TVTag).Year, Ids = ((TraktMovieSummary)item.TVTag).Ids }; var data = new TraktScrobbleMovie { Movie = currentMovieSelected, Progress = EbasicHandler.GetPlayerProgress(EbasicHandler.getCurrentProgram()), AppDate = TraktSettings.BuildDate, AppVersion = TraktSettings.Version }; EPGCache.addOnCache(EbasicHandler.getCurrentProgram().getOriginalTitle(), EPGCache.createData((TraktMovieSummary)item.TVTag)); EbasicHandler.overrideCurrentProgram((TraktMovieSummary)item.TVTag); EbasicHandler.StartScrobble(data); } #endregion else if (item.TVTag is TraktShowSummary) //search for seasons { TraktLogger.Info("TraktShowSummary Detected"); currentTvShow = (TraktShowSummary)item.TVTag; searchStack.Push(currentSearch); PopulateListControl(EbasicHandler.SearchShowSeasons(((TraktShowSummary)item.TVTag).Ids.Slug), searchlevel++); GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_INIT, GetID, 0, 0, 0, 0, null); OnMessage(msg); } else if (item.TVTag is TraktSeasonSummary) //Episode for episodes { #if DEBUG TraktLogger.Info("SeasonSummary Detected"); TraktLogger.Info("Season '{0}' for show {1} selected. Getting Episodes.", ((TraktSeasonSummary)item.TVTag).Number, currentTvShow.Ids.Slug); #endif searchStack.Push(currentSearch); PopulateListControl(EbasicHandler.SearchSeasonEpisodes(currentTvShow.Ids.Slug, ((TraktSeasonSummary)item.TVTag).Number.ToString()), searchlevel++); GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_INIT, GetID, 0, 0, 0, 0, null); OnMessage(msg); } #region SCROBBLESHOW else if (item.TVTag is TraktEpisodeSummary) //found! { TraktLogger.Info("EpisodeSummary Detected"); var data = new TraktScrobbleEpisode { Show = new TraktShow { Title = currentTvShow.Title, Year = currentTvShow.Year, Ids = currentTvShow.Ids }, Episode = new TraktEpisode { Season = ((TraktEpisodeSummary)item.TVTag).Season, Number = ((TraktEpisodeSummary)item.TVTag).Number, Title = ((TraktEpisodeSummary)item.TVTag).Title, Ids = ((TraktEpisodeSummary)item.TVTag).Ids }, Progress = EbasicHandler.GetPlayerProgress(EbasicHandler.getCurrentProgram()), AppDate = TraktSettings.BuildDate, AppVersion = TraktSettings.Version }; #if DEBUG TraktLogger.Info(currentTvShow.ToString()); #endif EPGCache.addOnCache(EbasicHandler.getCurrentProgram().getOriginalTitle(), EPGCache.createData(currentTvShow)); EbasicHandler.overrideCurrentProgram(currentTvShow, data.Episode); EbasicHandler.StartScrobble(data); } #endregion else if (item.TVTag.ToString() == "FirstButton") { if ((item.Label).ToString() == "Manual Search") { //popup the input dialog to search. I need to call the full GUI here. #if DEBUG TraktLogger.Info("Manual search selected"); #endif VirtualKeyboard keyboard = (VirtualKeyboard)GUIWindowManager.GetWindow((int)Window.WINDOW_VIRTUAL_KEYBOARD); //keyboard.IsSearchKeyboard = true; keyboard.Reset(); keyboard.Text = EbasicHandler.getCurrentProgram().Title; keyboard.DoModal(GUIWindowManager.ActiveWindow); if (keyboard.IsConfirmed) { //PopulateControlWithShows(keyboard.Text); //PopulateListControl(TraktAPI.TraktAPI.SearchShowByName(keyboard.Text)); //GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_INIT, GetID, 0, 0, 0, 0, null); //OnMessage(msg); //GUIShowSelectGUI.setCurrentSearch(TraktAPI.TraktAPI.SearchByName(keyboard.Text)); //GUIWindowManager.ActivateWindow((int)TraktGUIWindows.EPGShowSelect); GUIShowSelectGUI.callSearchGUI(TraktAPI.TraktAPI.SearchByName(keyboard.Text)); } } else //this handles back button { TraktLogger.Info("BackButtonDetected"); PopulateListControl(searchStack.Pop(), searchlevel--); GUIMessage msg = new GUIMessage(GUIMessage.MessageType.GUI_MSG_WINDOW_INIT, GetID, 0, 0, 0, 0, null); OnMessage(msg); } } } break; #endregion default: TraktLogger.Info("I don't know what's the object."); base.OnClicked(controlId, control, actionType); break; } }
public bool Scrobble(string filename) { StopScrobble(); istStoppingScrobble = false; if (!g_Player.IsTV) { return(false); } EbasicHandler.setCurrentProgram(GetCurrentProgram()); if (EbasicHandler.getCurrentProgram() == null) { return(false); } EbasicHandler.SetCurrentProgramIsScrobbling(true); TVJustTurnedOn = true; if (EbasicHandler.getCurrentProgramType() == VideoType.Series) { TraktLogger.Info("Detected tv show playing on Live TV. Title = '{0}'", EbasicHandler.getCurrentProgram().Title.ToString()); } else { TraktLogger.Info("Detected movie playing on Live TV. Title = '{0}'", EbasicHandler.getCurrentProgram().Title.ToString()); } #region Scrobble Timer TraktTimer = new Timer(new TimerCallback((stateInfo) => { Thread.CurrentThread.Name = "Scrobble"; // get the current program airing on tv now // this may have changed since last status update on trakt EVideoInfo videoInfo = GetCurrentProgram(); //Reinit all variables item = new TraktEPGCacheRecord(); response = new TraktScrobbleResponse(); // I have problems with GUI rendering most of the times. If i set the thread to sleep it really helps with GUI rendering. // This might also work well to handle zapping correctly. Thread.Sleep((TraktSettings.ETVScrobbleDelay) * 1000); try { if (videoInfo != null) { // if we are watching something different, // check if we should mark previous as watched //if (!videoInfo.Equals(CurrentProgram)) if (!videoInfo.Equals(EbasicHandler.getCurrentProgram())) { TraktLogger.Info("Detected new tv program has started. Previous Program = '{0}', New Program = '{1}'", EbasicHandler.getCurrentProgram().ToString(), videoInfo.ToString()); //The new program has changed. I should check if the active window is GUIShowSelect and eventually close it. if (GUIWindowManager.ActiveWindow.Equals((int)TraktGUIWindows.EPGShowSelect)) { GUIShowSelectGUI.exitGUI(); } if (IsProgramWatched(EbasicHandler.getCurrentProgram()) && EbasicHandler.IsCurrentProgramScrobbling()) { TraktLogger.Info("Playback of program on Live TV is considered watched. Title = '{0}'", EbasicHandler.getCurrentProgram().ToString()); BasicHandler.StopScrobble(EbasicHandler.getCurrentProgram(), true); } //The programs are different so we should start the whole scrobbling process. //For that we set the new videoInfo scrobbling status to true //later we're checking if videoInfo is scrobbling, and it should be false if we don't set it true here. videoInfo.IsScrobbling = true; //EbasicHandler.SetCurrentProgramIsScrobbling(true); } // continue watching new program // dont try to scrobble if previous attempt failed // If the current program is scrobbling, according to the APIARY there's no need to resend every 15 minutes, // it will expire after runtime has elapsed. if ((videoInfo.IsScrobbling) | (TVJustTurnedOn)) { TVJustTurnedOn = false; //Starts the scrobble of the new program because it changed //cache should search here because some shows have no name and could be in cache. #region CACHE CHECK and SCROBBLE from CACHE if (EPGCache.searchOnCache(videoInfo.Title, out item)) { if (item.Type.Equals("nullRecord")) { response.Code = 901; response.Description = "Manually set don't scrobble"; } else if ((item.Type.Equals("movie")) & (videoInfo.Type == VideoType.Movie)) { EbasicHandler.overrideVideoInfoProgram(ref videoInfo, item.Movie); response = EbasicHandler.StartScrobbleMovie(videoInfo); } else if ((item.Type.Equals("show")) & (videoInfo.Type == VideoType.Series)) { EbasicHandler.overrideVideoInfoProgram(ref videoInfo, item.Show); response = EbasicHandler.StartScrobbleEpisode(videoInfo); } else //The item type is different from the videoinfo type. Cache is authoritative here so overriding videoInfo with the cache. //It's most likely that a show is detected wrong as a movie, because a movie with episode and season number is totally nonsense, but handles both. { response.Code = 904; //This code will be used later. if (item.Type.Equals("show")) { EbasicHandler.overrideVideoInfoProgram(ref videoInfo, item.Show); response.Description = item.Show.Ids.Slug; } else { EbasicHandler.overrideVideoInfoProgram(ref videoInfo, item.Movie); } } }// end cache thingy if it was successful it should be scrobbled. #endregion #region CACHE MATCH UNSUCCESSFUL: TRY RETRIEVE ORIGINAL LANGUAGE AND SCROBBLE else { #region FOUND ORIGINAL LANGUAGE TITLE WITH A SINGLE MATCH // Try first to scrobble without changing anything. This is to avoid problems with shows that uses // real non translated shows. In this case the name of the show usually is enough to succesfully scrobble. if (videoInfo.Type == VideoType.Series) { response = EbasicHandler.StartScrobbleEpisode(videoInfo); } else { response = EbasicHandler.StartScrobbleMovie(videoInfo); } if (!(response.Code == 0) && EbasicHandler.setOriginalTitle(ref videoInfo)) { if ((videoInfo.Type == VideoType.Series)) { response = EbasicHandler.StartScrobbleEpisode(videoInfo); } else { response = EbasicHandler.StartScrobbleMovie(videoInfo); } } #endregion #region NO CACHE, NO ORIGINAL LANGUAGE SINGLE MATCH FOUND everything is very likely to fail. else if (!response.Code.Equals(0)) { response.Code = 404; response.Description = "Not Found"; } #endregion } #endregion EbasicHandler.setCurrentProgram(videoInfo); if (response.Code.Equals(901)) { TraktLogger.Info("Program {0} skipped because manually marked to skip on cache", videoInfo.Title); } else if (response.Code.Equals(0)) { if (TraktSettings.AllowPopUPOnSuccessfulScrobbling) { GUIDialogNotify notification = (GUIDialogNotify)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_NOTIFY); notification.Reset(); notification.SetHeading(string.Format("{0} scrobbled!", EbasicHandler.getCurrentProgram().Type.ToString())); notification.SetText(string.Format("Scrobbling '{0}' as '{1}'", EbasicHandler.getCurrentProgram().getOriginalTitle(), EbasicHandler.getCurrentProgram().Title)); notification.SetImage(Path.Combine(Config.GetFolder(Config.Dir.Skin), string.Format(@"{0}\Media\Logos\trakt.png", Config.SkinName))); notification.DoModal(GUIWindowManager.ActiveWindow); } } else // the response was bad! Everything gone worse than ever, again open the GUI { GUIDialogYesNo askManualSelection = (GUIDialogYesNo)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_YES_NO); if (askManualSelection != null) { askManualSelection.Reset(); askManualSelection.SetHeading("Start manual matching?"); askManualSelection.SetLine(1, string.Format("Cannot find a match for '{0}'", videoInfo.Title)); askManualSelection.SetDefaultToYes(true); askManualSelection.DoModal(GUIWindowManager.ActiveWindow); if (askManualSelection.IsConfirmed) { if (!istStoppingScrobble) //maybe we can handle this better. If the user stops the program right before this the plugin crashes. { EbasicHandler.StartGui(response.Code, item, TraktSettings.GUIAsDialog); } } else { // Need to handle cancel button with a null on cache to avoid future scrobbling. EPGCache.addOnCache(videoInfo.Title); } } } } } } catch (NullReferenceException exception) { //handle the worst. This usually happens when the user stops the player during a dialog. //We should at least log this in the mediaportal error. } }), null, 1000, 300000); #endregion return(true); }