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 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); } }