Esempio n. 1
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);
                TraktAPI.TraktAPI.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.Imdb;
                                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
                    TraktAPI.TraktAPI.LogTraktResponse<TraktSyncResponse>(TraktAPI.TraktAPI.ListAddItems(copyParams.Destination));
                    if (response.Status == "success") TraktLists.ClearCache(TraktSettings.Username);
                }
            })
            {
                Name = "Copy List",
                IsBackground = true
            };
            copyThread.Start(copyList);
        }
Esempio n. 2
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);
        }
Esempio n. 3
0
        private void CopyList(TraktListDetail sourceList, TraktListDetail 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)
                {
                    // get items from other list
                    var userListItems = TraktAPI.TraktAPI.GetUserListItems(copyParams.Username, copyParams.Source.Ids.Trakt.ToString(), "min");

                    // 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)
                        {
                            TraktHandlers.MovingPictures.UpdateCategoriesMenu(SyncListType.CustomList);
                            TraktHandlers.MovingPictures.UpdateFiltersMenu(SyncListType.CustomList);
                        }
                    }
                }
            })
            {
                Name = "CopyList",
                IsBackground = true
            };
            copyThread.Start(copyList);
        }
        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);
        }