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); }
public DividedQualityNicoVideo(NicoVideoQuality quality, NicoVideo nicoVideo, NiconicoMediaManager mediaManager) { Quality = quality; NicoVideo = nicoVideo; HohoemaApp = nicoVideo.HohoemaApp; NiconicoMediaManager = mediaManager; VideoDownloadManager = mediaManager.VideoDownloadManager; }
static internal Task <NiconicoMediaManager> Create(HohoemaApp app) { var man = new NiconicoMediaManager(app); // await man.RetrieveCacheCompletedVideos(); return(Task.FromResult(man)); }
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); }
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; }
/// <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); } } } }
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); }
// ダウンロード完了 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(); }
public DmcQualityNicoVideo(NicoVideoQuality quality, NicoVideo nicoVideo, NiconicoMediaManager context) : base(quality, nicoVideo, context) { }
public OriginalQualityNicoVideo(NicoVideo nicoVideo, NiconicoMediaManager context) : base(NicoVideoQuality.Original, nicoVideo, context) { }
public LowQualityNicoVideo(NicoVideo nicoVideo, NiconicoMediaManager context) : base(NicoVideoQuality.Low, nicoVideo, context) { }