protected override void RestoreState() { var state = DownloadStateIO.LoadMultiSourceHLSDownloadState(Id !); this._state = state; try { Log.Debug("Restoring chunks from: " + Path.Combine(state.TempDirectory, "chunks.db")); if (!TransactedIO.ReadStream("chunks.db", state.TempDirectory, s => { _chunks = ChunkStateFromBytes(s); })) { throw new FileNotFoundException(Path.Combine(state.TempDirectory, "chunks.db")); } var hlsDir = state.TempDirectory; var streamMap = _chunks.Select(c => new { c.Id, TempFilePath = Path.Combine(hlsDir, (c.StreamIndex == 0 ? "1_" : "2_") + c.Id + FileHelper.GetFileName(c.Uri)) }).ToDictionary(e => e.Id, e => e.TempFilePath); _chunkStreamMap = new SimpleStreamMap { StreamMap = streamMap }; var count = 0; totalDownloadedBytes = 0; _chunks.ForEach(c => { if (c.ChunkState == ChunkState.Finished) { count++; } if (c.Downloaded > 0) { totalDownloadedBytes += c.Downloaded; } }); ticksAtDownloadStartOrResume = Helpers.TickCount(); this.lastProgress = (count * 100) / _chunks.Count; Log.Debug("Already downloaded: " + count + " Total: " + _chunks.Count); } catch { // ignored Log.Debug("Chunk restore failed"); } }
public override void RestoreState() { state = DownloadStateIO.LoadSingleSourceHTTPDownloaderState(Id !); //if (!TransactedIO.ReadStream(Id + ".state", Config.DataDir, s => //{ // state = DownloadStateStore.SingleSourceHTTPDownloaderStateFromBytes(s); //})) //{ // throw new FileNotFoundException(Path.Combine(Config.DataDir, Id + ".state")); //} //var bytes = TransactedIO.ReadBytes(Id + ".state", Config.DataDir); //if (bytes == null) //{ // throw new FileNotFoundException(Path.Combine(Config.DataDir, Id + ".state")); //} //state = DownloadStateStore.SingleSourceHTTPDownloaderStateFromBytes(bytes); try { //var chunkBytes = TransactedIO.ReadBytes("chunks.db", state.TempDir); //if (chunkBytes == null) //{ // throw new FileNotFoundException(Path.Combine(state.TempDir, "chunks.json")); //} //pieces = ChunkStateFromBytes(chunkBytes); if (!TransactedIO.ReadStream("chunks.db", state !.TempDir !, s => { pieces = ChunkStateFromBytes(s); })) { throw new FileNotFoundException(Path.Combine(state.TempDir, "chunks.db")); } Log.Debug("Total size: " + state.FileSize); //foreach (var item in pieces.Keys) //{ // Log.Debug("Chunk id: " + item + " offset: " + pieces[item].Offset + " downloaded: " + // pieces[item].Downloaded + " length: " + pieces[item].Length + " state: " + pieces[item].State); //} } catch { // ignored Console.WriteLine("Chunk restore failed"); } TicksAndSizeAtResume(); }
public override void RestoreState() { state = DownloadStateIO.LoadDualSourceHTTPDownloaderState(Id !); try { if (!TransactedIO.ReadStream("chunks.db", state !.TempDir !, s => { pieces = ChunkStateFromBytes(s); })) { throw new FileNotFoundException(Path.Combine(state.TempDir, "chunks.db")); } } catch { // ignored Log.Debug("Chunk restore failed"); } TicksAndSizeAtResume(); }
protected override void RestoreState() { var state = DownloadStateIO.LoadMultiSourceDASHDownloadState(Id !); this._state = state; //var bytes = TransactedIO.ReadBytes(Id + ".state", Config.DataDir); //if (bytes == null) //{ // throw new FileNotFoundException(Path.Combine(Config.DataDir, Id + ".state")); //} //var state = DownloadStateStore.MultiSourceDASHDownloadStateFromBytes(bytes); //this._state = state; //var text = TransactedIO.Read(Id + ".state", Config.DataDir); //if (text == null) //{ // throw new FileNotFoundException(Path.Combine(Config.DataDir, Id + ".state")); //} ////since all information is available in constructor we assume chunk restore can not fail //var state = JsonConvert.DeserializeObject<MultiSourceDASHDownloadState>( // text); //this._state = state; try { Log.Debug("Restoring chunks from: " + Path.Combine(_state.TempDirectory, "chunks.db")); if (!TransactedIO.ReadStream("chunks.db", state.TempDirectory, s => { _chunks = ChunkStateFromBytes(s);// pieces = ChunkStateFromBytes(s); })) { throw new FileNotFoundException(Path.Combine(state.TempDirectory, "chunks.db")); } //var bytes2 = TransactedIO.ReadBytes("chunks.db", _state.TempDirectory); //if (bytes2 == null) //{ // throw new FileNotFoundException(Path.Combine(_state.TempDirectory, "chunks.json")); //} //_chunks = ChunkStateFromBytes(bytes2); var dashDir = _state.TempDirectory; var streamMap = _chunks.Select(c => new { c.Id, TempFilePath = Path.Combine(dashDir, (c.StreamIndex == 0 ? "1_" : "2_") + c.Id + FileHelper.GetFileName(c.Uri)) }).ToDictionary(e => e.Id, e => e.TempFilePath); _chunkStreamMap = new SimpleStreamMap { StreamMap = streamMap }; } catch (Exception ex) { Log.Debug(ex, "Error loading chunks"); if (state.Demuxed) { CreateChunks2(state, _chunks, _chunkStreamMap); } else { CreateChunks1(state, _chunks, _chunkStreamMap); } } var count = 0; totalDownloadedBytes = 0; _chunks.ForEach(c => { if (c.ChunkState == ChunkState.Finished) { count++; } if (c.Downloaded > 0) { totalDownloadedBytes += c.Downloaded; } }); this.lastProgress = (count * 100) / _chunks.Count; ticksAtDownloadStartOrResume = Helpers.TickCount(); Log.Debug("Already downloaded: " + count); }