Beispiel #1
0
        private async Task <IAttemptResult> EncodeVideosAsync(IWatchSession session, IDownloadContext context, IDownloadSettings settings, Action <string> onMessage, IEnumerable <string> segmentFilePaths, CancellationToken token)
        {
            var encodeSetting = new EncodeSettings()
            {
                FilePath           = context.FileName,
                CommandFormat      = settings.CommandFormat,
                TsFilePaths        = segmentFilePaths,
                IsOverwriteEnable  = settings.Overwrite,
                IsOverrideDTEnable = settings.OverrideVideoFileDateToUploadedDT,
                UploadedOn         = session.Video !.DmcInfo.UploadedOn,
                IsNoEncodeEnable   = settings.SaveWithoutEncode,
            };

            try
            {
                await this._encorder.EncodeAsync(encodeSetting, onMessage, token);
            }
            catch (Exception e)
            {
                this._logger.Error($"ファイルの変換中にエラーが発生しました。({this.context!.GetLogContent()})", e);
                onMessage("動画の変換中にエラー発生");
                return(AttemptResult.Fail($"ファイルの変換中にエラーが発生しました。(詳細: {e.Message})"));
            }

            return(AttemptResult.Succeeded());
        }
Beispiel #2
0
        public async Task <IAttemptResult <string> > BuildRequestAsync(IDmcInfo dmcInfo, ICommentFetchOption option, string key)
        {
            IAttemptResult <List <Request::RequestRoot> > result;

            try
            {
                result = await this.BuildRequestAsyncInternal(dmcInfo, option, key);
            }
            catch (Exception ex)
            {
                this._logger.Error("リクエストの構築中にエラーが発生しました。", ex);
                return(AttemptResult <string> .Fail($"リクエストの構築中にエラーが発生しました。(詳細:{ex.Message})"));
            }

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

            string json;

            try
            {
                json = JsonParser.Serialize(result.Data);
            }
            catch (Exception ex)
            {
                this._logger.Error("リクエストのシリアライズ中にエラーが発生しました。", ex);
                return(AttemptResult <string> .Fail($"リクエストのシリアライズ中にエラーが発生しました。(詳細:{ex.Message})"));
            }

            return(AttemptResult <string> .Succeeded(json));
        }
        public IAttemptResult <int> AddVideo(STypes::Video video)
        {
            //既にデータベースに存在する場合は再利用
            if (this.Exists(video.NiconicoId))
            {
                IAttemptResult <STypes::Video> vResult = this.GetVideo(video.NiconicoId);

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


                //動画情報が存在する場合は更新
                if (string.IsNullOrEmpty(video.Title))
                {
                    return(AttemptResult <int> .Succeeded(vResult.Data.Id));
                }

                video.Id = vResult.Data.Id;

                IAttemptResult uResult = this.UpdateInternal(video);

                if (uResult.IsSucceeded)
                {
                    this._logger.Log($"動画を上書きモードで追加しました。(niconicoID:{video.NiconicoId})");
                }

                return(uResult.IsSucceeded switch
                {
                    true => AttemptResult <int> .Succeeded(vResult.Data.Id),
                    _ => AttemptResult <int> .Fail(uResult.Message)
                });
Beispiel #4
0
        public IAttemptResult UnWireVideo(int videoId, int playlistId)
        {
            if (!this.Exists(playlistId))
            {
                return(AttemptResult.Fail("指定したプレイリストが存在しません。"));
            }

            IAttemptResult <STypes::Playlist> pResult = this.GetPlaylist(playlistId);

            if (!pResult.IsSucceeded || pResult.Data is null)
            {
                return(AttemptResult.Fail("プレイリストの取得に失敗しました。"));
            }

            STypes::Playlist playlist = pResult.Data;

            playlist.Videos.RemoveAll(v => v.Id == videoId);
            playlist.CustomVideoSequence.RemoveAll(v => v == videoId);

            var uResult = this.databaseInstance.Update(playlist, STypes::Playlist.TableName);

            if (!uResult.IsSucceeded)
            {
                return(AttemptResult.Fail($"動画の削除に失敗しました。(詳細:{uResult.ExceptionMessage})"));
            }

            this.logger.Log($"{playlist.PlaylistName}からの動画({videoId})を削除しました。");

            return(AttemptResult.Succeeded());
        }
        public override IAttemptResult Initialize()
        {
            string        appData = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData);
            List <string> packages;

            try
            {
                packages = this._directoryIO.GetDirectorys(Path.Combine(appData, "Packages"), "Mozilla.Firefox*");
            }
            catch (Exception e)
            {
                this._logger.Error("Microsoft Store版Firefoxアプリフォルダーの取得に失敗しました。", e);
                return(AttemptResult.Fail("Microsoft Store版Firefoxアプリフォルダーの取得に失敗しました。"));
            }

            if (packages.Count == 0)
            {
                return(AttemptResult.Fail("プロファイルの取得に失敗しました。"));
            }

            string profileRoot = Path.Combine(packages[0], @"LocalCache\Roaming\Mozilla\Firefox\Profiles");

            if (this._directoryIO.Exists(profileRoot))
            {
                this.profileFolder = profileRoot;
                this.isInitialized = true;
                return(AttemptResult.Succeeded());
            }
            else
            {
                return(AttemptResult.Fail("プロファイルフォルダーが存在しません、"));
            }
        }
Beispiel #6
0
        public IAttemptResult <STypes::Playlist> GetPlaylist(Expression <Func <STypes::Playlist, bool> > predicate)
        {
            IAttemptResult <STypes::Playlist> result = this.databaseInstance.GetRecord <STypes::Playlist>(STypes::Playlist.TableName, predicate);

            if (!result.IsSucceeded || result.Data is null)
            {
                if (result.Exception is not null)
                {
                    this.logger.Error("プレイリストの取得に失敗しました。", result.Exception);
                }
                else
                {
                    this.logger.Error("プレイリストの取得に失敗しました。");
                }

                return(AttemptResult <STypes::Playlist> .Fail("プレイリストの取得に失敗しました。"));
            }


            if (result.Data.Videos.Count > 0 && result.Data.CustomVideoSequence.Count != result.Data.Videos.Count)
            {
                var ids = result.Data.Videos.Select(v => v.Id).Where(id => !result.Data.CustomVideoSequence.Contains(id));
                result.Data.CustomVideoSequence.AddRange(ids);
            }

            this.logger.Log($"プレイリスト(name:{result.Data.PlaylistName}, ID:{result.Data.Id})を取得しました。");
            return(AttemptResult <STypes::Playlist> .Succeeded(result.Data));
        }
Beispiel #7
0
        /// <summary>
        /// 子プレイリストを辿って削除する
        /// </summary>
        /// <param name="parentId"></param>
        private IAttemptResult RemoveChildPlaylist(STypes::Playlist self)
        {
            if (self.IsConcretePlaylist)
            {
                return(AttemptResult.Succeeded());
            }

            IAttemptResult <List <STypes::Playlist> > cResult = this.GetChildPlaylists(self.Id);

            if (!cResult.IsSucceeded || cResult.Data is null)
            {
                return(AttemptResult.Fail("子プレイリストの取得に失敗しました。"));
            }

            foreach (var childPlaylist in cResult.Data)
            {
                IAttemptResult crResult = this.RemoveChildPlaylist(childPlaylist);
                if (!crResult.IsSucceeded)
                {
                    return(AttemptResult.Fail("子孫プレイリストの削除に失敗しました。"));
                }

                IAttemptResult dResul = this.DeletePlaylist(childPlaylist.Id);
                if (!dResul.IsSucceeded)
                {
                    return(AttemptResult.Fail("子プレイリストの削除に失敗しました。"));
                }

                this.logger.Log($"{self.Id}の子プレイリストを削除しました。");
            }

            return(AttemptResult.Succeeded());
        }
        public async Task <IAttemptResult <IListVideoInfo> > GetVideoListInfoAsync(string id, CancellationToken?ct = null)
        {
            IListVideoInfo video = this._videoInfoContainer.GetVideo(id);

            bool registerOnlyID = this._settingHandler.GetBoolSetting(SettingsEnum.StoreOnlyNiconicoID);

            if (registerOnlyID)
            {
                return(AttemptResult <IListVideoInfo> .Succeeded(video));
            }



            this._messageHandler.AppendMessage($"{id}の取得を開始します。");

            IAttemptResult <IListVideoInfo> result = await this._wacthPagehandler.TryGetVideoInfoAsync(id);

            if (!result.IsSucceeded || result.Data is null)
            {
                this._messageHandler.AppendMessage($"{id}の取得に失敗しました。(詳細:{result.Message})");
                return(AttemptResult <IListVideoInfo> .Fail($"{id}の取得に失敗しました。(詳細:{result.Message})"));
            }
            else
            {
                this._messageHandler.AppendMessage($"{id}の取得に成功しました。");
                video.SetNewData(result.Data);
            }

            return(AttemptResult <IListVideoInfo> .Succeeded(video));
        }
Beispiel #9
0
        /// <summary>
        /// Thread要求を構築する
        /// </summary>
        /// <param name="threadInfo"></param>
        /// <param name="dmcInfo"></param>
        /// <param name="option"></param>
        /// <returns></returns>
        private async Task <IAttemptResult <Request::Thread> > GetThreadAsync(IThread threadInfo, IDmcInfo dmcInfo, ICommentFetchOption option)
        {
            var thread = new Request::Thread()
            {
                ThreadNo   = threadInfo.ID.ToString(),
                UserID     = dmcInfo.UserId,
                Fork       = threadInfo.Fork,
                Language   = 0,
                WithGlobal = 1,
                Scores     = 1,
                Nicoru     = 3,
                Force184   = threadInfo.Is184Forced ? "1" : null,
            };

            //投コメを判定
            if (threadInfo.IsOwnerThread)
            {
                thread.ResFrom = -1000;
                thread.Version = "20061206";
            }
            else
            {
                thread.Version = "20090904";
            }

            //Force184?
            if (threadInfo.Is184Forced)
            {
                thread.Force184 = "1";
            }


            //公式動画を判別
            if (threadInfo.IsThreadkeyRequired)
            {
                thread.ThreadKey = threadInfo.Threadkey;
            }
            else
            {
                thread.UserKey = dmcInfo.Userkey;
            }

            //過去ログ
            if (option.DownloadLog)
            {
                IAttemptResult <WayBackKey> wResult = await this._officialCommentHandler.GetWayBackKeyAsync(threadInfo.ID.ToString());

                if (!wResult.IsSucceeded || wResult.Data is null)
                {
                    return(AttemptResult <Request::Thread> .Fail(wResult.Message));
                }

                thread.When       = option.When;
                thread.WayBackKey = wResult.Data.Key;
            }

            return(AttemptResult <Request::Thread> .Succeeded(thread));
        }
Beispiel #10
0
        public IAttemptResult <LocalCommentInfo> LoadComment(string folderPath, string niconicoID)
        {
            string?path = this.GetCommentFilePath(folderPath, niconicoID);

            if (path is null)
            {
                return(AttemptResult <LocalCommentInfo> .Fail("コメントファイルが存在しません。"));
            }

            string content;

            try
            {
                content = this._fileIO.OpenRead(path);
            }
            catch (Exception ex)
            {
                this._logger.Error("コメントファイルの読み込みに失敗しました。", ex);
                return(AttemptResult <LocalCommentInfo> .Fail($"コメントファイルの読み込みに失敗しました。(詳細:{ex.Message})"));
            }

            V2::PacketElement?data;

            try
            {
                data = Xmlparser.Deserialize <V2::PacketElement>(content);
            }
            catch (Exception ex)
            {
                this._logger.Error("コメントファイルの解析に失敗しました。", ex);
                return(AttemptResult <LocalCommentInfo> .Fail($"コメントファイルの解析に失敗しました。(詳細:{ ex.Message})"));
            }

            if (data is null)
            {
                return(AttemptResult <LocalCommentInfo> .Fail("コメントファイルの解析に失敗しました。"));
            }

            DateTime lastUpdatedTime;

            try
            {
                var info = new FileInfo(path);
                lastUpdatedTime = info.LastWriteTime;
            }
            catch (Exception ex)
            {
                this._logger.Error("コメントファイル情報の取得に失敗しました。", ex);
                return(AttemptResult <LocalCommentInfo> .Fail($"コメントファイル情報の取得に失敗しました。(詳細:{ex.Message})"));
            }

            var converted = data.Chat.Select(c => this._converter.ConvertChatToCoreComment(c));

            return(AttemptResult <LocalCommentInfo> .Succeeded(new LocalCommentInfo(lastUpdatedTime, converted)));
        }
Beispiel #11
0
        public IAttemptResult <IEnumerable <ITreePlaylistInfo> > GetAllPlaylists()
        {
            IAttemptResult <List <STypes::Playlist> > result = this._playlistStoreHandler.GetAllPlaylists();

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

            return(AttemptResult <IEnumerable <ITreePlaylistInfo> > .Succeeded(result.Data.Select(p => this._converter.ConvertStorePlaylistToLocalPlaylist(p))));
        }
Beispiel #12
0
        /// <summary>
        /// ThreadLeaves要求を取得
        /// </summary>
        /// <param name="thread"></param>
        /// <param name="dmcInfo"></param>
        /// <param name="option"></param>
        /// <param name="wayBackKey"></param>
        /// <returns></returns>
        private IAttemptResult <Request::ThreadLeaves> GetThreadLeaves(IThread thread, IDmcInfo dmcInfo, ICommentFetchOption option, string?wayBackKey)
        {
            var leaves = new Request::ThreadLeaves()
            {
                ThreadNo = thread.ID.ToString(),
                UserID   = dmcInfo.UserId,
                Fork     = thread.Fork,
                Language = 0,
                Scores   = 1,
                Nicoru   = 3,
            };

            //force184?
            if (thread.Is184Forced)
            {
                leaves.Force184 = "1";
            }

            //公式動画を判別
            if (thread.IsThreadkeyRequired)
            {
                leaves.ThreadKey = thread.Threadkey;
            }
            else
            {
                leaves.UserKey = dmcInfo.Userkey;
            }

            //過去ログ
            if (option.DownloadLog)
            {
                leaves.When       = option.When;
                leaves.WayBackKey = wayBackKey;
            }

            int flooredDuration;

            try
            {
                flooredDuration = (int)Math.Floor(dmcInfo.Duration / 60f);
            }
            catch (Exception ex)
            {
                this._logger.Error($"動画再生時間の計算に失敗しました。", ex);
                return(AttemptResult <Request::ThreadLeaves> .Fail($"動画再生時間の計算に失敗しました。(詳細:{ex.Message})"));
            }

            //leaves.Content = $"0-{flooredDuration}:100,1000:nicoru:100";
            leaves.Content = "1000";

            return(AttemptResult <Request::ThreadLeaves> .Succeeded(leaves));
        }
Beispiel #13
0
        public IAttemptResult <IEnumerable <IListVideoInfo> > GetAllVideos()
        {
            IAttemptResult <List <STypes::Video> > sResult = this._videoStoreHandler.GetAllVideos();

            if (!sResult.IsSucceeded || sResult.Data is null)
            {
                return(AttemptResult <IEnumerable <IListVideoInfo> > .Fail(sResult.Message));
            }

            IEnumerable <IListVideoInfo> converted = sResult.Data.Select(v => this._converter.ConvertStoreVideoToLocalVideo(v));

            return(AttemptResult <IEnumerable <IListVideoInfo> > .Succeeded(converted));
        }
Beispiel #14
0
        public IAttemptResult DeletePlaylist(int playlistID)
        {
            IAttemptResult dResult = this._playlistStoreHandler.DeletePlaylist(playlistID);

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

            this._treeHandler.Remove(playlistID);

            return(AttemptResult.Succeeded());
        }
Beispiel #15
0
        public IAttemptResult <IListVideoInfo> GetVideo(int id)
        {
            IAttemptResult <STypes::Video> sResult = this._videoStoreHandler.GetVideo(id);

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

            IListVideoInfo converted = this._converter.ConvertStoreVideoToLocalVideo(sResult.Data);

            return(AttemptResult <IListVideoInfo> .Succeeded(converted));
        }
Beispiel #16
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 #17
0
        public IAttemptResult Update(STypes::Playlist playlist)
        {
            if (!this.Exists(playlist.Id))
            {
                this.logger.Error($"存在しないプレイリストに対して更新が試行されました。(name:{playlist.PlaylistName}, ID:{playlist.Id})");
                return(AttemptResult.Fail("存在しないプレイリストに対して更新が試行されました。"));
            }

            this.databaseInstance.Update(playlist, STypes::Playlist.TableName);

            this.logger.Log($"プレイリスト(name:{playlist.PlaylistName}, ID:{playlist.Id})を更新しました。");

            return(AttemptResult.Succeeded());
        }
Beispiel #18
0
        private async Task <IAttemptResult> DownloadVideoInternalAsync(IStreamInfo targetStream, Action <string> onMessage, IDownloadContext context, int maxParallelSegmentDLCount, string segmentDirectoryName, CancellationToken token)
        {
            try
            {
                await this._videoDownloadHelper.DownloadAsync(targetStream, onMessage, context, maxParallelSegmentDLCount, segmentDirectoryName, token);
            }
            catch (Exception e)
            {
                this._logger.Error($"動画のダウンロード中にエラーが発生しました。({this.context!.GetLogContent()})", e);
                onMessage("動画のダウンロードに失敗");
                return(AttemptResult.Fail($"動画のダウンロード中にエラーが発生しました。(詳細: {e.Message})"));
            }

            return(AttemptResult.Succeeded());
        }
Beispiel #19
0
        public IAttemptResult Initialize()
        {
            if (this.isInitialized)
            {
                return(AttemptResult.Succeeded());
            }

            IAttemptResult result = this.profileManager.Initialize();

            if (result.IsSucceeded)
            {
                this.isInitialized = true;
            }

            return(result);
        }
Beispiel #20
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 #21
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 #22
0
        public async Task <IAttemptResult> DownloadThumbnailAsync(IDownloadSettings settings, IWatchSession session)
        {
            if (session.Video is null)
            {
                return(AttemptResult.Fail("動画情報が未取得です。"));
            }

            var filepath = this._pathOrganizer.GetFilePath(settings.FileNameFormat, session.Video !.DmcInfo, settings.ThumbnailExt, settings.FolderPath, settings.IsReplaceStrictedEnable, settings.Overwrite, settings.ThumbSuffix);

            string?thumbUrl;

            try
            {
                thumbUrl = session.Video !.DmcInfo.ThumbInfo.GetSpecifiedThumbnail(settings.ThumbSize);
            }
            catch (Exception e)
            {
                this._logger.Error($"サムネイルURLの取得に失敗しました。", e);
                return(AttemptResult.Fail("サムネイルのURLを取得できませんでした。"));
            }


            byte[] data;
            try
            {
                data = await this.DownloadAsync(thumbUrl);
            }
            catch (Exception e)
            {
                this._logger.Error($"サムネイルの取得に失敗しました。", e);
                return(AttemptResult.Fail($"サムネイルの取得に失敗しました。(詳細: {e.Message})"));
            }

            try
            {
                this.WriteThumb(data, filepath);
            }
            catch (Exception e)
            {
                this._logger.Error($"サムネイルの保存に失敗しました。", e);
                return(AttemptResult.Fail($"サムネイルの保存に失敗しました。(詳細: {e.Message})"));
            }

            return(AttemptResult.Succeeded());
        }
Beispiel #23
0
        private async Task <IAttemptResult <IStreamInfo> > GetStream(IWatchSession session, uint resolution)
        {
            IStreamInfo targetStream;

            try
            {
                IStreamsCollection streams = await session.GetAvailableStreamsAsync();

                targetStream = streams.GetStream(resolution);
            }
            catch (Exception e)
            {
                this._logger.Error($"ストリームの取得に失敗しました。({this.context!.GetLogContent()})", e);
                return(AttemptResult <IStreamInfo> .Fail("ストリームの取得に失敗しました。", e));
            }

            return(AttemptResult <IStreamInfo> .Succeeded(targetStream));
        }
Beispiel #24
0
        public IAttemptResult <int> AddPlaylistToRoot()
        {
            IAttemptResult <ITreePlaylistInfo> rResult = this.GetRootPlaylist();

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

            IAttemptResult <int> result = this.AddPlaylist(rResult.Data.Id);

            if (!result.IsSucceeded)
            {
                return(AttemptResult <int> .Fail(result.Message));
            }

            return(AttemptResult <int> .Succeeded(result.Data));
        }
Beispiel #25
0
        private IAttemptResult FixPlaylist(STypes::Playlist playlist)
        {
            //親が存在しないプレイリスト(孤児プレイリスト)の場合はそれ自体を削除
            if (playlist.ParentPlaylist is not null && !this.Exists(playlist.ParentPlaylist.Id))
            {
                IAttemptResult dResult = this.DeletePlaylist(playlist.Id);

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

                this.logger.Log($"孤児プレイリスト(name:{playlist.PlaylistName}, ID:{playlist.Id})を削除しました。");
                return(AttemptResult.Succeeded());
            }

            //並び替え情報を実際の動画と揃える
            if (playlist.Videos.Count > 0 && playlist.Videos.Count != playlist.CustomVideoSequence.Count)
            {
                if (playlist.Videos.Count > playlist.CustomVideoSequence.Count)
                {
                    var videosToAdd = playlist.Videos.Select(v => v.Id).Where(id => !playlist.CustomVideoSequence.Contains(id));
                    playlist.CustomVideoSequence.AddRange(videosToAdd);
                }
                else
                {
                    var videoIDs    = playlist.Videos.Select(v => v.Id).ToList();
                    var newSequence = playlist.CustomVideoSequence.Where(id => videoIDs.Contains(id));
                    playlist.CustomVideoSequence.Clear();
                    playlist.CustomVideoSequence.AddRange(newSequence);
                }

                IAttemptResult uResult = this.Update(playlist);

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

                this.logger.Log($"並び替え順情報を登録されている動画数と同期しました。(id:{playlist.Id})");
            }

            return(AttemptResult.Succeeded());
        }
Beispiel #26
0
        public IAttemptResult DeletePlaylist(int playlistID)
        {
            if (!this.Exists(playlistID))
            {
                this.logger.Error("存在しないプレイリストに対して削除が試行されました。");
                return(AttemptResult.Fail("存在しないプレイリストに対して削除が試行されました。"));
            }

            IAttemptResult <STypes::Playlist> result = this.GetPlaylist(playlistID);

            if (!result.IsSucceeded || result.Data is null)
            {
                this.logger.Error("削除対象のプレイリストの取得に失敗しました。");
                return(AttemptResult.Fail("削除対象のプレイリストの取得に失敗しました。"));
            }

            STypes::Playlist playlist = result.Data;


            //ルートプレイリストは削除禁止
            if (playlist.IsRoot || playlist.Layer == 1 || playlist !.IsTemporary || playlist !.IsDownloadFailedHistory || playlist !.IsDownloadSucceededHistory)
            {
                this.logger.Log($"削除できないプレイリストに対する削除が試行されました。(isRoot:{playlist.IsRoot}, layer:{playlist.Layer}, isTmp:{playlist.IsTemporary}, isFailed:{ playlist.IsDownloadFailedHistory}, IsSucceeeded:{playlist.IsDownloadSucceededHistory})");
                return(AttemptResult.Fail("削除できないプレイリストに対する削除が試行されました。"));
            }

            IAttemptResult cResult = this.RemoveChildPlaylist(playlist);

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

            IAttemptResult <bool> deleteResult = this.databaseInstance.Delete(STypes::Playlist.TableName, playlistID);

            if (!deleteResult.IsSucceeded || !deleteResult.Data)
            {
                return(AttemptResult.Fail("プレイリストの削除に失敗しました。"));
            }

            this.logger.Log($"{playlistID}を削除しました。");

            return(AttemptResult.Succeeded());
        }
Beispiel #27
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 #28
0
        public IAttemptResult SaveAllPlaylists()
        {
            var playlists = this._treeHandler.GetAllPlaylists();

            foreach (var p in playlists)
            {
                if (!this._playlistStoreHandler.Exists(p.Id))
                {
                    continue;
                }
                IAttemptResult result = this.Update(p);

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

            return(AttemptResult.Succeeded());
        }
Beispiel #29
0
        public IAttemptResult WireVideo(STypes::Video video, int playlistId)
        {
            if (!this.Exists(playlistId))
            {
                return(AttemptResult.Fail("指定したプレイリストが存在しません。"));
            }

            IAttemptResult <STypes::Playlist> pResult = this.GetPlaylist(playlistId);

            if (!pResult.IsSucceeded || pResult.Data is null)
            {
                return(AttemptResult.Fail("プレイリストの取得に失敗しました。"));
            }

            STypes::Playlist playlist = pResult.Data;


            if (playlist.Videos is null)
            {
                playlist.Videos = new List <STypes.Video>();
            }

            if (playlist.Videos.Any(v => v.NiconicoId == video.NiconicoId))
            {
                return(AttemptResult.Fail("すでに登録されている動画です。"));
            }

            playlist.Videos.Add(video);
            playlist.CustomVideoSequence.Add(video.Id);

            IAttemptResult uResult = this.databaseInstance.Update(playlist, STypes::Playlist.TableName);

            if (!uResult.IsSucceeded)
            {
                return(AttemptResult.Fail($"動画の追加に失敗しました。(詳細:{uResult.ExceptionMessage})"));
            }

            this.logger.Log($"{video.NiconicoId}をプレイリスト({playlist.PlaylistName})に追加しました。");

            return(AttemptResult.Succeeded());
        }
Beispiel #30
0
        public IAttemptResult <List <STypes::Playlist> > GetChildPlaylists(int id)
        {
            var result = this.databaseInstance.GetAllRecords <STypes::Playlist>(STypes::Playlist.TableName, p => p.ParentPlaylist is null ? false : p.ParentPlaylist.Id == id);

            if (!result.IsSucceeded || result.Data is null)
            {
                if (result.Exception is not null)
                {
                    this.logger.Error("子プレイリストの取得に失敗しました。", result.Exception);
                }
                else
                {
                    this.logger.Error("子プレイリストの取得に失敗しました。");
                }

                return(AttemptResult <List <STypes::Playlist> > .Fail("子プレイリストの取得に失敗しました。"));
            }

            this.logger.Log($"{id}の子プレイリストを取得しました。");
            return(AttemptResult <List <STypes::Playlist> > .Succeeded(result.Data));
        }