示例#1
0
        private void OnDownloadProgress(object sender, DownloadOperation op)
        {
            Debug.WriteLine($"{op.RequestedUri}:{op.Progress.TotalBytesToReceive}");
            var info = NiconicoMediaManager.CacheRequestInfoFromFileName(op.ResultFile);

            DownloadProgress?.Invoke(this, info, op);
        }
示例#2
0
 public DividedQualityNicoVideo(NicoVideoQuality quality, NicoVideo nicoVideo, NiconicoMediaManager mediaManager)
 {
     Quality              = quality;
     NicoVideo            = nicoVideo;
     HohoemaApp           = nicoVideo.HohoemaApp;
     NiconicoMediaManager = mediaManager;
     VideoDownloadManager = mediaManager.VideoDownloadManager;
 }
示例#3
0
        static internal Task <NiconicoMediaManager> Create(HohoemaApp app)
        {
            var man = new NiconicoMediaManager(app);

//            await man.RetrieveCacheCompletedVideos();

            return(Task.FromResult(man));
        }
示例#4
0
        public NicoVideo(HohoemaApp app, string rawVideoid, NiconicoMediaManager manager)
        {
            HohoemaApp            = app;
            RawVideoId            = rawVideoid;
            _NiconicoMediaManager = manager;

            _InterfaceByQuality  = new Dictionary <NicoVideoQuality, DividedQualityNicoVideo>();
            QualityDividedVideos = new ReadOnlyObservableCollection <DividedQualityNicoVideo>(_QualityDividedVideos);
            CommentClient        = new CommentClient(HohoemaApp, RawVideoId);
        }
示例#5
0
        public VideoDownloadManager(HohoemaApp hohoemaApp, NiconicoMediaManager mediaManager)
        {
            HohoemaApp   = hohoemaApp;
            MediaManager = mediaManager;

            _CacheDownloadPendingVideos = new ObservableCollection <NicoVideoCacheRequest>();
            CacheDownloadPendingVideos  = new ReadOnlyObservableCollection <NicoVideoCacheRequest>(_CacheDownloadPendingVideos);

            HohoemaApp.OnSignin += HohoemaApp_OnSignin;

            // ダウンロード完了をバックグラウンドで処理
            CoreApplication.BackgroundActivated += CoreApplication_BackgroundActivated;
        }
示例#6
0
        /// <summary>
        /// キャッシュダウンロードのタスクから
        /// ダウンロードの情報を復元します
        /// </summary>
        /// <returns></returns>
        private async Task RestoreBackgroundDownloadTask()
        {
            // TODO: ユーザーのログイン情報を更新してダウンロードを再開する必要がある?
            // ユーザー情報の有効期限が切れていた場合には最初からダウンロードし直す必要があるかもしれません

            var tasks = await BackgroundDownloader.GetCurrentDownloadsAsync();

            foreach (var task in tasks)
            {
                NicoVideoCacheProgress info = null;
                try
                {
                    var _info = NiconicoMediaManager.CacheRequestInfoFromFileName(task.ResultFile);
                    info = new NicoVideoCacheProgress()
                    {
                        RawVideoId        = _info.RawVideoId,
                        Quality           = _info.Quality,
                        DownloadOperation = task
                    };

                    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);

                        // ダウンロード再開に失敗したらキャッシュリクエストに積み直します
                        // 失敗の通知はここではなくバックグラウンドタスクの 後処理 として渡されるかもしれません
                        await AddCacheRequest(info.RawVideoId, info.Quality, forceUpdate : true);
                    }
                }
            }
        }
示例#7
0
        public static async Task <HohoemaApp> Create(IEventAggregator ea)
        {
            HohoemaApp.UIDispatcher = Window.Current.CoreWindow.Dispatcher;

            var app = new HohoemaApp(ea);

            app.MediaManager = await NiconicoMediaManager.Create(app);

            await app.LoadUserSettings();

            await app.FeedManager.Initialize();

            var folder         = ApplicationData.Current.LocalFolder;
            var playlistFolder = await folder.CreateFolderAsync(PlaylistSaveFolderName, CreationCollisionOption.OpenIfExists);

            app.Playlist = new HohoemaPlaylist(MediaPlayer, app.UserSettings.PlaylistSettings, playlistFolder);

            await app.Playlist.Load();

            app.RagistrationBackgroundUpdateHandle();

            return(app);
        }
示例#8
0
        // ダウンロード完了
        private async Task OnDownloadCompleted(Task <DownloadOperation> prevTask)
        {
            if (prevTask.IsFaulted)
            {
                return;
            }

            Debug.WriteLine("キャッシュ完了");


            if (prevTask.Result != null)
            {
                var op   = prevTask.Result;
                var info = NiconicoMediaManager.CacheRequestInfoFromFileName(op.ResultFile);
                await RemoveDownloadOperation(info);

                if (op.Progress.Status == BackgroundTransferStatus.Completed)
                {
                    if (op.Progress.TotalBytesToReceive == op.Progress.BytesReceived)
                    {
                        Debug.WriteLine("キャッシュ済み: " + op.ResultFile.Name);
                        DownloadCompleted?.Invoke(this, info, op.ResultFile.Path);
                    }
                    else
                    {
                        Debug.WriteLine("キャッシュキャンセル: " + op.ResultFile.Name);
                        DownloadCanceled?.Invoke(this, info);
                    }
                    using (var pendingVideoLockReleaser = await _CacheDownloadPendingVideosLock.LockAsync())
                    {
                        _CacheDownloadPendingVideos.Remove(info);
                    }
                }
                else
                {
                    Debug.WriteLine($"キャッシュ失敗: {op.ResultFile.Name} (再ダウンロードします)");
                    DownloadCanceled?.Invoke(this, info);

                    await AddCacheRequest(info.RawVideoId, info.Quality, forceUpdate : true);
                }

                try
                {
                    if (op.TransferGroup != null &&
                        _BackgroundTransferCompletionInfoMap.ContainsKey(op.TransferGroup.Name)
                        )
                    {
                        var btcInfo = _BackgroundTransferCompletionInfoMap[op.TransferGroup.Name];
                        btcInfo.TaskRegistration.Unregister(cancelTask: false);

                        _BackgroundTransferCompletionInfoMap.Remove(op.TransferGroup.Name);
                    }
                }
                catch
                {
                    Debug.WriteLine("failed unregister background download completion task.");
                }
            }



            await TryNextCacheRequestedVideoDownload();
        }
示例#9
0
 public DmcQualityNicoVideo(NicoVideoQuality quality, NicoVideo nicoVideo, NiconicoMediaManager context)
     : base(quality, nicoVideo, context)
 {
 }
示例#10
0
 public OriginalQualityNicoVideo(NicoVideo nicoVideo, NiconicoMediaManager context)
     : base(NicoVideoQuality.Original, nicoVideo, context)
 {
 }
示例#11
0
 public LowQualityNicoVideo(NicoVideo nicoVideo, NiconicoMediaManager context)
     : base(NicoVideoQuality.Low, nicoVideo, context)
 {
 }