コード例 #1
0
        public async Task <List <NicoVideo> > GetNicoVideoItemsAsync(params string[] idList)
        {
            List <NicoVideo> videos = new List <NicoVideo>();

            using (var releaser = await _VideoIdToNicoVideoLock.LockAsync())
            {
                foreach (var id in idList)
                {
                    NicoVideo nicoVideo = null;
                    if (false == _VideoIdToNicoVideo.ContainsKey(id))
                    {
                        nicoVideo = new NicoVideo(_HohoemaApp, id, _HohoemaApp.MediaManager);
                        _VideoIdToNicoVideo.Add(id, nicoVideo);
                    }
                    else
                    {
                        nicoVideo = _VideoIdToNicoVideo[id];
                    }

                    videos.Add(nicoVideo);
                }
            }

            foreach (var video in videos.AsParallel())
            {
                await video.Initialize();
            }

            return(videos);
        }
コード例 #2
0
        public override async Task <Uri> GenerateVideoContentUrl()
        {
            // Lowクオリティ
            await NicoVideo.VisitWatchPage();

            return(NicoVideo.LegacyVideoUrl);
        }
コード例 #3
0
        public async Task RequestCache(bool forceUpdate = false)
        {
            if (!CanDownload)
            {
                return;
            }

            var isCacheFileExist = false;

            using (var releaser = await _Lock.LockAsync())
            {
                isCacheFileExist = !forceUpdate && (IsCached || NowCacheDonwloading);
            }

            if (isCacheFileExist)
            {
                // update cached time
                await GetCacheFile();

                return;
            }

            using (var releaser = await _Lock.LockAsync())
            {
                VideoDownloadManager.DownloadStarted += VideoDownloadManager_DownloadStarted;
                IsCacheRequested = true;
                CacheState       = NicoVideoCacheState.Pending;

                VideoFileCreatedAt = DateTime.Now;

                await VideoDownloadManager.AddCacheRequest(NicoVideo.RawVideoId, Quality, forceUpdate);

                await NicoVideo.OnCacheRequested();
            }
        }
コード例 #4
0
 public DividedQualityNicoVideo(NicoVideoQuality quality, NicoVideo nicoVideo, NiconicoMediaManager mediaManager)
 {
     Quality              = quality;
     NicoVideo            = nicoVideo;
     HohoemaApp           = nicoVideo.HohoemaApp;
     NiconicoMediaManager = mediaManager;
     VideoDownloadManager = mediaManager.VideoDownloadManager;
 }
コード例 #5
0
        public override async Task <Uri> GenerateVideoContentUrl()
        {
            // Originalクオリティ
            if (NicoVideo.LegacyVideoUrl == null)
            {
                await NicoVideo.VisitWatchPage();
            }

            return(NicoVideo.LegacyVideoUrl);
        }
コード例 #6
0
ファイル: VideoCacheManager.cs プロジェクト: TaoziDB/Hohoema
        /// <summary>
        /// キャッシュダウンロードのタスクから
        /// ダウンロードの情報を復元します
        /// </summary>
        /// <returns></returns>
        private async Task RestoreBackgroundDownloadTask()
        {
            // TODO: ユーザーのログイン情報を更新してダウンロードを再開する必要がある?
            // ユーザー情報の有効期限が切れていた場合には最初からダウンロードし直す必要があるかもしれません
            var tasks = await BackgroundDownloader.GetCurrentDownloadsForTransferGroupAsync(_NicoCacheVideoBGTransferGroup);

            foreach (var task in tasks)
            {
                NicoVideoCacheProgress info = null;
                try
                {
                    var _info = VideoCacheManager.CacheRequestInfoFromFileName(task.ResultFile);

                    var nicoVideo = new NicoVideo(_info.RawVideoId, _HohoemaApp.ContentProvider, _HohoemaApp.NiconicoContext, _HohoemaApp.CacheManager);

                    var session = await nicoVideo.CreateVideoStreamingSession(_info.Quality, forceDownload : true);

                    if (session?.Quality == _info.Quality)
                    {
                        continue;
                    }

                    info = new NicoVideoCacheProgress(_info, task, session);

                    await RestoreDonloadOperation(info, task);

                    Debug.WriteLine($"実行中のキャッシュBGDLを補足: {info.RawVideoId} {info.Quality}");
                }
                catch
                {
                    Debug.WriteLine(task.ResultFile + "のキャッシュダウンロード操作を復元に失敗しました");
                    continue;
                }


                try
                {
                    task.Resume();
                }
                catch
                {
                    if (task.Progress.Status != BackgroundTransferStatus.Running)
                    {
                        await RemoveDownloadOperation(info);

                        // ダウンロード再開に失敗したらキャッシュリクエストに積み直します
                        // 失敗の通知はここではなくバックグラウンドタスクの 後処理 として渡されるかもしれません
                        DownloadProgress?.Invoke(this, info);
                    }
                }
            }
        }
コード例 #7
0
        internal async Task NotifyCacheForceDeleted(NicoVideo nicoVideo)
        {
            // キャッシュ登録を削除
            var videoInfo = await VideoInfoDb.GetAsync(nicoVideo.RawVideoId);

            if (videoInfo != null)
            {
                videoInfo.IsDeleted = true;
                await VideoInfoDb.UpdateAsync(videoInfo);
            }

            var toastService = App.Current.Container.Resolve <Views.Service.ToastNotificationService>();

            toastService.ShowText("動画削除:" + nicoVideo.RawVideoId
                                  , $"{nicoVideo.Title} はニコニコ動画サーバーから削除されたため、キャッシュを強制削除しました。"
                                  , Microsoft.Toolkit.Uwp.Notifications.ToastDuration.Long
                                  );
        }
コード例 #8
0
        public NGResult IsNgVideo(NicoVideo info)
        {
            NGResult result = null;

            result = IsNgVideoOwnerId(info.OwnerId.ToString());
            if (result != null)
            {
                return(result);
            }

            result = IsNGVideoId(info.RawVideoId);
            if (result != null)
            {
                return(result);
            }

            result = IsNGVideoTitle(info.Title);
            if (result != null)
            {
                return(result);
            }

            return(result);
        }
コード例 #9
0
        public async Task <NicoVideo> GetNicoVideoAsync(string rawVideoId, bool withInitialize = true)
        {
            NicoVideo nicoVideo = null;

            using (var releaser = await _VideoIdToNicoVideoLock.LockAsync())
            {
                if (false == _VideoIdToNicoVideo.ContainsKey(rawVideoId))
                {
                    nicoVideo = new NicoVideo(_HohoemaApp, rawVideoId, _HohoemaApp.MediaManager);
                    _VideoIdToNicoVideo.Add(rawVideoId, nicoVideo);
                }
                else
                {
                    nicoVideo = _VideoIdToNicoVideo[rawVideoId];
                }
            }

            if (withInitialize)
            {
                await nicoVideo.Initialize();
            }

            return(nicoVideo);
        }
コード例 #10
0
 public DmcQualityNicoVideo(NicoVideoQuality quality, NicoVideo nicoVideo, NiconicoMediaManager context)
     : base(quality, nicoVideo, context)
 {
 }
コード例 #11
0
 public OriginalQualityNicoVideo(NicoVideo nicoVideo, NiconicoMediaManager context)
     : base(NicoVideoQuality.Original, nicoVideo, context)
 {
 }
コード例 #12
0
 public LowQualityNicoVideo(NicoVideo nicoVideo, NiconicoMediaManager context)
     : base(NicoVideoQuality.Low, nicoVideo, context)
 {
 }
コード例 #13
0
 public DmcQualityNicoVideo(NicoVideoQuality quality, NicoVideo nicoVideo, VideoCacheManager context)
     : base(quality, nicoVideo, context)
 {
 }
コード例 #14
0
 public OriginalQualityNicoVideo(NicoVideo nicoVideo, VideoCacheManager context)
     : base(NicoVideoQuality.Smile_Original, nicoVideo, context)
 {
 }
コード例 #15
0
 public LowQualityNicoVideo(NicoVideo nicoVideo, VideoCacheManager context)
     : base(NicoVideoQuality.Smile_Low, nicoVideo, context)
 {
 }
コード例 #16
0
ファイル: VideoCacheManager.cs プロジェクト: TaoziDB/Hohoema
        // 次のキャッシュダウンロードを試行
        // ダウンロード用の本数
        private async Task TryNextCacheRequestedVideoDownload()
        {
            if (State != CacheManagerState.Running)
            {
                return;
            }

            NicoVideoCacheRequest nextDownloadItem = null;

            using (var releaser = await _CacheRequestProcessingLock.LockAsync())
            {
                while (CanAddDownloadLine)
                {
                    if (_DownloadOperations.Count == 0)
                    {
                        nextDownloadItem = _CacheDownloadPendingVideos
                                           .FirstOrDefault();
                    }

                    if (nextDownloadItem == null)
                    {
                        break;
                    }

                    if (_DownloadOperations.Any(x => x.RawVideoId == nextDownloadItem.RawVideoId && x.Quality == nextDownloadItem.Quality))
                    {
                        _CacheDownloadPendingVideos.Remove(nextDownloadItem);
                        break;
                    }

                    Debug.WriteLine($"キャッシュ準備を開始: {nextDownloadItem.RawVideoId} {nextDownloadItem.Quality}");

                    // 動画ダウンロードURLを取得
                    var nicoVideo = new NicoVideo(nextDownloadItem.RawVideoId, _HohoemaApp.ContentProvider, _HohoemaApp.NiconicoContext, _HohoemaApp.CacheManager);
                    var videoInfo = await _HohoemaApp.ContentProvider.GetNicoVideoInfo(nextDownloadItem.RawVideoId);

                    // DownloadSessionを保持して、再生完了時にDisposeさせる必要がある
                    var downloadSession = await nicoVideo.CreateVideoStreamingSession(nextDownloadItem.Quality, forceDownload : true);

                    var uri = await downloadSession.GetDownloadUrlAndSetupDonwloadSession();

                    var downloader = new BackgroundDownloader()
                    {
                        TransferGroup = _NicoCacheVideoBGTransferGroup
                    };

                    downloader.SuccessToastNotification = MakeSuccessToastNotification(videoInfo);
                    downloader.FailureToastNotification = MakeFailureToastNotification(videoInfo);

                    // 保存先ファイルの確保
                    var filename = VideoCacheManager.MakeCacheVideoFileName(
                        videoInfo.Title,
                        nextDownloadItem.RawVideoId,
                        videoInfo.MovieType,
                        downloadSession.Quality
                        );

                    var videoFolder = await _HohoemaApp.GetVideoCacheFolder();

                    var videoFile = await videoFolder.CreateFileAsync(filename, CreationCollisionOption.OpenIfExists);

                    // ダウンロード操作を作成
                    var operation = downloader.CreateDownload(uri, videoFile);

                    var progress = new NicoVideoCacheProgress(nextDownloadItem, operation, downloadSession);
                    await AddDownloadOperation(progress);


                    Debug.WriteLine($"キャッシュ準備完了: {nextDownloadItem.RawVideoId} {nextDownloadItem.Quality}");


                    // ダウンロードを開始

                    /*
                     * if (Helpers.ApiContractHelper.IsFallCreatorsUpdateAvailable)
                     * {
                     *  operation.IsRandomAccessRequired = true;
                     * }
                     */

                    var action = operation.StartAsync();
                    action.Progress = OnDownloadProgress;
                    var task = action.AsTask();
                    TaskIdToCacheProgress.Add(task.Id, progress);
                    var _ = task.ContinueWith(OnDownloadCompleted);



                    VideoCacheStateChanged?.Invoke(this, new VideoCacheStateChangedEventArgs()
                    {
                        CacheState = NicoVideoCacheState.Downloading,
                        Request    = progress
                    });

                    Debug.WriteLine($"キャッシュ開始: {nextDownloadItem.RawVideoId} {nextDownloadItem.Quality}");

                    SendUpdatableToastWithProgress(videoInfo.Title, nextDownloadItem);


                    // DL作業を作成できたらDL待ちリストから削除
                    _CacheDownloadPendingVideos.Remove(nextDownloadItem);

                    await SaveDownloadRequestItems();
                }
            }
        }