Ejemplo n.º 1
0
 internal static void AddRemoveItemInList(List <string> slugs, TraktListItem item, bool remove)
 {
     AddRemoveItemInList(slugs, new List <TraktListItem>()
     {
         item
     }, remove);
 }
Ejemplo n.º 2
0
        public TraktItem(TraktListItem listItem)
        {
            // TODO: No switch possible because of implementation?
            if (listItem.Type == TraktListItemType.Movie)
            {
                // TODO: Redundant?
                Type  = TraktItemType.Movie;
                Movie = listItem.Movie;
            }
            else if (listItem.Type == TraktListItemType.Show)
            {
                Type = TraktItemType.Show;
                Show = listItem.Show;
            }
            else if (listItem.Type == TraktListItemType.Season)
            {
                Type   = TraktItemType.Season;
                Show   = listItem.Show;
                Season = listItem.Season;
            }
            else if (listItem.Type == TraktListItemType.Episode)
            {
                Type    = TraktItemType.Episode;
                Show    = listItem.Show;
                Episode = listItem.Episode;
            }

            // TODO: Default operation?
        }
        private string GetListItemLabel(TraktListItem listItem)
        {
            string retValue = string.Empty;

            switch (listItem.Type)
            {
            case "movie":
                retValue = listItem.Movie.Title;
                break;

            case "show":
                retValue = listItem.Show.Title;
                break;

            case "season":
                retValue = string.Format("{0} {1} {2}", listItem.Show.Title, GUI.Translation.Season, listItem.Season.Number);
                break;

            case "episode":
                retValue = string.Format("{0} - {1}x{2}{3}", listItem.Show.Title, listItem.Episode.Season, listItem.Episode.Number, string.IsNullOrEmpty(listItem.Episode.Title) ? string.Empty : " - " + listItem.Episode.Title);
                break;

            case "person":
                retValue = listItem.Person.Name;
                break;
            }
            return(retValue);
        }
Ejemplo n.º 4
0
    private async Task <Option <int> > IdentifyMovie(TvContext dbContext, TraktListItem item)
    {
        var guids = item.Guids.Map(g => g.Guid).ToList();

        Option <int> maybeMovieByGuid = await dbContext.MovieMetadata
                                        .AsNoTracking()
                                        .Filter(mm => mm.Guids.Any(g => guids.Contains(g.Guid)))
                                        .FirstOrDefaultAsync()
                                        .Map(Optional)
                                        .MapT(mm => mm.MovieId);

        foreach (int movieId in maybeMovieByGuid)
        {
            _logger.LogDebug("Located trakt movie {Title} by id", item.DisplayTitle);
            return(movieId);
        }

        Option <int> maybeMovieByTitleYear = await dbContext.MovieMetadata
                                             .AsNoTracking()
                                             .Filter(mm => mm.Title == item.Title && mm.Year == item.Year)
                                             .FirstOrDefaultAsync()
                                             .Map(Optional)
                                             .MapT(mm => mm.MovieId);

        foreach (int movieId in maybeMovieByTitleYear)
        {
            _logger.LogDebug("Located trakt movie {Title} by title/year", item.DisplayTitle);
            return(movieId);
        }

        _logger.LogDebug("Unable to locate trakt movie {Title}", item.DisplayTitle);

        return(None);
    }
Ejemplo n.º 5
0
    private async Task <Option <int> > IdentifySeason(TvContext dbContext, TraktListItem item)
    {
        var guids = item.Guids.Map(g => g.Guid).ToList();

        Option <int> maybeSeasonByGuid = await dbContext.SeasonMetadata
                                         .AsNoTracking()
                                         .Filter(sm => sm.Guids.Any(g => guids.Contains(g.Guid)))
                                         .FirstOrDefaultAsync()
                                         .Map(Optional)
                                         .MapT(sm => sm.SeasonId);

        foreach (int seasonId in maybeSeasonByGuid)
        {
            _logger.LogDebug("Located trakt season {Title} by id", item.DisplayTitle);
            return(seasonId);
        }

        Option <int> maybeSeasonByTitleYear = await dbContext.SeasonMetadata
                                              .AsNoTracking()
                                              .Filter(sm => sm.Season.Show.ShowMetadata.Any(s => s.Title == item.Title && s.Year == item.Year))
                                              .Filter(sm => sm.Season.SeasonNumber == item.Season)
                                              .FirstOrDefaultAsync()
                                              .Map(Optional)
                                              .MapT(sm => sm.SeasonId);

        foreach (int seasonId in maybeSeasonByTitleYear)
        {
            _logger.LogDebug("Located trakt season {Title} by title/year/season", item.DisplayTitle);
            return(seasonId);
        }

        _logger.LogDebug("Unable to locate trakt season {Title}", item.DisplayTitle);

        return(None);
    }
        private string GetListItemSecondLabel(TraktListItem listItem)
        {
            string retValue = string.Empty;

            switch (listItem.Type)
            {
            case "movie":
                retValue = listItem.Movie.Year == null ? "----" : listItem.Movie.Year.ToString();
                break;

            case "show":
                retValue = listItem.Show.Year == null ? "----" : listItem.Show.Year.ToString();
                break;

            case "season":
                retValue = string.Format("{0} {1}", listItem.Season.EpisodeCount, Translation.Episodes);
                break;

            case "episode":
                retValue = listItem.Episode.FirstAired.FromISO8601().ToShortDateString();
                break;

            case "person":
                retValue = listItem.Person.Birthday;
                break;
            }
            return(retValue);
        }
        private void PublishMovieSkinProperties(TraktListItem item)
        {
            if (item == null || item.Movie == null)
            {
                return;
            }

            GUICommon.SetMovieProperties(item.Movie);
        }
        private void PublishPersonSkinProperties(TraktListItem item)
        {
            if (item == null || item.Person == null)
            {
                return;
            }

            GUICommon.SetPersonProperties(item.Person);
        }
Ejemplo n.º 9
0
 public static void AddRemoveItemInList(string listname, TraktListItem item, bool remove)
 {
     AddRemoveItemInList(new List <string> {
         listname
     }, new List <TraktListItem>()
     {
         item
     }, remove);
 }
        private void PublishShowSkinProperties(TraktListItem item)
        {
            if (item == null || item.Show == null)
            {
                return;
            }

            GUICommon.SetShowProperties(item.Show);
        }
        private void PublishSeasonSkinProperties(TraktListItem item)
        {
            if (item == null || item.Season == null)
            {
                return;
            }

            GUICommon.SetSeasonProperties(item.Show, item.Season);

            PublishShowSkinProperties(item);
        }
 private void RemoveItemFromCollection(TraktListItem item)
 {
     if (SelectedType == TraktItemType.movie)
     {
         TraktHelper.RemoveMovieFromCollection(item.Movie);
     }
     else if (SelectedType == TraktItemType.episode)
     {
         TraktHelper.RemoveEpisodeFromCollection(item.Episode);
         TraktCache.RemoveEpisodeFromCollection(item.Show, item.Episode);
     }
 }
        private void PublishEpisodeSkinProperties(TraktListItem item)
        {
            if (item == null || item.Episode == null)
            {
                return;
            }

            GUICommon.SetProperty("#Trakt.Season.Number", item.Episode.Season);
            GUICommon.SetEpisodeProperties(item.Show, item.Episode);

            PublishShowSkinProperties(item);
        }
 private void AddItemToCollection(TraktListItem item)
 {
     if (SelectedType == TraktItemType.movie)
     {
         TraktHelper.AddMovieToCollection(item.Movie);
     }
     else if (SelectedType == TraktItemType.episode)
     {
         TraktHelper.AddEpisodeToCollection(item.Episode);
         TraktCache.AddEpisodeToCollection(item.Show, item.Episode);
     }
 }
Ejemplo n.º 15
0
        public void Test_TraktListItem_Default_Constructor()
        {
            var listItem = new TraktListItem();

            listItem.Rank.Should().BeNull();
            listItem.ListedAt.Should().BeNull();
            listItem.Type.Should().BeNull();
            listItem.Movie.Should().BeNull();
            listItem.Show.Should().BeNull();
            listItem.Season.Should().BeNull();
            listItem.Episode.Should().BeNull();
            listItem.Person.Should().BeNull();
        }
Ejemplo n.º 16
0
        public void TestTraktListItemDefaultConstructor()
        {
            var listItem = new TraktListItem();

            listItem.Rank.Should().BeNullOrEmpty();
            listItem.ListedAt.Should().NotHaveValue();
            listItem.Type.Should().BeNull();
            listItem.Movie.Should().BeNull();
            listItem.Show.Should().BeNull();
            listItem.Season.Should().BeNull();
            listItem.Episode.Should().BeNull();
            listItem.Person.Should().BeNull();
        }
        private GUITmdbImage GetTmdbImage(TraktListItem listItem)
        {
            var images = new GUITmdbImage();

            switch (listItem.Type)
            {
            case "movie":
                images.MovieImages = new TmdbMovieImages {
                    Id = listItem.Movie.Ids.Tmdb
                };
                break;

            case "show":
                images.ShowImages = new TmdbShowImages {
                    Id = listItem.Show.Ids.Tmdb
                };
                break;

            case "season":
                images.ShowImages = new TmdbShowImages {
                    Id = listItem.Show.Ids.Tmdb
                };
                images.SeasonImages = new TmdbSeasonImages
                {
                    Id     = listItem.Show.Ids.Tmdb,
                    Season = listItem.Season.Number
                };
                break;

            case "episode":
                images.ShowImages = new TmdbShowImages {
                    Id = listItem.Show.Ids.Tmdb
                };
                images.SeasonImages = new TmdbSeasonImages
                {
                    Id     = listItem.Show.Ids.Tmdb,
                    Season = listItem.Episode.Season
                };
                break;

            case "person":
                images.PeopleImages = new TmdbPeopleImages {
                    Id = listItem.Person.Ids.TmdbId
                };
                break;
            }

            return(images);
        }
 private void RateItem(TraktListItem item)
 {
     if (SelectedType == TraktItemType.movie)
     {
         GUICommon.RateMovie(item.Movie);
     }
     else if (SelectedType == TraktItemType.show)
     {
         GUICommon.RateShow(item.Show);
     }
     else if (SelectedType == TraktItemType.episode)
     {
         GUICommon.RateEpisode(item.Show, item.Episode);
     }
 }
 private void RemoveItemFromWatchList(TraktListItem item)
 {
     if (SelectedType == TraktItemType.movie)
     {
         TraktHelper.RemoveMovieFromWatchList(item.Movie, true);
     }
     else if (SelectedType == TraktItemType.show)
     {
         TraktHelper.RemoveShowFromWatchList(item.Show);
     }
     else if (SelectedType == TraktItemType.episode)
     {
         TraktHelper.RemoveEpisodeFromWatchList(item.Episode);
     }
 }
 private void AddItemToWatchList(TraktListItem item)
 {
     if (SelectedType == TraktItemType.movie)
     {
         TraktHelper.AddMovieToWatchList(item.Movie, true);
     }
     else if (SelectedType == TraktItemType.show)
     {
         TraktHelper.AddShowToWatchList(item.Show);
     }
     else if (SelectedType == TraktItemType.episode)
     {
         TraktHelper.AddEpisodeToWatchList(item.Episode);
         TraktCache.AddEpisodeToWatchlist(item.Show, item.Episode);
     }
 }
        private bool ListItemMatch(TraktListItem currentItem, TraktListItem itemToMatch)
        {
            switch (itemToMatch.Type)
            {
            case "movie":
                if (currentItem.Movie == null)
                {
                    return(false);
                }
                return(currentItem.Movie.Ids.Trakt == itemToMatch.Movie.Ids.Trakt);

            case "show":
                if (currentItem.Show == null)
                {
                    return(false);
                }
                return(currentItem.Show.Ids.Trakt == itemToMatch.Show.Ids.Trakt);

            case "season":
                if (currentItem.Season == null)
                {
                    return(false);
                }
                return(currentItem.Season.Ids.Trakt == itemToMatch.Season.Ids.Trakt);

            case "episode":
                if (currentItem.Episode == null)
                {
                    return(false);
                }
                return(currentItem.Episode.Ids.Trakt == itemToMatch.Episode.Ids.Trakt);

            case "person":
                if (currentItem.Person == null)
                {
                    return(false);
                }
                return(currentItem.Person.Ids.Trakt == itemToMatch.Person.Ids.Trakt);
            }

            return(false);
        }
Ejemplo n.º 22
0
    private static TraktListItem ProjectItem(TraktList list, TraktListItemWithGuids item)
    {
        var result = new TraktListItem
        {
            TraktList = list,
            Kind      = item.Kind,
            TraktId   = item.TraktId,
            Rank      = item.Rank,
            Title     = item.Title,
            Year      = item.Year,
            Season    = item.Season,
            Episode   = item.Episode
        };

        result.Guids = item.Guids.Map(g => new TraktListItemGuid {
            Guid = g, TraktListItem = result
        }).ToList();

        return(result);
    }
Ejemplo n.º 23
0
        public static void AddRemoveEpisodeInUserList(string username, string title, string year, string season, string episode, string tvdbid, bool remove)
        {
            if (!GUICommon.CheckLogin(false))
            {
                return;
            }

            GUIBackgroundTask.Instance.ExecuteInBackgroundAndCallback(() =>
            {
                return(TraktLists.GetListsForUser(username));
            },
                                                                      delegate(bool success, object result)
            {
                if (success)
                {
                    IEnumerable <TraktUserList> customlists = result as IEnumerable <TraktUserList>;

                    // get slug of lists selected
                    List <string> slugs = TraktLists.GetUserListSelections(customlists.ToList());
                    if (slugs == null || slugs.Count == 0)
                    {
                        return;
                    }

                    TraktListItem item = new TraktListItem
                    {
                        Type    = TraktItemType.episode.ToString(),
                        Title   = title,
                        Year    = Convert.ToInt32(year),
                        Season  = Convert.ToInt32(season),
                        Episode = Convert.ToInt32(episode),
                        TvdbId  = tvdbid
                    };

                    AddRemoveItemInList(slugs, item, remove);
                }
            }, Translation.GettingLists, true);
        }
Ejemplo n.º 24
0
        private void CopyList(TraktListDetail sourceList, TraktList newList)
        {
            var copyList = new CopyList {
                Username    = CurrentUser,
                Source      = sourceList,
                Destination = newList
            };

            var copyThread = new Thread((obj) =>
            {
                var copyParams = obj as CopyList;

                // first create new list
                TraktLogger.Info("Creating new list online. Privacy = '{0}', Name = '{1}'", copyParams.Destination.Privacy, copyParams.Destination.Name);
                var response = TraktAPI.TraktAPI.CreateCustomList(copyParams.Destination);
                if (response == null || response.Ids == null)
                {
                    TraktLogger.Error("Failed to create user list. List Name = '{0}'", copyParams.Destination.Name);
                    return;
                }

                // get items from other list
                var userListItems = TraktAPI.TraktAPI.GetUserListItems(copyParams.Source.User.Ids.Slug, copyParams.Source.Ids.Trakt.ToString(), "min");
                if (userListItems == null)
                {
                    TraktLogger.Error("Failed to get user list items. List Name = '{0}', ID = '{1}'", copyParams.Destination.Name, copyParams.Source.Ids.Trakt);
                    return;
                }

                // copy items to new list
                var itemsToAdd = new TraktSyncAll();
                foreach (var item in userListItems)
                {
                    var listItem  = new TraktListItem();
                    listItem.Type = item.Type;

                    switch (item.Type)
                    {
                    case "movie":
                        if (itemsToAdd.Movies == null)
                        {
                            itemsToAdd.Movies = new List <TraktMovie>();
                        }

                        itemsToAdd.Movies.Add(new TraktMovie {
                            Ids = item.Movie.Ids
                        });
                        break;

                    case "show":
                        if (itemsToAdd.Shows == null)
                        {
                            itemsToAdd.Shows = new List <TraktShow>();
                        }

                        itemsToAdd.Shows.Add(new TraktShow {
                            Ids = item.Show.Ids
                        });
                        break;

                    case "season":
                        if (itemsToAdd.Seasons == null)
                        {
                            itemsToAdd.Seasons = new List <TraktSeason>();
                        }

                        itemsToAdd.Seasons.Add(new TraktSeason {
                            Ids = item.Season.Ids
                        });
                        break;

                    case "episode":
                        if (itemsToAdd.Episodes == null)
                        {
                            itemsToAdd.Episodes = new List <TraktEpisode>();
                        }

                        itemsToAdd.Episodes.Add(new TraktEpisode {
                            Ids = item.Episode.Ids
                        });
                        break;

                    case "person":
                        if (itemsToAdd.People == null)
                        {
                            itemsToAdd.People = new List <TraktPerson>();
                        }

                        itemsToAdd.People.Add(new TraktPerson {
                            Ids = item.Person.Ids
                        });
                        break;
                    }
                }

                // add items to the list
                var ItemsAddedResponse = TraktAPI.TraktAPI.AddItemsToList("me", response.Ids.Trakt.ToString(), itemsToAdd);

                if (ItemsAddedResponse != null)
                {
                    TraktLists.ClearListCache(TraktSettings.Username);
                    TraktCache.ClearCustomListCache();

                    // updated MovingPictures categories and filters menu
                    if (TraktHelper.IsMovingPicturesAvailableAndEnabled)
                    {
                        MovingPictures.UpdateCategoriesMenu(SyncListType.CustomList);
                        MovingPictures.UpdateFiltersMenu(SyncListType.CustomList);
                    }
                }
            })
            {
                Name         = "CopyList",
                IsBackground = true
            };

            copyThread.Start(copyList);
        }
        private TraktSyncAll GetSyncItems(TraktListItem listItem)
        {
            var syncItems = new TraktSyncAll();

            switch (listItem.Type)
            {
            case "movie":
                var movie = new TraktMovie
                {
                    Ids = new TraktMovieId {
                        Trakt = listItem.Movie.Ids.Trakt
                    }
                };
                syncItems.Movies = new List <TraktMovie>();
                syncItems.Movies.Add(movie);
                break;

            case "show":
                var show = new TraktShow
                {
                    Ids = new TraktShowId {
                        Trakt = listItem.Show.Ids.Trakt
                    }
                };
                syncItems.Shows = new List <TraktShow>();
                syncItems.Shows.Add(show);
                break;

            case "season":
                var season = new TraktSeason
                {
                    Ids = new TraktSeasonId {
                        Trakt = listItem.Season.Ids.Trakt
                    }
                };
                syncItems.Seasons = new List <TraktSeason>();
                syncItems.Seasons.Add(season);
                break;

            case "episode":
                var episode = new TraktEpisode
                {
                    Ids = new TraktEpisodeId {
                        Trakt = listItem.Episode.Ids.Trakt
                    }
                };
                syncItems.Episodes = new List <TraktEpisode>();
                syncItems.Episodes.Add(episode);
                break;

            case "person":
                var person = new TraktPerson
                {
                    Ids = new TraktPersonId {
                        Trakt = listItem.Person.Ids.Trakt
                    }
                };
                syncItems.People = new List <TraktPerson>();
                syncItems.People.Add(person);
                break;
            }

            return(syncItems);
        }
Ejemplo n.º 26
0
        private void CopyList(TraktUserList sourceList, TraktList newList)
        {
            CopyList copyList = new CopyList {
                Username = CurrentUser, Source = sourceList, Destination = newList
            };

            Thread copyThread = new Thread(delegate(object obj)
            {
                CopyList copyParams = obj as CopyList;

                // first create new list
                TraktLogger.Info("Creating new '{0}' list '{1}'", copyParams.Destination.Privacy, copyParams.Destination.Name);
                TraktAddListResponse response = TraktAPI.TraktAPI.ListAdd(copyParams.Destination);
                TraktLogger.LogTraktResponse <TraktResponse>(response);
                if (response.Status == "success")
                {
                    // update with offical slug
                    copyParams.Destination.Slug = response.Slug;

                    // get items from other list
                    TraktUserList userList = TraktAPI.TraktAPI.GetUserList(copyParams.Username, copyParams.Source.Slug);
                    // copy items to new list
                    List <TraktListItem> items = new List <TraktListItem>();
                    foreach (var item in userList.Items)
                    {
                        TraktListItem listItem = new TraktListItem();
                        listItem.Type          = item.Type;

                        switch (item.Type)
                        {
                        case "movie":
                            listItem.Title  = item.Movie.Title;
                            listItem.Year   = Convert.ToInt32(item.Movie.Year);
                            listItem.ImdbId = item.Movie.IMDBID;
                            break;

                        case "show":
                            listItem.Title  = item.Show.Title;
                            listItem.Year   = item.Show.Year;
                            listItem.TvdbId = item.Show.Tvdb;
                            break;

                        case "season":
                            listItem.Title  = item.Show.Title;
                            listItem.Year   = item.Show.Year;
                            listItem.TvdbId = item.Show.Tvdb;
                            listItem.Season = Convert.ToInt32(item.SeasonNumber);
                            break;

                        case "episode":
                            listItem.Title   = item.Show.Title;
                            listItem.Year    = item.Show.Year;
                            listItem.TvdbId  = item.Show.Tvdb;
                            listItem.Season  = Convert.ToInt32(item.SeasonNumber);
                            listItem.Episode = Convert.ToInt32(item.EpisodeNumber);
                            break;
                        }
                        items.Add(listItem);
                    }
                    copyParams.Destination.Items = items;

                    // add items to the list
                    TraktLogger.LogTraktResponse <TraktSyncResponse>(TraktAPI.TraktAPI.ListAddItems(copyParams.Destination));
                    if (response.Status == "success")
                    {
                        TraktLists.ClearCache(TraktSettings.Username);
                    }
                }
            })
            {
                Name         = "CopyList",
                IsBackground = true
            };

            copyThread.Start(copyList);
        }
        public override async Task<ITraktListItem> ReadObjectAsync(JsonTextReader jsonReader, CancellationToken cancellationToken = default)
        {
            CheckJsonTextReader(jsonReader);

            if (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.StartObject)
            {
                var movieReader = new MovieObjectJsonReader();
                var showReader = new ShowObjectJsonReader();
                var seasonReader = new SeasonObjectJsonReader();
                var episodeReader = new EpisodeObjectJsonReader();
                var personReader = new PersonObjectJsonReader();

                ITraktListItem traktListItem = new TraktListItem();

                while (await jsonReader.ReadAsync(cancellationToken) && jsonReader.TokenType == JsonToken.PropertyName)
                {
                    var propertyName = jsonReader.Value.ToString();

                    switch (propertyName)
                    {
                        case JsonProperties.PROPERTY_NAME_ID:
                            {
                                var value = await JsonReaderHelper.ReadUnsignedIntegerValueAsync(jsonReader, cancellationToken);

                                if (value.First)
                                    traktListItem.Id = value.Second;

                                break;
                            }
                        case JsonProperties.PROPERTY_NAME_RANK:
                            traktListItem.Rank = await jsonReader.ReadAsStringAsync(cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_LISTED_AT:
                            {
                                var value = await JsonReaderHelper.ReadDateTimeValueAsync(jsonReader, cancellationToken);

                                if (value.First)
                                    traktListItem.ListedAt = value.Second;

                                break;
                            }
                        case JsonProperties.PROPERTY_NAME_TYPE:
                            traktListItem.Type = await JsonReaderHelper.ReadEnumerationValueAsync<TraktListItemType>(jsonReader, cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_MOVIE:
                            traktListItem.Movie = await movieReader.ReadObjectAsync(jsonReader, cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_SHOW:
                            traktListItem.Show = await showReader.ReadObjectAsync(jsonReader, cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_SEASON:
                            traktListItem.Season = await seasonReader.ReadObjectAsync(jsonReader, cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_EPISODE:
                            traktListItem.Episode = await episodeReader.ReadObjectAsync(jsonReader, cancellationToken);
                            break;
                        case JsonProperties.PROPERTY_NAME_PERSON:
                            traktListItem.Person = await personReader.ReadObjectAsync(jsonReader, cancellationToken);
                            break;
                        default:
                            await JsonReaderHelper.ReadAndIgnoreInvalidContentAsync(jsonReader, cancellationToken);
                            break;
                    }
                }

                return traktListItem;
            }

            return await Task.FromResult(default(ITraktListItem));
        }
Ejemplo n.º 28
0
        protected override void OnShowContextMenu()
        {
            var selectedItem = this.Facade.SelectedListItem;

            if (selectedItem == null)
            {
                return;
            }

            var userListItem = selectedItem.TVTag as TraktUserListItem;

            if (userListItem == null)
            {
                return;
            }

            var dlg = (IDialogbox)GUIWindowManager.GetWindow((int)GUIWindow.Window.WINDOW_DIALOG_MENU);

            if (dlg == null)
            {
                return;
            }

            dlg.Reset();
            dlg.SetHeading(GUIUtils.PluginName());

            GUIListItem listItem = null;

            if (SelectedType == TraktItemType.movie || SelectedType == TraktItemType.episode)
            {
                // Mark As Watched
                if (!userListItem.Watched)
                {
                    listItem = new GUIListItem(Translation.MarkAsWatched);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.MarkAsWatched;
                }

                // Mark As UnWatched
                if (userListItem.Watched)
                {
                    listItem = new GUIListItem(Translation.MarkAsUnWatched);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.MarkAsUnWatched;
                }
            }

            if (SelectedType != TraktItemType.season)
            {
                // Add/Remove Watch List
                if (!userListItem.InWatchList)
                {
                    listItem = new GUIListItem(Translation.AddToWatchList);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.AddToWatchList;
                }
                else
                {
                    listItem = new GUIListItem(Translation.RemoveFromWatchList);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.RemoveFromWatchList;
                }
            }

            // Add to Custom list
            listItem = new GUIListItem(Translation.AddToList);
            dlg.Add(listItem);
            listItem.ItemId = (int)ContextMenuItem.AddToList;

            // Remove from Custom list (Only if current user is the active user)
            if (TraktSettings.Username == CurrentUser)
            {
                listItem = new GUIListItem(Translation.RemoveFromList);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.RemoveFromList;
            }

            if (SelectedType == TraktItemType.movie || SelectedType == TraktItemType.episode)
            {
                // Add to Library
                // Don't allow if it will be removed again on next sync
                // movie could be part of a DVD collection
                if (!userListItem.InCollection && !TraktSettings.KeepTraktLibraryClean)
                {
                    listItem = new GUIListItem(Translation.AddToLibrary);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.AddToLibrary;
                }

                if (userListItem.InCollection)
                {
                    listItem = new GUIListItem(Translation.RemoveFromLibrary);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.RemoveFromLibrary;
                }
            }

            // Related Movies/Shows
            listItem = new GUIListItem(SelectedType == TraktItemType.movie ? Translation.RelatedMovies : Translation.RelatedShows + "...");
            dlg.Add(listItem);
            listItem.ItemId = (int)ContextMenuItem.Related;

            if (SelectedType != TraktItemType.season)
            {
                // Rate
                listItem = new GUIListItem(Translation.Rate + "...");
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Rate;

                // Shouts
                listItem = new GUIListItem(Translation.Shouts + "...");
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Shouts;
            }

            // Trailers
            if (TraktHelper.IsOnlineVideosAvailableAndEnabled)
            {
                listItem = new GUIListItem(Translation.Trailers);
                dlg.Add(listItem);
                listItem.ItemId = (int)ContextMenuItem.Trailers;
            }

            // Search with mpNZB
            if (TraktHelper.IsMpNZBAvailableAndEnabled)
            {
                if ((userListItem.Movie != null && !userListItem.Movie.InCollection) || userListItem.Episode != null)
                {
                    listItem = new GUIListItem(Translation.SearchWithMpNZB);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.SearchWithMpNZB;
                }
            }

            // Search with MyTorrents
            if (TraktHelper.IsMyTorrentsAvailableAndEnabled)
            {
                if ((userListItem.Movie != null && !userListItem.Movie.InCollection) || userListItem.Episode != null)
                {
                    listItem = new GUIListItem(Translation.SearchTorrent);
                    dlg.Add(listItem);
                    listItem.ItemId = (int)ContextMenuItem.SearchTorrent;
                }
            }

            // Change Layout
            listItem = new GUIListItem(Translation.ChangeLayout);
            dlg.Add(listItem);
            listItem.ItemId = (int)ContextMenuItem.ChangeLayout;

            // Show Context Menu
            dlg.DoModal(GUIWindowManager.ActiveWindow);
            if (dlg.SelectedId < 0)
            {
                return;
            }

            switch (dlg.SelectedId)
            {
            case ((int)ContextMenuItem.MarkAsWatched):
                MarkItemAsWatched(userListItem);
                if (userListItem.Plays == 0)
                {
                    userListItem.Plays = 1;
                }
                userListItem.Watched  = true;
                selectedItem.IsPlayed = true;
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.MarkAsUnWatched):
                MarkItemAsUnWatched(userListItem);
                userListItem.Watched  = false;
                selectedItem.IsPlayed = false;
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.AddToWatchList):
                AddItemToWatchList(userListItem);
                userListItem.InWatchList = true;
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                GUIWatchListMovies.ClearCache(TraktSettings.Username);
                break;

            case ((int)ContextMenuItem.RemoveFromWatchList):
                RemoveItemFromWatchList(userListItem);
                userListItem.InWatchList = false;
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                GUIWatchListMovies.ClearCache(TraktSettings.Username);
                break;

            case ((int)ContextMenuItem.AddToList):
                if (SelectedType == TraktItemType.movie)
                {
                    TraktHelper.AddRemoveMovieInUserList(userListItem.Title, userListItem.Year, userListItem.ImdbId, false);
                }
                else if (SelectedType == TraktItemType.show)
                {
                    TraktHelper.AddRemoveShowInUserList(userListItem.Title, userListItem.Year, userListItem.Show.Tvdb, false);
                }
                else if (SelectedType == TraktItemType.season)
                {
                    TraktHelper.AddRemoveSeasonInUserList(userListItem.Title, userListItem.Year, userListItem.SeasonNumber, userListItem.Show.Tvdb, false);
                }
                else if (SelectedType == TraktItemType.episode)
                {
                    TraktHelper.AddRemoveEpisodeInUserList(userListItem.Title, userListItem.Year, userListItem.SeasonNumber, userListItem.EpisodeNumber, userListItem.Show.Tvdb, false);
                }
                break;

            case ((int)ContextMenuItem.RemoveFromList):
                if (!GUIUtils.ShowYesNoDialog(Translation.DeleteListItem, Translation.ConfirmDeleteListItem))
                {
                    break;
                }

                // Only do remove from current list
                // We could do same as Add (ie remove from multile lists) but typically you only remove from the current list
                if (SelectedType == TraktItemType.movie)
                {
                    TraktListItem item = new TraktListItem {
                        Type = "movie", ImdbId = userListItem.ImdbId, Title = userListItem.Title, Year = Convert.ToInt32(userListItem.Year)
                    };
                    TraktHelper.AddRemoveItemInList(CurrentList.Slug, item, true);
                }
                else if (SelectedType == TraktItemType.show)
                {
                    TraktListItem item = new TraktListItem {
                        Type = "show", TvdbId = userListItem.Show.Tvdb, Title = userListItem.Title, Year = Convert.ToInt32(userListItem.Year)
                    };
                    TraktHelper.AddRemoveItemInList(CurrentList.Slug, item, true);
                }
                else if (SelectedType == TraktItemType.season)
                {
                    TraktListItem item = new TraktListItem {
                        Type = "season", TvdbId = userListItem.Show.Tvdb, Title = userListItem.Title, Year = Convert.ToInt32(userListItem.Year), Season = Convert.ToInt32(userListItem.SeasonNumber)
                    };
                    TraktHelper.AddRemoveItemInList(CurrentList.Slug, item, true);
                }
                else if (SelectedType == TraktItemType.episode)
                {
                    TraktListItem item = new TraktListItem {
                        Type = "episode", TvdbId = userListItem.Show.Tvdb, Title = userListItem.Title, Year = Convert.ToInt32(userListItem.Year), Season = Convert.ToInt32(userListItem.SeasonNumber), Episode = Convert.ToInt32(userListItem.EpisodeNumber)
                    };
                    TraktHelper.AddRemoveItemInList(CurrentList.Slug, item, true);
                }

                // Remove from view
                if (Facade.Count > 1)
                {
                    PreviousSelectedIndex = Facade.SelectedListItemIndex;
                    CurrentList.Items.Remove(userListItem);
                    SendListItemsToFacade(CurrentList);
                }
                else
                {
                    CurrentList.Items.Remove(userListItem);

                    // no more items left
                    GUIControl.ClearControl(GetID, Facade.GetID);
                    ClearProperties();
                    GUIWindowManager.Process();

                    // nothing left, exit
                    GUIWindowManager.ShowPreviousWindow();
                    return;
                }
                break;

            case ((int)ContextMenuItem.AddToLibrary):
                AddItemToLibrary(userListItem);
                userListItem.InCollection = true;
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.RemoveFromLibrary):
                RemoveItemFromLibrary(userListItem);
                userListItem.InCollection = false;
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.Related):
                if (SelectedType == TraktItemType.movie)
                {
                    RelatedMovie relatedMovie = new RelatedMovie();
                    relatedMovie.IMDbId           = userListItem.Movie.IMDBID;
                    relatedMovie.Title            = userListItem.Movie.Title;
                    GUIRelatedMovies.relatedMovie = relatedMovie;
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.RelatedMovies);
                }
                else
                {
                    //series, season & episode
                    RelatedShow relatedShow = new RelatedShow();
                    relatedShow.Title           = userListItem.Show.Title;
                    relatedShow.TVDbId          = userListItem.Show.Tvdb;
                    GUIRelatedShows.relatedShow = relatedShow;
                    GUIWindowManager.ActivateWindow((int)TraktGUIWindows.RelatedShows);
                }
                break;

            case ((int)ContextMenuItem.Rate):
                RateItem(userListItem);
                OnItemSelected(selectedItem, Facade);
                if (SelectedType == TraktItemType.movie)
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("MoviePoster");
                }
                else
                {
                    (Facade.SelectedListItem as GUICustomListItem).Images.NotifyPropertyChanged("ShowPoster");
                }
                break;

            case ((int)ContextMenuItem.Shouts):
                GUIShouts.ShoutType = (GUIShouts.ShoutTypeEnum)Enum.Parse(typeof(GUIShouts.ShoutTypeEnum), SelectedType.ToString(), true);
                if (SelectedType == TraktItemType.movie)
                {
                    GUIShouts.MovieInfo = new MovieShout {
                        IMDbId = userListItem.ImdbId, TMDbId = userListItem.Movie.TMDBID, Title = userListItem.Title, Year = userListItem.Year
                    }
                }
                ;
                else if (SelectedType == TraktItemType.show)
                {
                    GUIShouts.ShowInfo = new ShowShout {
                        IMDbId = userListItem.ImdbId, TVDbId = userListItem.Show.Tvdb, Title = userListItem.Title
                    }
                }
                ;
                else
                {
                    GUIShouts.EpisodeInfo = new EpisodeShout {
                        IMDbId = userListItem.ImdbId, TVDbId = userListItem.Show.Tvdb, Title = userListItem.Title, SeasonIdx = userListItem.SeasonNumber, EpisodeIdx = userListItem.EpisodeNumber
                    }
                };
                GUIShouts.Fanart = SelectedType == TraktItemType.movie ? userListItem.Movie.Images.Fanart.LocalImageFilename(ArtworkType.MovieFanart) : userListItem.Show.Images.Fanart.LocalImageFilename(ArtworkType.ShowFanart);
                GUIWindowManager.ActivateWindow((int)TraktGUIWindows.Shouts);
                break;

            case ((int)ContextMenuItem.Trailers):
                if (SelectedType == TraktItemType.movie)
                {
                    GUICommon.ShowMovieTrailersMenu(userListItem.Movie);
                }
                else if (SelectedType == TraktItemType.episode)
                {
                    userListItem.Episode.Season = Convert.ToInt32(userListItem.SeasonNumber);
                    userListItem.Episode.Number = Convert.ToInt32(userListItem.EpisodeNumber);

                    GUICommon.ShowTVShowTrailersMenu(userListItem.Show, userListItem.Episode);
                }
                else if (SelectedType == TraktItemType.season && TraktSettings.UseTrailersPlugin && TraktHelper.IsTrailersAvailableAndEnabled)
                {
                    GUICommon.ShowTVSeasonTrailersPluginMenu(userListItem.Show, int.Parse(userListItem.SeasonNumber));
                }
                break;

            case ((int)ContextMenuItem.SearchWithMpNZB):
                string loadingParam = String.Empty;
                if (userListItem.Movie != null)
                {
                    loadingParam = string.Format("search:{0}", userListItem.Movie.Title);
                }
                else if (userListItem.Episode != null)
                {
                    loadingParam = string.Format("search:{0} S{1}E{2}", userListItem.Show.Title, userListItem.Episode.Season.ToString("D2"), userListItem.Episode.Number.ToString("D2"));
                }
                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.MpNZB, loadingParam);
                break;

            case ((int)ContextMenuItem.SearchTorrent):
                string loadPar = String.Empty;
                if (userListItem.Movie != null)
                {
                    loadPar = userListItem.Movie.Title;
                }
                else if (userListItem.Episode != null)
                {
                    loadPar = string.Format("{0} S{1}E{2}", userListItem.Show.Title, userListItem.Episode.Season.ToString("D2"), userListItem.Episode.Number.ToString("D2"));
                }
                GUIWindowManager.ActivateWindow((int)ExternalPluginWindows.MyTorrents, loadPar);
                break;

            case ((int)ContextMenuItem.ChangeLayout):
                CurrentLayout = GUICommon.ShowLayoutMenu(CurrentLayout, PreviousSelectedIndex);
                break;

            default:
                break;
            }

            base.OnShowContextMenu();
        }