public static void SaveDownloadInfo(string id, MultiSourceDASHDownloadInfo info) { using var s = new FileStream(Path.Combine(Config.DataDir, id + ".info"), FileMode.Create); using var w = new BinaryWriter(s); WriteStringSafe(info.Url, w); WriteStringSafe(info.File, w); WriteStringSafe(info.AudioFormat, w); WriteStringSafe(info.VideoFormat, w); WriteStringSafe(info.AudioMimeType, w); WriteStringSafe(info.VideoMimeType, w); w.Write(info.Duration); StreamHelper.WriteStateHeaders(info.Headers, w); StreamHelper.WriteStateCookies(info.Cookies, w); var c1 = info.AudioSegments == null ? 0 : info.AudioSegments.Count; if (c1 > 0) { foreach (var audioSegment in info.AudioSegments !) { w.Write(audioSegment.ToString()); } } var c2 = info.VideoSegments == null ? 0 : info.VideoSegments.Count; if (c1 > 0) { foreach (var videoSegment in info.VideoSegments !) { w.Write(videoSegment.ToString()); } } }
public static MultiSourceDASHDownloadInfo?LoadMultiSourceDASHDownloadInfo(string id) { try { using var s = new FileStream(Path.Combine(Config.DataDir, id + ".info"), FileMode.Open); using var r = new BinaryReader(s); var info = new MultiSourceDASHDownloadInfo { Url = StreamHelper.ReadString(r), File = StreamHelper.ReadString(r), AudioFormat = StreamHelper.ReadString(r), VideoFormat = StreamHelper.ReadString(r), AudioMimeType = StreamHelper.ReadString(r), VideoMimeType = StreamHelper.ReadString(r), Duration = r.ReadInt64() }; StreamHelper.ReadStateHeaders(r, out Dictionary <string, List <string> > headers); info.Headers = headers; StreamHelper.ReadStateCookies(r, out Dictionary <string, string> cookies); info.Cookies = cookies; var c1 = r.ReadInt32(); if (c1 > 0) { info.AudioSegments = new List <Uri>(c1); for (int c = 0; c < c1; c++) { info.AudioSegments.Add(new Uri(r.ReadString())); } } var c2 = r.ReadInt32(); if (c2 > 0) { info.VideoSegments = new List <Uri>(c2); for (int c = 0; c < c2; c++) { info.VideoSegments.Add(new Uri(r.ReadString())); } } return(info); } catch (Exception ex) { Log.Debug(ex, ex.Message); } return(null); }