Beispiel #1
0
        public IAttemptResult MoveVideoToForward(int videoIndex, int playlistID)
        {
            IAttemptResult <ITreePlaylistInfo> result = this.GetPlaylist(playlistID);

            if (!result.IsSucceeded || result.Data is null)
            {
                return(AttemptResult.Fail(result.Message));
            }

            ITreePlaylistInfo playlist = result.Data;

            playlist.VideoSortType = STypes::VideoSortType.Custom;

            if (videoIndex == playlist.Videos.Count - 1)
            {
                return(AttemptResult.Fail("指定された動画は最後に存在するため前に移動できません。"));
            }

            try
            {
                playlist.Videos.InsertIntoForward(videoIndex);
            }
            catch (Exception e)
            {
                this._logger.Error($"動画の並び替え操作に失敗しました。({nameof(this.MoveVideoToForward)})", e);
                return(AttemptResult.Fail($"動画の並び替え操作に失敗しました。(詳細:{e.Message})", e));
            }

            return(this.Update(playlist));
        }
        public STypes::Playlist ConvertLocalPlaylistToStorePlaylist(ITreePlaylistInfo source)
        {
            var converted = new STypes::Playlist();

            converted.Id                         = source.Id;
            converted.IsRoot                     = source.IsRoot;
            converted.PlaylistName               = source.Name.Value;
            converted.FolderPath                 = source.Folderpath;
            converted.IsExpanded                 = source.IsExpanded;
            converted.SortType                   = source.VideoSortType;
            converted.IsVideoDescending          = source.IsVideoDescending;
            converted.IsTemporary                = source.IsTemporary;
            converted.IsDownloadSucceededHistory = source.IsDownloadSucceededHistory;
            converted.IsDownloadFailedHistory    = source.IsDownloadFailedHistory;
            converted.IsRemotePlaylist           = source.RemoteType != RemoteType.None;
            converted.RemoteId                   = source.RemoteId;
            converted.IsWatchLater               = source.RemoteType == RemoteType.WatchLater;
            converted.IsMylist                   = source.RemoteType == RemoteType.Mylist;
            converted.IsSeries                   = source.RemoteType == RemoteType.Series;
            converted.IsChannel                  = source.RemoteType == RemoteType.Channel;
            converted.IsUserVideos               = source.RemoteType == RemoteType.UserVideos;
            converted.BookMarkedVideoID          = source.BookMarkedVideoID;
            converted.Videos.Clear();
            converted.Videos.AddRange(source.Videos.Select(v => this.ConvertLocalVideoToStoreVideo(v)));

            IAttemptResult <STypes::Playlist> pResult = this._playlistStoreHandler.GetPlaylist(source.ParentId);

            if (pResult.IsSucceeded && pResult.Data is not null)
            {
                converted.ParentPlaylist = pResult.Data;
            }

            return(converted);
        }
Beispiel #3
0
        public IAttemptResult WireVideoToPlaylist(int videoID, int playlistID)
        {
            IAttemptResult <STypes::Video> vResult = this._videoStoreHandler.GetVideo(videoID);

            if (!vResult.IsSucceeded || vResult.Data is null)
            {
                return(AttemptResult.Fail("追加する動画はDBに保存されていません。"));
            }

            STypes::Video video = vResult.Data;

            video.PlaylistIds.AddUnique(playlistID);
            this._videoStoreHandler.Update(video);

            IAttemptResult result = this._playlistStoreHandler.WireVideo(video, playlistID);

            ITreePlaylistInfo playlistInfo = this._playlistInfoContainer.GetPlaylist(playlistID);
            IListVideoInfo    videoInfo    = this._videoInfoContainer.GetVideo(video.NiconicoId);

            if (!playlistInfo.Videos.Any(v => v.Id.Value == videoID))
            {
                playlistInfo.Videos.Add(videoInfo);
            }

            return(result);
        }
Beispiel #4
0
        public IAttemptResult <ITreePlaylistInfo> GetRootPlaylist()
        {
            IAttemptResult <STypes::Playlist> result = this._playlistStoreHandler.GetRootPlaylist();

            if (!result.IsSucceeded || result.Data is null)
            {
                return(AttemptResult <ITreePlaylistInfo> .Fail(result.Message));
            }

            ITreePlaylistInfo converted = this._converter.ConvertStorePlaylistToLocalPlaylist(result.Data);

            return(AttemptResult <ITreePlaylistInfo> .Succeeded(converted));
        }
Beispiel #5
0
 /// <summary>
 /// データをセットする
 /// </summary>
 /// <param name="dbPlaylist"></param>
 /// <param name="playlistInfo"></param>
 private void SetData(STypes::Playlist dbPlaylist, ITreePlaylistInfo playlistInfo)
 {
     dbPlaylist.PlaylistName = playlistInfo.Name.Value;
     dbPlaylist.FolderPath   = playlistInfo.Folderpath;
     dbPlaylist.IsExpanded   = playlistInfo.IsExpanded;
     dbPlaylist.CustomVideoSequence.Clear();
     dbPlaylist.CustomVideoSequence.AddRange(playlistInfo.CustomSortSequence);
     dbPlaylist.SortType                   = playlistInfo.VideoSortType;
     dbPlaylist.IsVideoDescending          = playlistInfo.IsVideoDescending;
     dbPlaylist.IsTemporary                = playlistInfo.IsTemporary;
     dbPlaylist.IsDownloadSucceededHistory = playlistInfo.IsDownloadSucceededHistory;
     dbPlaylist.IsDownloadFailedHistory    = playlistInfo.IsDownloadFailedHistory;
     dbPlaylist.BookMarkedVideoID          = playlistInfo.BookMarkedVideoID;
 }
Beispiel #6
0
        public IAttemptResult BookMark(int videoID, int playlistID)
        {
            IAttemptResult <ITreePlaylistInfo> result = this.GetPlaylist(playlistID);

            if (!result.IsSucceeded || result.Data is null)
            {
                return(AttemptResult.Fail(result.Message));
            }

            ITreePlaylistInfo playlist = result.Data;

            playlist.BookMarkedVideoID = videoID;

            return(this.Update(playlist));
        }
Beispiel #7
0
        public IAttemptResult <ITreePlaylistInfo> GetSpecialPlaylist(SpecialPlaylistTypes types)
        {
            IAttemptResult <STypes::Playlist> result = types switch
            {
                SpecialPlaylistTypes.DLFailedHistory => this._playlistStoreHandler.GetPlaylist(p => p.IsDownloadFailedHistory),
                _ => this._playlistStoreHandler.GetPlaylist(p => p.IsDownloadSucceededHistory),
            };

            if (!result.IsSucceeded || result.Data is null)
            {
                return(AttemptResult <ITreePlaylistInfo> .Fail(result.Message));
            }

            ITreePlaylistInfo converted = this._converter.ConvertStorePlaylistToLocalPlaylist(result.Data);

            return(AttemptResult <ITreePlaylistInfo> .Succeeded(converted));
        }
Beispiel #8
0
        public IAttemptResult SetAsRemotePlaylist(int playlistId, string remoteID, string name, RemoteType type)
        {
            IAttemptResult result = this._playlistStoreHandler.SetAsRemotePlaylist(playlistId, remoteID, type);

            if (!result.IsSucceeded)
            {
                return(result);
            }

            bool autoRename = this._settingHandler.GetBoolSetting(SettingsEnum.AutoRenameNetPlaylist);

            if (!autoRename)
            {
                return(AttemptResult.Succeeded());
            }

            string playlistName = type switch
            {
                RemoteType.Mylist => name,
                RemoteType.UserVideos => $"{name}さんの投稿動画",
                RemoteType.WatchLater => "あとで見る",
                RemoteType.Channel => name,
                RemoteType.Series => name,
                _ => name,
            };

            if (string.IsNullOrEmpty(name))
            {
                return(AttemptResult.Succeeded());
            }

            IAttemptResult <ITreePlaylistInfo> pResult = this.GetPlaylist(playlistId);

            if (!pResult.IsSucceeded || pResult.Data is null)
            {
                return(AttemptResult.Fail(pResult.Message));
            }

            ITreePlaylistInfo playlist = pResult.Data;

            playlist.Name.Value = playlistName;
            IAttemptResult uResult = this.Update(playlist);

            return(uResult);
        }
Beispiel #9
0
        public void ツリーを構築する()
        {
            ITreePlaylistInfo tree = this.handler.Playlists.First();

            //子プレイリストの概観チェック
            Assert.AreEqual(2, tree.Children.Count);
            Assert.AreEqual(1, tree.Children[0].Children.Count);
            Assert.AreEqual(3, tree.Children[0].Children[0].Children.Count);

            //子プレイリストの詳細チェック
            Assert.AreEqual(1, tree.Id);
            Assert.AreEqual(2, tree.Children[0].Id);
            Assert.AreEqual(3, tree.Children[1].Id);
            Assert.AreEqual(4, tree.Children[0].Children[0].Id);
            Assert.AreEqual(5, tree.Children[0].Children[0].Children[0].Id);
            Assert.AreEqual(6, tree.Children[0].Children[0].Children[1].Id);
            Assert.AreEqual(7, tree.Children[0].Children[0].Children[2].Id);
        }
Beispiel #10
0
        private IAttemptResult SetPlaylists(bool expandAll = false, bool inheritExpandedState = false, bool isInitialRefresh = false)
        {
            //プレイリスト
            var list = new List <ITreePlaylistInfo>();

            //プレイリストを取得する
            IAttemptResult <List <STypes::Playlist> > pResult = this._playlistStoreHandler.GetAllPlaylists();

            if (!pResult.IsSucceeded || pResult.Data is null)
            {
                return(AttemptResult.Fail());
            }

            for (var i = 0; i < pResult.Data.Count; ++i)
            {
                STypes::Playlist p = pResult.Data[i];

                ITreePlaylistInfo playlist = this._converter.ConvertStorePlaylistToLocalPlaylist(p);

                var ex = playlist.IsExpanded;

                if (isInitialRefresh && !inheritExpandedState)
                {
                    ex = false;
                }

                if (expandAll)
                {
                    ex = true;
                }
                else if (inheritExpandedState)
                {
                    ex = p.IsExpanded;
                }

                playlist.IsExpanded = ex;
                list.Add(playlist);
            }

            this._treeHandler.Initialize(list);

            return(AttemptResult.Succeeded());
        }
Beispiel #11
0
        public IAttemptResult UnWireVideoToPlaylist(int videoID, int playlistID)
        {
            IAttemptResult <STypes::Video> vResult = this._videoStoreHandler.GetVideo(videoID);

            if (!vResult.IsSucceeded || vResult.Data is null)
            {
                return(AttemptResult.Fail("削除する動画はDBに保存されていません。"));
            }

            STypes::Video     video        = vResult.Data;
            ITreePlaylistInfo playlistInfo = this._playlistInfoContainer.GetPlaylist(playlistID);
            IListVideoInfo    videoInfo    = this._videoInfoContainer.GetVideo(video.NiconicoId);

            playlistInfo.Videos.RemoveAll(v => v.Id.Value == videoID);

            IAttemptResult result = this._playlistStoreHandler.UnWireVideo(videoID, playlistID);

            return(result);
        }
Beispiel #12
0
        public IAttemptResult Update(ITreePlaylistInfo newpaylist)
        {
            if (!this._playlistStoreHandler.Exists(newpaylist.Id))
            {
                return(AttemptResult.Fail("指定されたプレイリストが存在しません。"));
            }

            STypes::Playlist converted = this._converter.ConvertLocalPlaylistToStorePlaylist(newpaylist);

            IAttemptResult result = this._playlistStoreHandler.Update(converted);

            if (!result.IsSucceeded)
            {
                return(AttemptResult.Fail());
            }

            this._treeHandler.MergeRange(new List <ITreePlaylistInfo> {
                newpaylist
            });

            return(AttemptResult.Succeeded());
        }
        public PlaylistEditViewModel(ITreePlaylistInfo playlist)
        {
            this.playlist     = playlist;
            this.PlaylistName = this.playlist.Name.Value ?? string.Empty;
            this.FolderPath   = this.playlist.Folderpath ?? string.Empty;

            this.OnExit = new CommandBase <Window>(arg => true, arg =>
            {
                var oldPlaylist = this.playlist;
                if (oldPlaylist is not null && (oldPlaylist.Name.Value != this.PlaylistName || oldPlaylist.Folderpath != this.FolderPath))
                {
                    var newPlaylist        = oldPlaylist.Clone();
                    newPlaylist.Name.Value = this.PlaylistName;
                    newPlaylist.Folderpath = this.FolderPath;
                    WS::Mainpage.PlaylistHandler.Update(newPlaylist);
                    WS::Mainpage.CurrentPlaylist.SelectedPlaylist.Value = newPlaylist;
                }

                if (arg is not null && arg is Window window)
                {
                    window.Close();
                }
            });
Beispiel #14
0
 public XenoImportResult(ITreePlaylistInfo playlist)
 {
     this.PlaylistInfo = playlist;
 }
Beispiel #15
0
 public IAttemptResult Update(ITreePlaylistInfo newpaylist)
 {
     return(AttemptResult.Succeeded());
 }