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)
                });
        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));
        }
        /// <summary>
        /// コメントをダウンロードする
        /// </summary>
        private async Task <IAttemptResult> TryDownloadCommentAsync(IDownloadSettings settings, IWatchSession session, Action <string> onMessage, IDownloadContext context, CancellationToken token)
        {
            Cdl::ICommentDownloader?      v1 = null;
            V2Comment::ICommentDownloader?v2 = null;

            if (settings.EnableExperimentalCommentSafetySystem)
            {
                v2 = DIFactory.Provider.GetRequiredService <V2Comment::ICommentDownloader>();
            }
            else
            {
                v1 = DIFactory.Provider.GetRequiredService <Cdl::ICommentDownloader>();
            }

            IAttemptResult result;

            try
            {
                result = v2 is null ? await v1 !.DownloadComment(session, settings, onMessage, context, token) : await v2.DownloadCommentAsync(session.Video !.DmcInfo, settings, context, token);
            }
            catch (Exception e)
            {
                this.logger.Error("コメントのダウンロードに失敗しました。", e);
                return(AttemptResult.Fail($"コメントのダウンロードに失敗しました。({e.Message})"));
            }

            return(result);
        }
Beispiel #4
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 #5
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 #6
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));
        }
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());
        }
Beispiel #8
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());
        }
Beispiel #9
0
        public IAttemptResult MoveVideoToPrev(int playlistID, int videoIndex)
        {
            if (!this.Exists(playlistID))
            {
                return new AttemptResult()
                       {
                           Message = $"指定されたプレイリストは存在しません。(id={playlistID})"
                       }
            }
            ;

            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.Count < videoIndex + 1)
            {
                return new AttemptResult()
                       {
                           Message = $"指定されたインデックスは範囲外です。(index={videoIndex}, actual={playlist.Videos.Count})"
                       }
            }
            ;

            if (videoIndex == 0)
            {
                return new AttemptResult()
                       {
                           Message = $"指定されたインデックスは最初の動画です。(index={videoIndex})"
                       }
            }
            ;

            try
            {
                playlist.CustomVideoSequence.InsertIntoPrev(videoIndex);
            }
            catch (Exception e)
            {
                return(new AttemptResult()
                {
                    Message = $"挿入操作に失敗しました。", Exception = e
                });
            }

            playlist.SortType = STypes.VideoSortType.Custom;

            this.Update(playlist);

            this.logger.Log($"{playlistID}の{videoIndex + 1}番目の動画を一つ後ろに挿入しました。");
            return(new AttemptResult()
            {
                IsSucceeded = true
            });
        }
Beispiel #10
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));
        }
Beispiel #11
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));
        }
        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 #13
0
        /// <summary>
        /// プレイリストを作成する
        /// </summary>
        /// <param name="videos"></param>
        /// <param name="directoryPath"></param>
        /// <param name="type"></param>
        /// <returns></returns>
        public IAttemptResult <int> TryCreatePlaylist(IEnumerable <Playlist::IListVideoInfo> videos, PlaylistType type)
        {
            if (this._current.SelectedPlaylist.Value is null)
            {
                return(AttemptResult <int> .Fail("プレイリストが選択されていません。"));
            }

            string playlistName  = this._current.SelectedPlaylist.Value.Name.Value;
            string directoryPath = this._current.PlaylistFolderPath;

            videos = videos.Where(v => v.IsDownloaded.Value);
            if (!videos.Any())
            {
                return(AttemptResult <int> .Fail("ダウンロードされた動画がありません。"));
            }

            int           allVideos  = videos.Count();
            List <string> videosPath = new();
            string        data;

            try
            {
                videosPath = videos.Select(v => v.FileName.Value).Where(p => this._fileIO.Exists(p)).ToList();
                data       = this._fileFactory.GetPlaylist(videosPath, playlistName, type);
            }
            catch (Exception e)
            {
                this._logger.Error("プレイリストの作成に失敗しました。", e);
                return(AttemptResult <int> .Fail("プレイリストの作成に失敗しました。"));
            }

            if (!this._directoryIO.Exists(directoryPath))
            {
                try
                {
                    this._directoryIO.Create(directoryPath);
                }
                catch (Exception e)
                {
                    this._logger.Error("ディレクトリーの作成に失敗しました。", e);
                    return(AttemptResult <int> .Fail("ディレクトリーの作成に失敗しました。"));
                }
            }

            try
            {
                this._fileIO.Write(Path.Combine(directoryPath, $"playlist.{this.GetExt(type)}"), data, encoding: this.GetEncording(type));
            }
            catch (Exception e)
            {
                this._logger.Error("プレイリストへの書き込みに失敗しました。", e);
                return(AttemptResult <int> .Fail("プレイリストへの書き込みに失敗しました。"));
            }

            return(new AttemptResult <int>()
            {
                IsSucceeded = true, Data = allVideos - videosPath.Count
            });
        }
Beispiel #14
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));
        }
        public void AttemptResult_Fail_IsFalse()
        {
            // arrange

            // act
            bool value = AttemptResult.Fail("This is a failure.");

            // assert
            Assert.False(value);
        }
Beispiel #16
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 #17
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 #18
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 #19
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 #20
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 #21
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 #22
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 #23
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 #24
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));
        }
        /// <summary>
        /// 市場情報をダウンロードする
        /// </summary>
        private async Task <IAttemptResult> DownloadIchibaInfoAsync(IDownloadSettings settings, IWatchSession session, Action <string> onMessage, IDownloadContext context)
        {
            var            iDownloader = DIFactory.Provider.GetRequiredService <IIchibaInfoDownloader>();
            IAttemptResult result;

            try
            {
                result = await iDownloader.DownloadIchibaInfo(session, settings, onMessage, context);
            }
            catch (Exception e)
            {
                this.logger.Error("市場情報のダウンロードに失敗しました。", e);
                return(AttemptResult.Fail($"市場情報のダウンロードに失敗しました。({e.Message})"));
            }
            return(result);
        }
        /// <summary>
        /// 非同期で動画をダウンロードする
        /// </summary>
        private async Task <IAttemptResult> TryDownloadVideoAsync(IDownloadSettings settings, Action <string> onMessage, IWatchSession session, IDownloadContext context, CancellationToken token)
        {
            var            videoDownloader = DIFactory.Provider.GetRequiredService <Vdl::IVideoDownloader>();
            IAttemptResult result;

            try
            {
                result = await videoDownloader.DownloadVideoAsync(settings, onMessage, context, session, token);
            }
            catch (Exception e)
            {
                this.logger.Error($"動画のダウンロードに失敗しました。({context.GetLogContent()})", e);
                return(AttemptResult.Fail($"動画のダウンロードに失敗しました。(詳細:{e.Message})"));
            }
            return(result);
        }
Beispiel #27
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));
        }
        /// <summary>
        /// サムネイルをダウンロードする
        /// </summary>
        private async Task <IAttemptResult> TryDownloadThumbAsync(IDownloadSettings setting, IWatchSession session)
        {
            var            thumbDownloader = DIFactory.Provider.GetRequiredService <Tdl::IThumbDownloader>();
            IAttemptResult result;

            try
            {
                result = await thumbDownloader.DownloadThumbnailAsync(setting, session);
            }
            catch (Exception e)
            {
                this.logger.Error($"サムネイルのダウンロードに失敗しました。", e);
                return(AttemptResult.Fail($"サムネイルのダウンロードに失敗しました。(詳細:{e.Message})"));
            }

            return(result);
        }
Beispiel #29
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 #30
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);
        }