aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/HttpHandlers/AudioHandler.cs
diff options
context:
space:
mode:
authorLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-08-12 13:05:51 -0400
committerLukePulverenti Luke Pulverenti luke pulverenti <LukePulverenti Luke Pulverenti luke.pulverenti@gmail.com>2012-08-12 13:05:51 -0400
commit6fe82962661d30baadb19d241f30fb6126f53406 (patch)
tree482dbf54eeb0adf5f86c453b10611588677759b3 /MediaBrowser.Api/HttpHandlers/AudioHandler.cs
parent537b3553b8e630e24127844bcd971cd68f408568 (diff)
Moved more common code from audio/video handler down to the base class
Diffstat (limited to 'MediaBrowser.Api/HttpHandlers/AudioHandler.cs')
-rw-r--r--MediaBrowser.Api/HttpHandlers/AudioHandler.cs47
1 files changed, 23 insertions, 24 deletions
diff --git a/MediaBrowser.Api/HttpHandlers/AudioHandler.cs b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs
index c3c27c568..311f8f9c7 100644
--- a/MediaBrowser.Api/HttpHandlers/AudioHandler.cs
+++ b/MediaBrowser.Api/HttpHandlers/AudioHandler.cs
@@ -1,28 +1,36 @@
-using System;
-using System.Collections.Generic;
+using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Model.Entities;
namespace MediaBrowser.Api.HttpHandlers
{
+ /// <summary>
+ /// Supported output formats are: mp3,flac,ogg,wav,asf,wma,aac
+ /// </summary>
public class AudioHandler : BaseMediaHandler<Audio>
{
/// <summary>
- /// Supported values: mp3,flac,ogg,wav,asf
+ /// Overriding to provide mp3 as a default, since pretty much every device supports it
/// </summary>
- public IEnumerable<string> AudioFormats
+ protected override IEnumerable<string> OutputFormats
{
get
{
- string val = QueryString["audioformats"];
+ IEnumerable<string> vals = base.OutputFormats;
- if (string.IsNullOrEmpty(val))
- {
- return new string[] { "mp3" };
- }
+ return vals.Any() ? vals : new string[] { "mp3" };
+ }
+ }
- return val.Split(',');
+ /// <summary>
+ /// We can output these files directly, but we can't encode them
+ /// </summary>
+ protected override IEnumerable<string> UnsupportedOutputEncodingFormats
+ {
+ get
+ {
+ return new string[] { "wma", "aac" };
}
}
@@ -48,7 +56,7 @@ namespace MediaBrowser.Api.HttpHandlers
return null;
}
- int index = AudioFormats.ToList().IndexOf(audioFormat);
+ int index = OutputFormats.ToList().IndexOf(audioFormat);
return AudioBitRates.ElementAt(index);
}
@@ -58,14 +66,13 @@ namespace MediaBrowser.Api.HttpHandlers
/// </summary>
protected override bool RequiresConversion()
{
- string currentFormat = Path.GetExtension(LibraryItem.Path).Replace(".", string.Empty);
-
- // If it's not in a format the consumer accepts, return true
- if (!AudioFormats.Any(f => currentFormat.EndsWith(f, StringComparison.OrdinalIgnoreCase)))
+ if (base.RequiresConversion())
{
return true;
}
+ string currentFormat = Path.GetExtension(LibraryItem.Path).Replace(".", string.Empty);
+
int? bitrate = GetMaxAcceptedBitRate(currentFormat);
// If the bitrate is greater than our desired bitrate, we need to transcode
@@ -91,21 +98,13 @@ namespace MediaBrowser.Api.HttpHandlers
}
/// <summary>
- /// Gets the format we'll be converting to
- /// </summary>
- protected override string GetOutputFormat()
- {
- return AudioFormats.First();
- }
-
- /// <summary>
/// Creates arguments to pass to ffmpeg
/// </summary>
protected override string GetCommandLineArguments()
{
List<string> audioTranscodeParams = new List<string>();
- string outputFormat = GetOutputFormat();
+ string outputFormat = GetConversionOutputFormat();
int? bitrate = GetMaxAcceptedBitRate(outputFormat);