public void AddAudio(string language) { if (language.IsNotEmpty()) { Audio.Add(language); } }
void LoadAudio(string zipPath, string[] audios) {//Загрузка из архивов аудиофайлов foreach (var audio in audios) { if (!Audio.ContainsKey(audio)) { var buff = ReadFromZip(zipPath, audio); buff.Position = 0; Audio.Add(audio, buff); } else { continue; } } }
public Get(string filePath) { var file = Path.Combine(Path.GetTempPath(), $"nemu_{new Random().Next(0, 999999999):D9}.xml"); var ec = new Run().Execute($"\"{FFmpeg.Probe}\" -hide_banner -print_format xml -show_format -show_streams \"{filePath}\" > \"{file}\"", Path.GetTempPath()); try { var xml = XDocument.Load(file); var format = from a in xml.Descendants("format") select new { fmtcode = a.Attribute("format_name").Value, fmtlong = a.Attribute("format_long_name").Value, size = a.Attribute("size").Value, bitrate = a.Attribute("bit_rate")?.Value, duration = a.Attribute("duration")?.Value, }; var video = from a in xml.Descendants("stream") where string.Equals("video", (string)a.Attribute("codec_type"), IC) select new { id = (int)a.Attribute("index"), lang = a.Elements("tag").SingleOrDefault(x => string.Equals(x.Attribute("key").Value, "language", IC))?.Attribute("value")?.Value, codec = a.Attribute("codec_name").Value, pixfmt = a.Attribute("pix_fmt")?.Value, bpc = a.Attribute("bits_per_raw_sample")?.Value, width = a.Attribute("width").Value, height = a.Attribute("height").Value, fps = a.Attribute("r_frame_rate")?.Value, afps = a.Attribute("avg_frame_rate")?.Value, framecount = a.Attribute("nb_frames")?.Value, duration = a.Attribute("duration")?.Value, }; var audio = from a in xml.Descendants("stream") where string.Equals("audio", (string)a.Attribute("codec_type"), IC) select new { id = (int)a.Attribute("index"), lang = a.Elements("tag").SingleOrDefault(x => string.Equals(x.Attribute("key").Value, "language", IC))?.Attribute("value")?.Value, codec = a.Attribute("codec_name").Value, sample = a.Attribute("sample_rate").Value, bitdepth = a.Attribute("sample_fmt").Value, channel = a.Attribute("channels").Value, duration = a.Attribute("duration")?.Value, }; var subtitle = from a in xml.Descendants("stream") where string.Equals("subtitle", (string)a.Attribute("codec_type"), IC) select new { id = (int)a.Attribute("index"), lang = a.Elements("tag").SingleOrDefault(x => string.Equals(x.Attribute("key").Value, "language", IC))?.Attribute("value")?.Value, codec = a.Attribute("codec_name").Value, }; var attachment = from a in xml.Descendants("stream") where string.Equals("attachment", (string)a.Attribute("codec_type"), IC) select new { id = (int)a.Attribute("index"), filename = a.Elements("tag").SingleOrDefault(x => string.Equals(x.Attribute("key").Value, "filename", IC))?.Attribute("value")?.Value, mimetype = a.Elements("tag").SingleOrDefault(x => string.Equals(x.Attribute("key").Value, "mimetype", IC))?.Attribute("value")?.Value, }; FilePath = filePath; foreach (var item in format) { ulong filesize = 0; ulong bitrate = 0; float time = 0; ulong.TryParse(item.size, out filesize); ulong.TryParse(item.bitrate, out bitrate); float.TryParse(item.duration, out time); FormatName = item.fmtcode; FormatNameFull = item.fmtlong; FileSize = filesize; BitRate = bitrate; Duration = time; break; // single only } foreach (var item in video) { int bpc = 8; int pix = 420; int w = 0; int h = 0; int fc = 0; int.TryParse(item.bpc, out bpc); int.TryParse(item.width, out w); int.TryParse(item.height, out h); int.TryParse(item.framecount, out fc); float num = 0; float den = 0; float.TryParse(item.fps.Split('/')[0], out num); float.TryParse(item.fps.Split('/')[1], out den); float fps = num / den; float.TryParse(item.afps.Split('/')[0], out num); float.TryParse(item.afps.Split('/')[1], out den); float afps = num / den; float du = Duration; if (!string.IsNullOrEmpty(item.duration)) { if (float.TryParse(item.duration, out du)) { du = Duration; } } if (string.IsNullOrEmpty(item.pixfmt)) { var mpix = Regex.Match(item.pixfmt, @"yuv(\d+)"); if (mpix.Success) { int.TryParse(mpix.Groups[1].Value, out pix); } else { pix = 420; } } if (bpc == 0) { var mbpc = Regex.Match(item.pixfmt, @"yuv\d+p(\d+)"); if (mbpc.Success) { int.TryParse(mbpc.Groups[1].Value, out bpc); } else { bpc = 8; } } Video.Add(new StreamVideo { Id = item.id, Language = string.IsNullOrEmpty(item.lang) ? "und" : item.lang, Codec = item.codec, Chroma = pix, BitDepth = bpc, Width = w, Height = h, FrameRateConstant = fps == afps, FrameRate = fps, FrameRateAvg = afps, FrameCount = fc, Duration = du, }); } foreach (var item in audio) { int sample = 44100; int bitdepth = 16; int channel = 2; int.TryParse(item.sample, out sample); int.TryParse(item.bitdepth, out bitdepth); int.TryParse(item.channel, out channel); if (bitdepth == 0) { bitdepth = 16; } if (bitdepth >= 32) { bitdepth = 24; } float du = 0; float.TryParse(item.duration, out du); Audio.Add(new StreamAudio { Id = item.id, Language = string.IsNullOrEmpty(item.lang) ? "und" : item.lang, Codec = item.codec, SampleRate = sample, BitDepth = bitdepth, Channel = channel, Duration = du, }); } foreach (var item in subtitle) { Subtitle.Add(new StreamSubtitle { Id = item.id, Language = string.IsNullOrEmpty(item.lang) ? "und" : item.lang, Codec = item.codec, }); } foreach (var item in attachment) { Attachment.Add(new StreamAttachment { Id = item.id, FileName = item.filename, MimeType = item.mimetype }); } // remove xml File.Delete(file); // error display if (ec > 0) { Console.ForegroundColor = ConsoleColor.Red; Console.Write(Run.errorString); Console.ResetColor(); } } catch (Exception) { throw; } }
/// <summary> /// Contains meta-data about a page. /// /// Protocols supported: /// The Open Graph protocol: http://ogp.me/ /// </summary> /// <param name="Doc">HTML Document</param> public PageMetaData(HtmlDocument Doc) { List <ImageInformation> Images = null; List <AudioInformation> Audio = null; List <VideoInformation> Video = null; List <string> LocaleAlternate = null; ImageInformation LastImage = null; AudioInformation LastAudio = null; VideoInformation LastVideo = null; string Name; string Value; if (Doc.Meta != null) { foreach (Meta Meta in Doc.Meta) { if (!Meta.HasAttributes) { continue; } Name = Value = null; foreach (HtmlAttribute Attr in Meta.Attributes) { switch (Attr.Name) { case "property": Name = Attr.Value; break; case "content": Value = Attr.Value; break; } } if (string.IsNullOrEmpty(Name) || string.IsNullOrEmpty(Value)) { continue; } switch (Name) { case "og:title": this.title = Value; break; case "twitter:title": if (string.IsNullOrEmpty(this.title)) { this.title = Value; } break; case "og:type": this.type = Value; break; case "twitter:card": if (string.IsNullOrEmpty(this.type)) { this.type = Value; } break; case "og:url": this.url = Value; break; case "og:image": case "og:image:url": case "twitter:image": if (Images != null) { LastImage = null; foreach (ImageInformation Image in Images) { if (Image.Url == Value) { LastImage = Image; break; } } if (LastImage != null) { break; } } LastImage = new ImageInformation() { Url = Value }; if (Images == null) { Images = new List <ImageInformation>(); } Images.Add(LastImage); break; case "og:image:secure_url": if (LastImage != null) { LastImage.SecureUrl = Value; } break; case "og:image:type": if (LastImage != null) { LastImage.ContentType = Value; } break; case "og:image:width": if (LastImage != null && int.TryParse(Value, out int i)) { LastImage.Width = i; } break; case "og:image:height": if (LastImage != null && int.TryParse(Value, out i)) { LastImage.Height = i; } break; case "og:image:alt": case "twitter:image:alt": if (LastImage != null) { LastImage.Description = Value; } break; case "og:audio": LastAudio = new AudioInformation() { Url = Value }; if (Audio == null) { Audio = new List <AudioInformation>(); } Audio.Add(LastAudio); break; case "og:audio:secure_url": if (LastAudio != null) { LastAudio.SecureUrl = Value; } break; case "og:audio:type": if (LastAudio != null) { LastAudio.ContentType = Value; } break; case "og:description": this.description = Value; break; case "twitter:description": case "description": if (string.IsNullOrEmpty(this.description)) { this.description = Value; } break; case "og:determiner": this.determiner = Value; break; case "og:locale": this.locale = Value; break; case "og:locale:alternate": if (LocaleAlternate == null) { LocaleAlternate = new List <string>(); } LocaleAlternate.Add(Value); break; case "og:site_name": this.siteName = Value; break; case "og:video": LastVideo = new VideoInformation() { Url = Value }; if (Video == null) { Video = new List <VideoInformation>(); } Video.Add(LastVideo); break; case "og:video:secure_url": if (LastVideo != null) { LastVideo.SecureUrl = Value; } break; case "og:video:type": if (LastVideo != null) { LastVideo.ContentType = Value; } break; case "og:video:width": if (LastVideo != null && int.TryParse(Value, out i)) { LastVideo.Width = i; } break; case "og:video:height": if (LastVideo != null && int.TryParse(Value, out i)) { LastVideo.Height = i; } break; } } } if (string.IsNullOrEmpty(this.title) && Doc.Title != null) { this.title = Doc.Title.InnerHtml.Trim(); } this.images = Images?.ToArray(); this.audio = Audio?.ToArray(); this.video = Video?.ToArray(); this.localeAlternate = LocaleAlternate?.ToArray(); }
public MediaInfo(string path) { dynamic json = JsonConvert.DeserializeObject(new ReadFile().Media(path)); // General info FilePath = (string)json.format.filename; FileSize = ulong.TryParse((string)json.format.size, out ulong fs) ? fs : 0; BitRate = ulong.TryParse((string)json.format.bit_rate, out ulong br) ? br : 0; Duration = float.TryParse((string)json.format.duration, out float d) ? d : 0; FormatName = (string)json.format.format_name; FormatNameFull = (string)json.format.format_long_name; // Capture stream type foreach (var stream in json.streams) { string type = stream.codec_type; if (string.Equals(type, "video", IgnoreCase)) { int id = 0; try { id = int.Parse((string)stream.index); } catch (Exception ex) { Console.WriteLine(ex.Message); } string lang = "und"; try { lang = stream.tags.language; } catch (Exception ex) { Console.WriteLine(ex.Message); } if (string.IsNullOrEmpty(lang)) { lang = "und"; } string codec = "unknown"; try { codec = stream.codec_name; } catch (Exception ex) { Console.WriteLine(ex.Message); } int width = 0; try { width = int.Parse((string)stream.width); } catch (Exception ex) { Console.WriteLine(ex.Message); } int height = 0; try { height = int.Parse((string)stream.height); } catch (Exception ex) { Console.WriteLine(ex.Message); } string r = "0/0"; try { r = stream.r_frame_rate; } catch (Exception ex) { Console.WriteLine(ex.Message); } float.TryParse(r.Split('/')[0], out float rn); float.TryParse(r.Split('/')[1], out float rd); float rfps = rn / rd; string a = "0/0"; try { a = stream.avg_frame_rate; } catch (Exception ex) { Console.WriteLine(ex.Message); } float.TryParse(a.Split('/')[0], out float an); float.TryParse(a.Split('/')[1], out float ad); float afps = an / ad; int pix = 420; try { if (!string.IsNullOrEmpty((string)stream.pix_fmt)) { var mpix = Regex.Match((string)stream.pix_fmt, @"yuv(\d+)"); if (mpix.Success) { int.TryParse(mpix.Groups[1].Value, out pix); } else { pix = 420; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } int bpc = 8; try { if (int.TryParse((string)stream.bits_per_raw_sample, out int x)) { bpc = x; } else { var mbpc = Regex.Match((string)stream.pix_fmt, @"yuv\d+p(\d+)"); if (mbpc.Success) { int.TryParse(mbpc.Groups[1].Value, out bpc); } else { bpc = 8; } } } catch (Exception ex) { Console.WriteLine(ex.Message); } Video.Add(new StreamVideo { Id = id, Language = lang, Codec = codec, Chroma = pix, BitDepth = bpc, Width = width, Height = height, FrameRateConstant = rfps == afps, FrameRate = rfps, FrameRateAvg = afps, FrameCount = (int)(Duration * afps), Duration = Duration, }); } if (string.Equals(type, "audio", IgnoreCase)) { int id = 1; try { id = stream.index; } catch (Exception ex) { Console.WriteLine(ex.Message); } string lang = "und"; try { lang = stream.tags.language; } catch (Exception ex) { Console.WriteLine(ex.Message); } if (string.IsNullOrEmpty(lang)) { lang = "und"; } string codec = "unknown"; try { codec = stream.codec_name; } catch (Exception ex) { Console.WriteLine(ex.Message); } int sample = 44100; try { sample = stream.sample_rate; } catch (Exception ex) { Console.WriteLine(ex.Message); } int bitdepth = 16; try { bitdepth = stream.sample_fmt; } catch (Exception ex) { Console.WriteLine(ex.Message); } int channel = 2; try { channel = stream.channels; } catch (Exception ex) { Console.WriteLine(ex.Message); } if (bitdepth == 0) { bitdepth = 16; } else if (bitdepth >= 32) { bitdepth = 24; } Audio.Add(new StreamAudio { Id = id, Language = lang, Codec = codec, SampleRate = sample, BitDepth = bitdepth, Channel = channel, Duration = Duration, }); } if (string.Equals(type, "subtitle", IgnoreCase)) { int id = 2; try { id = stream.index; } catch (Exception ex) { Console.WriteLine(ex.Message); } string lang = "und"; try { lang = stream.tags.language; } catch (Exception ex) { Console.WriteLine(ex.Message); } if (string.IsNullOrEmpty(lang)) { lang = "und"; } string codec = "unknown"; try { codec = stream.codec_name; } catch (Exception ex) { Console.WriteLine(ex.Message); } Subtitle.Add(new StreamSubtitle { Id = id, Language = lang, Codec = FormatId.Get(codec), }); } if (string.Equals(type, "attachment", IgnoreCase)) { int id = 3; try { id = stream.index; } catch (Exception ex) { Console.WriteLine(ex.Message); } string fname = "unknown"; try { fname = stream.tags.filename; } catch (Exception ex) { Console.WriteLine(ex.Message); } string mtype = "application/octet-stream"; try { mtype = stream.tags.mimetype; } catch (Exception ex) { Console.WriteLine(ex.Message); } Attachment.Add(new StreamAttachment { Id = id, FileName = fname, MimeType = mtype }); } } }
public void UpdateAsync() { SendFunction("", true, x => { try { var e = (DownloadStringCompletedEventArgs)x; if (e.Error != null) { OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = false }); return; } if (e.UserState == null) { return; } IsInitializing = true; _logger.Debug("Updating vMix state."); var _temp = Create(e.Result); if (_temp == null) { _logger.Debug("vMix is offline"); _logger.Debug("Firing \"updated\" event."); IsInitializing = false; OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = false }); } _logger.Debug("Calculating difference."); Diff(this, _temp); _logger.Debug("Updating inputs."); if (Inputs == null) { Inputs = new List <Input>(); } if (Overlays == null) { Overlays = new List <Overlay>(); } if (Audio == null) { Audio = new List <Master>(); } if (Transitions == null) { Transitions = new List <Transition>(); } Inputs.Clear(); foreach (var item in _temp.Inputs) { Inputs.Add(item); } Overlays.Clear(); foreach (var item in _temp.Overlays) { Overlays.Add(item); } Audio.Clear(); foreach (var item in _temp.Audio) { Audio.Add(item); } Transitions.Clear(); foreach (var item in _temp.Transitions) { Transitions.Add(item); } Mixes.Clear(); foreach (var item in _temp.Mixes) { Mixes.Add(item); } if (_currentStateText != _temp._currentStateText) { _currentStateText = _temp._currentStateText; } _logger.Debug("Firing \"updated\" event."); IsInitializing = false; OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = true, OldInputs = null, NewInputs = null }); return; } catch (Exception e) { IsInitializing = false; _logger.Error(e, "Exception at UpdateAsync"); } }); }
public bool Update() { try { IsInitializing = true; _logger.Debug("Updating vMix state."); var _temp = Create(); if (_temp == null) { _logger.Debug("vMix is offline"); _logger.Debug("Firing \"updated\" event."); OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = false }); IsInitializing = false; return(false); } _logger.Debug("Calculating difference."); Diff(this, _temp); _logger.Debug("Updating inputs."); Inputs.Clear(); foreach (var item in _temp.Inputs) { Inputs.Add(item); } Overlays.Clear(); foreach (var item in _temp.Overlays) { Overlays.Add(item); } Audio.Clear(); foreach (var item in _temp.Audio) { Audio.Add(item); } Transitions.Clear(); foreach (var item in _temp.Transitions) { Transitions.Add(item); } Mixes.Clear(); foreach (var item in _temp.Mixes) { Mixes.Add(item); } //UpdateChangedInputs(_currentStateText, _temp._currentStateText); if (_currentStateText != _temp._currentStateText) { _currentStateText = _temp._currentStateText; } _logger.Debug("Firing \"updated\" event."); OnStateSynced?.Invoke(this, new StateSyncedEventArgs() { Successfully = true, OldInputs = null, NewInputs = null }); IsInitializing = false; return(true); } catch (Exception e) { IsInitializing = false; _logger.Error(e, "Exception at Update"); return(false); } }
public GetInfo(string FileMedia) { dynamic json = JsonConvert.DeserializeObject(new Run(FileMedia).Output); // General info FilePath = json.format.filename; FileSize = json.format.size; BitRate = json.format.bit_rate; Duration = json.format.duration; FormatName = json.format.format_name; FormatNameFull = json.format.format_long_name; // Capture stream type foreach (var stream in json.streams) { string type = stream.codec_type; if (string.Equals(type, "video", IgnoreCase)) { string r = stream.r_frame_rate; float.TryParse(r.Split('/')[0], out float rn); float.TryParse(r.Split('/')[1], out float rd); float rfps = rn / rd; string a = stream.avg_frame_rate; float.TryParse(a.Split('/')[0], out float an); float.TryParse(a.Split('/')[1], out float ad); float afps = an / ad; int pix = 420; if (!string.IsNullOrEmpty((string)stream.pix_fmt)) { var mpix = Regex.Match((string)stream.pix_fmt, @"yuv(\d+)"); if (mpix.Success) { int.TryParse(mpix.Groups[1].Value, out pix); } else { pix = 420; } } int bpc = stream.bits_per_raw_sample; if (bpc == 0) { var mbpc = Regex.Match((string)stream.pix_fmt, @"yuv\d+p(\d+)"); if (mbpc.Success) { int.TryParse(mbpc.Groups[1].Value, out bpc); } else { bpc = 8; } } string lang = stream.tags.language; if (string.IsNullOrEmpty(lang)) { lang = "und"; } Video.Add(new StreamVideo { Id = stream.index, Language = lang, Codec = stream.codec_name, Chroma = pix, BitDepth = stream.bits_per_raw_sample, Width = stream.width, Height = stream.height, FrameRateConstant = rfps == afps, FrameRate = rfps, FrameRateAvg = afps, FrameCount = (int)(Duration * afps), Duration = Duration, }); } if (string.Equals(type, "audio", IgnoreCase)) { int.TryParse((string)stream.sample_rate, out int sample); int.TryParse((string)stream.sample_fmt, out int bitdepth); int.TryParse((string)stream.channels, out int channel); if (bitdepth == 0) { bitdepth = 16; } else if (bitdepth >= 32) { bitdepth = 24; } string lang = stream.tags.language; if (string.IsNullOrEmpty(lang)) { lang = "und"; } Audio.Add(new StreamAudio { Id = stream.index, Language = lang, Codec = stream.codec_name, SampleRate = sample, BitDepth = bitdepth, Channel = channel, Duration = Duration, }); } if (string.Equals(type, "subtitle", IgnoreCase)) { string lang = stream.tags.language; if (string.IsNullOrEmpty(lang)) { lang = "und"; } Subtitle.Add(new StreamSubtitle { Id = stream.index, Language = lang, Codec = stream.codec_name, }); } if (string.Equals(type, "attachment", IgnoreCase)) { Attachment.Add(new StreamAttachment { Id = stream.index, FileName = stream.tags.filename, MimeType = stream.tags.mimetype }); } } }