private static void ProcessAudioFiles(MainApp app, string folder, bool includeSubFolders, bool useParallelProcessing) { var extractor = new AudioExtractor(); var result = app.Execute(extractor, folder, includeSubFolders, useParallelProcessing); if (result.count > 0) { Console.WriteLine(); Console.WriteLine($"{result.count} audio files. Output = {result.outputPath}"); Console.WriteLine(); } }
public ActionResult Audio(string path) { if (!path.IsNullOrEmpty()) { string physicalPath; string category; Global.GetPhysicalPathAndCategory(path, out physicalPath, out category); if (AudioExtractor.Extract(ref path, physicalPath)) { return(Redirect(Request.GetMediaUrl(path))); } } return(HttpNotFound()); }
public ActionResult Playlist(string path) { if (!path.IsNullOrEmpty()) { string physicalPath; string category; Global.GetPhysicalPathAndCategory(path, out physicalPath, out category); string parent = Path.GetDirectoryName(physicalPath); return(Json(from m in GetFiles(new DirectoryInfo(parent), category) let canExtract = AudioExtractor.CanExtract(m.PathForUrl) where canExtract || (Request.GetPlayer(m.PathForUrl) == Player.Html5Audio) select new { Name = Path.GetFileNameWithoutExtension(m.PathForUrl), Url = canExtract ? Url.Action(Global.ActionName.Audio, m.PathForUrl.GetRouteValues()) : Request.GetMediaUrl(m.PathForUrl) })); } return(HttpNotFound()); }
public MMetadataResponse CreateExtractor(int mediaType, string path) { var result = new MMetadataResponse(); if (string.IsNullOrEmpty(path)) { result.IsSuccess = false; result.Message = "檔案路徑不得為空"; return(result); } if (mediaType < 0) { result.IsSuccess = false; result.Message = "MediaSourceType錯誤"; return(result); } IMediaExtractor mediaExtractor = null; try { switch (mediaType) { case 0: break; case 1: mediaExtractor = new ImageExtractor(mediaType, path); break; case 2: mediaExtractor = new AudioExtractor(mediaType, path); break; case 3: mediaExtractor = new VideoExtractor(mediaType, path); break; default: return(null); } if (mediaExtractor == null || mediaExtractor.MediaInformation == null) { result.IsSuccess = false; result.Message = "IMediaExtractor不得為空或解析失敗"; return(result); } var dicMediaInformation = Utility.ParseObj(mediaExtractor.MediaInformation); result.MediaExtractor = mediaExtractor; result.DicMediaInformation = dicMediaInformation; result.IsSuccess = true; result.Message = "MediaMetadataExtractor套件解析成功"; } catch (Exception ex) { result.IsSuccess = false; result.Message = "MediaMetadataExtractor套件解析錯誤" + "\r\n" + ex.Message; } return(result); }
public ActionResult Play(string path, bool isAudioOnly = false) { if (!path.IsNullOrEmpty()) { string physicalPath; string category; Global.GetPhysicalPathAndCategory(path, out physicalPath, out category); if (!physicalPath.IsNullOrEmpty()) { if (isAudioOnly && !AudioExtractor.Extract(ref path, physicalPath)) { return(null); } Player player = Request.GetPlayer(path); string parent = Path.GetDirectoryName(physicalPath); switch (player) { case Player.Html5Video: string[] subs = Directory.EnumerateFiles(parent, "{0}.*".FormatWith(Path.GetFileNameWithoutExtension(physicalPath))) .Where(s => SubtitleConverter.CanExtract(s)) .Select(s => GetPathForUrl(s, category)).ToArray(); Html5VideoModel model = new Html5VideoModel { Title = Path.GetFileNameWithoutExtension(path), Url = Request.GetMediaUrl(path), SubtitleLanguages = subs.ToSubtitleLanguages(), Parent = Url.Action(Global.ActionName.Index, GetPathForUrl(parent, category).GetRouteValues()), }; FileModel[] files = GetFiles(new DirectoryInfo(parent), category); int index = Array.FindIndex(files, f => f.PathForUrl.Equals(path, StringComparison.OrdinalIgnoreCase)); if (index > 0) { model.Previous = Url.Action(Global.ActionName.Play, files[index - 1].PathForUrl.GetRouteValues()); } if (index < (files.Length - 1)) { model.Next = Url.Action(Global.ActionName.Play, files[index + 1].PathForUrl.GetRouteValues()); } return(View(player.GetViewName(), playerMasterPageName, model)); case Player.Html5Audio: return(View(player.GetViewName(), playerMasterPageName, new Html5AudioModel { Title = Path.GetFileNameWithoutExtension(path), Url = Request.GetMediaUrl(path), Parent = Url.Action(Global.ActionName.Index, GetPathForUrl(parent, category).GetRouteValues()), })); case Player.Silverlight: case Player.Flash: return(View(player.GetViewName(), playerMasterPageName, new MediaModel { Title = Path.GetFileNameWithoutExtension(path), Url = Request.GetMediaUrl(path), })); case Player.None: return(Redirect(Request.GetMediaUrl(path))); } } } return(HttpNotFound()); }
public static void RunWithArgs(string[] args, Action <string> showComparisonResultsCallback) { bool scanCues = false; string dirArg = null; string infile = null; var loadDiscInterface = DiscInterface.BizHawk; var compareDiscInterfaces = new List <DiscInterface>(); bool hawk = false; bool music = false; bool overwrite = false; int idx = 0; while (idx < args.Length) { string a = args[idx++]; string au = a.ToUpperInvariant(); if (au == "LOAD") { loadDiscInterface = (DiscInterface)Enum.Parse(typeof(DiscInterface), args[idx++], true); } else if (au == "COMPARE") { compareDiscInterfaces.Add((DiscInterface)Enum.Parse(typeof(DiscInterface), args[idx++], true)); } else if (au == "HAWK") { hawk = true; } else if (au == "CUEDIR") { dirArg = args[idx++]; scanCues = true; } else if (au is "MUSIC") { music = true; } else if (au is "OVERWRITE") { overwrite = true; } else { infile = a; } } if (hawk) { if (infile == null) { return; } HawkAndWriteFile( inputPath: infile, errorCallback: err => Console.WriteLine($"failed to convert {infile}:\n{err}"), discInterface: loadDiscInterface); } if (music) { if (infile is null) { return; } using var disc = Disc.LoadAutomagic(infile); var path = Path.GetDirectoryName(infile); var filename = Path.GetFileNameWithoutExtension(infile); bool?CheckOverwrite(string mp3Path) { if (overwrite) { return(true); // overwrite } Console.WriteLine($"{mp3Path} already exists. Remove existing output files, or retry with the extra argument \"OVERWRITE\"."); return(null); // cancel } AudioExtractor.Extract(disc, path, filename, CheckOverwrite); } bool verbose = true; if (scanCues) { verbose = false; var todo = FindCuesRecurse(dirArg); var po = new ParallelOptions(); var cts = new CancellationTokenSource(); po.CancellationToken = cts.Token; po.MaxDegreeOfParallelism = 1; if (po.MaxDegreeOfParallelism < 0) { po.MaxDegreeOfParallelism = 1; } object olock = new object(); int ctr = 0; bool blocked = false; try { Parallel.ForEach(todo, po, (fp) => { lock (olock) { ctr++; int strlen = todo.Count.ToString().Length; string fmt = string.Format("{{0,{0}}}/{{1,{0}}} {{2}}", strlen); Console.WriteLine(fmt, ctr, todo.Count, Path.GetFileNameWithoutExtension(fp)); } if (!blocked) { foreach (var cmpif in compareDiscInterfaces) { var sw = new StringWriter(); bool success = CompareFile(fp, loadDiscInterface, cmpif, verbose, cts, sw); if (!success) { lock (Console.Out) Console.Out.Write(sw.ToString()); cts.Cancel(); return; } } } }); } catch (AggregateException ae) { Console.WriteLine(ae.ToString()); } catch (OperationCanceledException oce) { Console.WriteLine(oce.ToString()); } Console.WriteLine("--TERMINATED--"); return; } if (compareDiscInterfaces.Count != 0) { var sw = new StringWriter(); foreach (var cmpif in compareDiscInterfaces) { CompareFile(infile, loadDiscInterface, cmpif, verbose, null, sw); } sw.Flush(); string results = sw.ToString(); showComparisonResultsCallback(results); } }