Ejemplo n.º 1
0
        /// <summary>
        /// Get the slugs for each list selected by a user in the Multi-Select dialog
        /// </summary>
        /// <param name="username">username of user</param>
        /// <param name="lists">List of lists created by user</param>
        public static List <string> GetUserListSelections(List <TraktUserList> lists)
        {
            if (lists.Count == 0)
            {
                if (!GUIUtils.ShowYesNoDialog(Translation.Lists, Translation.NoListsFound, true))
                {
                    // nothing to do, return
                    return(null);
                }
                TraktList list = new TraktList();
                if (TraktLists.GetListDetailsFromUser(ref list))
                {
                    TraktLogger.Info("Creating new '{0}' list '{1}'", list.Privacy, list.Name);
                    TraktAddListResponse response = TraktAPI.TraktAPI.ListAdd(list);
                    TraktAPI.TraktAPI.LogTraktResponse <TraktResponse>(response);
                    if (response.Status == "success")
                    {
                        ClearCache(TraktSettings.Username);
                        return(new List <string> {
                            response.Slug
                        });
                    }
                }
                return(null);
            }

            List <MultiSelectionItem> selectedItems = GUIUtils.ShowMultiSelectionDialog(Translation.SelectLists, GetMultiSelectItems(lists));

            if (selectedItems == null)
            {
                return(null);
            }

            List <string> slugs = new List <string>();

            foreach (var item in selectedItems.Where(l => l.Selected == true))
            {
                slugs.Add(item.ItemID);
            }
            return(slugs);
        }
Ejemplo 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);
        }