67 lines
3.5 KiB
C#
67 lines
3.5 KiB
C#
namespace Lumi.Companion.SongOverlay;
|
|
|
|
public sealed record MediaSourceDefinition(string Id, string Label, string Detail, bool EnabledByDefault);
|
|
|
|
public static class MediaSourceCatalog
|
|
{
|
|
public static IReadOnlyList<MediaSourceDefinition> All { get; } =
|
|
[
|
|
new("wmp", "Windows Media Player", "Windows Media Player and the modern Windows Media Player app", true),
|
|
new("youtube", "YouTube / YouTube Music", "YouTube playback exposed by Chrome or Edge", true),
|
|
new("spotify", "Spotify", "Spotify desktop playback", true),
|
|
new("vlc", "VLC", "VLC media playback", false),
|
|
new("apple_music", "iTunes / Apple Music", "iTunes and Apple Music for Windows", false),
|
|
new("soundcloud", "SoundCloud", "SoundCloud playback exposed by a browser or app", false),
|
|
new("tidal", "TIDAL", "TIDAL playback exposed by a browser or app", false),
|
|
new("bandcamp", "Bandcamp", "Bandcamp playback exposed by a browser", false),
|
|
new("qobuz", "Qobuz", "Qobuz playback exposed by a browser or app", false)
|
|
];
|
|
|
|
public static HashSet<string> Defaults() =>
|
|
All.Where(source => source.EnabledByDefault).Select(source => source.Id).ToHashSet(StringComparer.Ordinal);
|
|
|
|
public static string? Detect(string? sourceAppId, string? title, string? artist, string? album)
|
|
{
|
|
var source = (sourceAppId ?? "").ToLowerInvariant();
|
|
var metadata = string.Join(" ", title, artist, album).ToLowerInvariant();
|
|
if (source.Contains("spotify")) return "spotify";
|
|
if (source.Contains("vlc")) return "vlc";
|
|
if (source.Contains("itunes") || source.Contains("applemusic") || source.Contains("apple music")) return "apple_music";
|
|
if (source.Contains("soundcloud")) return "soundcloud";
|
|
if (source.Contains("tidal")) return "tidal";
|
|
if (source.Contains("bandcamp")) return "bandcamp";
|
|
if (source.Contains("qobuz")) return "qobuz";
|
|
if (source.Contains("wmplayer") || source.Contains("zunemusic") || source.Contains("mediaplayer")) return "wmp";
|
|
|
|
var browser = source.Contains("chrome") || source.Contains("msedge") || source.Contains("firefox");
|
|
if (!browser) return null;
|
|
if (metadata.Contains("soundcloud")) return "soundcloud";
|
|
if (metadata.Contains("tidal")) return "tidal";
|
|
if (metadata.Contains("bandcamp")) return "bandcamp";
|
|
if (metadata.Contains("qobuz")) return "qobuz";
|
|
if (metadata.Contains("youtube") || metadata.Contains("yt music")) return "youtube";
|
|
|
|
// Browser media sessions do not consistently expose their origin. Treat
|
|
// an otherwise unidentified browser session as YouTube, the enabled
|
|
// browser default, while named services remain independently switchable.
|
|
return "youtube";
|
|
}
|
|
|
|
public static string? DetectEnabled(
|
|
string? sourceAppId,
|
|
string? title,
|
|
string? artist,
|
|
string? album,
|
|
IReadOnlySet<string> enabled)
|
|
{
|
|
var detected = Detect(sourceAppId, title, artist, album);
|
|
if (detected != "youtube" || enabled.Contains("youtube")) return detected;
|
|
var source = (sourceAppId ?? "").ToLowerInvariant();
|
|
if (!source.Contains("chrome") && !source.Contains("msedge") && !source.Contains("firefox")) return detected;
|
|
return new[] { "soundcloud", "tidal", "bandcamp", "qobuz" }.FirstOrDefault(enabled.Contains);
|
|
}
|
|
|
|
public static string Label(string? id) =>
|
|
All.FirstOrDefault(source => source.Id == id)?.Label ?? "Windows media";
|
|
}
|