public AudioConfigViewModel() { BitrateCollection = new ReadOnlyObservableCollection <AudioBitrate>(new ObservableCollection <AudioBitrate>(Enum .GetValues(typeof(AudioBitrate)).Cast <AudioBitrate>())); ChannelCollection = new ReadOnlyObservableCollection <AudioChannel>(new ObservableCollection <AudioChannel>(Enum .GetValues(typeof(AudioChannel)).Cast <AudioChannel>())); AudioEndPointCollection = new ReadOnlyObservableCollection <AudioEndPointViewModel>(new ObservableCollection <AudioEndPointViewModel>(AudioHelper.Instance.Devices.Select(s => new AudioEndPointViewModel() { Channels = s.Channels, Disabled = s.Disabled, DeviceId = s.DeviceId, DeviceName = s.DeviceName, JackColor = s.JackColor }))); SelectedAudioEndPoint = AudioEndPointCollection.FirstOrDefault(fd => fd.DeviceId == AudioHelper.Instance.Device.DeviceId /* && !AudioHelper.Instance.Device.Disabled*/); _selectedBitrateItem = AudioHelper.Instance.Bitrate; _selectedChannelItem = AudioHelper.Instance.Channel; GlobalEventAggregator.Instance.AddListener <PeakValueEventArgs>(PeakValueChangedListner); GlobalEventAggregator.Instance.AddListener <RecordingStateEventArgs>(RecordingStateListner); GlobalEventAggregator.Instance.AddListener <DeviceStateChangedEventArgs>(DeviceStateListner); }
/// <summary> /// Converts the file /// </summary> /// <param name="fileName">The path to the file which should become converted</param> /// <param name="newFileName">The name of the new file WITHOUT extension</param> /// <param name="bitrate">The audio bitrate</param> /// <param name="format"></param> public static async Task ConvertFile(string fileName, string newFileName, AudioBitrate bitrate, AudioFormat format) { var fileToConvert = new FileInfo(fileName); var p = new Process { StartInfo = { CreateNoWindow = true, FileName = HurricaneSettings.Paths.FFmpegPath, Arguments = GetParameter(fileName, newFileName, bitrate, format), UseShellExecute = false } }; p.Start(); await Task.Run(() => p.WaitForExit()); var newFile = new FileInfo(newFileName); if (!newFile.Exists || newFile.Length == 0) { if (newFile.Exists) newFile.Delete(); fileToConvert.MoveTo(newFileName); //If the convert failed, we just use the "old" file } fileToConvert.Delete(); }
/// <summary> /// Converts the file /// </summary> /// <param name="fileName">The path to the file which should become converted</param> /// <param name="newFileName">The name of the new file WITHOUT extension</param> /// <param name="bitrate">The audio bitrate</param> /// <param name="format"></param> public static async Task ConvertFile(string fileName, string newFileName, AudioBitrate bitrate, AudioFormat format) { var fileToConvert = new FileInfo(fileName); var p = new Process { StartInfo = { CreateNoWindow = true, FileName = HurricaneSettings.Paths.FFmpegPath, Arguments = GetParameter(fileName, newFileName,bitrate, format), UseShellExecute = false } }; p.Start(); await Task.Run(() => p.WaitForExit()); var newFile = new FileInfo(newFileName); if (!newFile.Exists || newFile.Length == 0) { if (newFile.Exists) { newFile.Delete(); } fileToConvert.MoveTo(newFileName); //If the convert failed, we just use the "old" file } fileToConvert.Delete(); }
public void DownloadAudioAsync(AudioInformation audioInformation, FileFormat format, AudioBitrate bitrate, string destinationFileName) { if (!audioInformation.IsAvailableInFormatAndBitrate(format, bitrate)) throw new QualityNotAvailableException(); audioInProgress = audioInformation; var downloadLink = audioInformation.GetDownloadURL(format, bitrate); webClient.DownloadFileAsync(new Uri(downloadLink), destinationFileName); }
public AudioDataEventArgs( int sampleRate, int bitsPerSample, int channels, int bytesRecorded, byte[] buffer, AudioChannel audioChannel, AudioBitrate audioBitrate) : this() { SampleRate = sampleRate; BitsPerSample = bitsPerSample; Channels = channels; BytesRecorded = bytesRecorded; Buffer = buffer; PreferedChannel = audioChannel; PreferedBitrate = audioBitrate; }
public AudioConfigViewModel() { BitrateCollection = new ReadOnlyObservableCollection <AudioBitrate>(new ObservableCollection <AudioBitrate>(Enum .GetValues(typeof(AudioBitrate)).Cast <AudioBitrate>())); ChannelCollection = new ReadOnlyObservableCollection <AudioChannel>(new ObservableCollection <AudioChannel>(Enum .GetValues(typeof(AudioChannel)).Cast <AudioChannel>())); AudioEndPointCollection = new ReadOnlyObservableCollection <AudioEndPoint>(new ObservableCollection <AudioEndPoint>(AudioHelper.Instance.Devices)); SelectedAudioEndPoint = AudioEndPointCollection.FirstOrDefault(fd => fd.DeviceId == AudioHelper.Instance.DeviceId); _selectedBitrateItem = AudioHelper.Instance.Bitrate; _selectedChannelItem = AudioHelper.Instance.Channel; GlobalEventAggregator.Instance.AddListener <PeakValueEventArgs>(PeakValueChangedListner); }
public void DownloadAudioAsync(AudioInformation audioInformation, FileFormat format, AudioBitrate bitrate, string destinationFileName) { if (!audioInformation.IsAvailableInFormatAndBitrate(format, bitrate)) { throw new QualityNotAvailableException(); } audioInProgress = audioInformation; var downloadLink = audioInformation.GetDownloadURL(format, bitrate); webClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "mEOmAPmEOmAP1881@"); webClient.DownloadFileAsync(new Uri(downloadLink), destinationFileName); }
public string GetDownloadURL(FileFormat format, AudioBitrate bitrate) { return(IsAvailableInFormatAndBitrate(format, bitrate) ? AvailableQualities[Tuple.Create(format, bitrate)] : null); }
public bool IsAvailableInFormatAndBitrate(FileFormat format, AudioBitrate bitrate) { return(AvailableQualities.Keys.Contains(Tuple.Create(format, bitrate))); }
public void DownloadAudioAsync(AudioInformation audioInformation, FileFormat format, AudioBitrate bitrate, string destinationFileName) { if (!audioInformation.IsAvailableInFormatAndBitrate(format, bitrate)) { throw new QualityNotAvailableException(); } audioInProgress = audioInformation; var downloadLink = audioInformation.GetDownloadURL(format, bitrate); webClient.DownloadFileAsync(new Uri(downloadLink), destinationFileName); }
private static string GetParameter(string inputFile, string outputFile, AudioBitrate bitrate, AudioFormat format) { return string.Format("-i \"{0}\" -c:a {1} -vn -b:a {2}k \"{3}\"", inputFile, GetAudioLibraryFromFormat(format), bitrate.ToString().Remove(0, 1), outputFile); }
private static string GetParameter(string inputFile, string outputFile, AudioBitrate bitrate, AudioFormat format) { return(string.Format("-i \"{0}\" -c:a {1} -vn -b:a {2}k \"{3}\"", inputFile, GetAudioLibraryFromFormat(format), bitrate.ToString().Remove(0, 1), outputFile)); }
//[End] private static async Task <AudioInformation> ParseVideoFromHTML(string html) { try { // Parse basic video information from the HTML string url = new Regex(URL_PATTERN).Match(html).Groups[1].Value; string title = new Regex(TITLE_PATTERN).Match(html).Groups[1].Value; string description = new Regex(DESCRIPTION_PATTERN).Match(html).Groups[1].Value; string thumbnailURL = new Regex(THUMBNAIL_PATTERN).Match(html).Groups[1].Value; // Make sure that the title and description don't contain any HTML-escaped characters like & title = WebUtility.HtmlDecode(title); description = WebUtility.HtmlDecode(description); if (url.Contains("&")) { url = url.Split('&')[0]; // If the URL contains more stuff in the query string, get rid of it } // Separate the JSON string, which is what we need for the download URLs and qualities string jsonString = html.Split(new[] { "ytplayer.config = " }, StringSplitOptions.None)[1]; jsonString = jsonString.Split(new [] { "};" }, StringSplitOptions.None)[0] + "}"; // Parse video information from the JSON dynamic json = new JavaScriptSerializer().Deserialize <object>(jsonString); string[] keywords = json["args"]["keywords"].Split(','); string[] adaptive_fmts = json["args"]["adaptive_fmts"].Split(new[] { "," }, StringSplitOptions.None); // Create a dictionary with different qualities, formats and URL's Dictionary <Tuple <FileFormat, AudioBitrate>, string> availableQualities = new Dictionary <Tuple <FileFormat, AudioBitrate>, string>(); foreach (string stream in adaptive_fmts) { if (!stream.Contains("url=")) { continue; } if (!stream.Contains("itag=")) { continue; } string formatString = Uri.UnescapeDataString(ParseFieldFromQueryString("type", stream)); if (!IsAudio(formatString)) { continue; } string videoURL = Uri.UnescapeDataString(ParseFieldFromQueryString("url", stream)); string itag = Uri.UnescapeDataString(ParseFieldFromQueryString("itag", stream)); AudioBitrate bitrate = ParseBitrate(itag); FileFormat format = ParseFormat(formatString); Tuple <FileFormat, AudioBitrate> qualityTuple = Tuple.Create(format, bitrate); if (!availableQualities.ContainsKey(qualityTuple)) { availableQualities.Add(qualityTuple, videoURL); } } // Download the thumbnail Image thumbnail; using (var http = new HttpClient()) { thumbnail = Image.FromStream(new MemoryStream(await http.GetByteArrayAsync(thumbnailURL))); } // Create the video instance AudioInformation audioInformation = new AudioInformation { URL = url, Title = title, Description = description, Keywords = keywords, Thumbnail = thumbnail, AvailableQualities = availableQualities }; foreach (Tuple <FileFormat, AudioBitrate> qualityTuple in availableQualities.Keys) { Console.WriteLine(qualityTuple.ToString()); } // And return it :) return(audioInformation); } catch (Exception ex) { Console.WriteLine(ex.ToString()); return(null); } }
private static string GetParameter(string inputFile, string outputFile, AudioBitrate bitrate, AudioFormat format) { return ($"-i \"{inputFile}\" -c:a {GetAudioLibraryFromFormat(format)} -vn -b:a {bitrate.ToString().Remove(0, 1)}k \"{outputFile}\""); }
public void WriteLine() { VideoBitrate.WriteLine("Video"); AudioBitrate.WriteLine("Audio"); CombinedBitrate.WriteLine("Combined"); }