mirror of
https://github.com/ppy/osu.git
synced 2026-05-30 04:39:54 +08:00
Add manual MIME type resolution for TagLib file creation
This commit is contained in:
@@ -9,6 +9,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.IO.FileAbstraction;
|
||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
using osu.Game.Storyboards;
|
||||
using osu.Game.Utils;
|
||||
using TagLib;
|
||||
using File = TagLib.File;
|
||||
|
||||
@@ -61,7 +62,7 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
{
|
||||
// We use TagLib here for platform invariance; BASS cannot detect audio presence on Linux.
|
||||
using (Stream data = context.WorkingBeatmap.GetStream(storagePath))
|
||||
using (File tagFile = File.Create(new StreamFileAbstraction(filename, data)))
|
||||
using (File tagFile = TagLibUtils.CreateFile(new StreamFileAbstraction(filename, data)))
|
||||
{
|
||||
if (tagFile.Properties.AudioChannels == 0)
|
||||
continue;
|
||||
|
||||
@@ -9,6 +9,7 @@ using osu.Game.Beatmaps;
|
||||
using osu.Game.IO.FileAbstraction;
|
||||
using osu.Game.Rulesets.Edit.Checks.Components;
|
||||
using osu.Game.Storyboards;
|
||||
using osu.Game.Utils;
|
||||
using TagLib;
|
||||
using File = TagLib.File;
|
||||
|
||||
@@ -45,7 +46,7 @@ namespace osu.Game.Rulesets.Edit.Checks
|
||||
try
|
||||
{
|
||||
using (Stream data = context.WorkingBeatmap.GetStream(storagePath))
|
||||
using (File tagFile = File.Create(new StreamFileAbstraction(filename, data)))
|
||||
using (File tagFile = TagLibUtils.CreateFile(new StreamFileAbstraction(filename, data)))
|
||||
{
|
||||
int height = tagFile.Properties.VideoHeight;
|
||||
int width = tagFile.Properties.VideoWidth;
|
||||
|
||||
@@ -102,7 +102,7 @@ namespace osu.Game.Screens.Edit.Setup
|
||||
|
||||
try
|
||||
{
|
||||
tagSource = TagLib.File.Create(source.FullName);
|
||||
tagSource = TagLibUtils.CreateFile(source.FullName);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
// Copyright (c) ppy Pty Ltd <contact@ppy.sh>. Licensed under the MIT Licence.
|
||||
// See the LICENCE file in the repository root for full licence text.
|
||||
|
||||
using System.IO;
|
||||
using osu.Game.IO.FileAbstraction;
|
||||
using TagLib;
|
||||
|
||||
namespace osu.Game.Utils
|
||||
{
|
||||
public class TagLibUtils
|
||||
{
|
||||
/// <summary>
|
||||
/// Creates a <see cref="TagLib.File"/> with culture-invariant MIME type detection.
|
||||
/// </summary>
|
||||
/// <param name="fileAbstraction">The file abstraction of the file to be created.</param>
|
||||
/// <returns>The <see cref="TagLib.File"/> created.</returns>
|
||||
public static TagLib.File CreateFile(StreamFileAbstraction fileAbstraction) =>
|
||||
TagLib.File.Create(fileAbstraction, getMimeType(fileAbstraction.Name), ReadStyle.Average);
|
||||
|
||||
/// <summary>
|
||||
/// Creates a <see cref="TagLib.File"/> with culture-invariant MIME type detection.
|
||||
/// </summary>
|
||||
/// <param name="filePath">The full path of the file to be created.</param>
|
||||
/// <returns>The <see cref="TagLib.File"/> created.</returns>
|
||||
public static TagLib.File CreateFile(string filePath) =>
|
||||
TagLib.File.Create(filePath, getMimeType(filePath), ReadStyle.Average);
|
||||
|
||||
// Manual MIME type resolution to avoid culture variance (ie. https://github.com/ppy/osu/issues/32962)
|
||||
private static string getMimeType(string fileName) =>
|
||||
@"taglib/" + Path.GetExtension(fileName).TrimStart('.');
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user