125 lines
3.9 KiB
C#
125 lines
3.9 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using IPA;
|
|
using IPALogger = IPA.Logging.Logger;
|
|
|
|
namespace Setlist
|
|
{
|
|
[Plugin(RuntimeOptions.SingleStartInit)]
|
|
public class Plugin
|
|
{
|
|
internal static Plugin Instance { get; private set; }
|
|
|
|
/// <summary>
|
|
/// BSIPA logger (shows in BSIPA console / game logs when verbose).
|
|
/// </summary>
|
|
internal static IPALogger Log { get; private set; }
|
|
|
|
[Init]
|
|
public Plugin(IPALogger logger)
|
|
{
|
|
Instance = this;
|
|
Log = logger;
|
|
}
|
|
|
|
[OnStart]
|
|
public void OnApplicationStart()
|
|
{
|
|
try
|
|
{
|
|
var playlists = BeatSaberPlaylistsLib.PlaylistManager.DefaultManager.GetAllPlaylists(
|
|
includeChildren: true,
|
|
out AggregateException loadErrors);
|
|
|
|
if (loadErrors != null)
|
|
{
|
|
Log.Error(loadErrors.Message);
|
|
foreach (var inner in loadErrors.InnerExceptions)
|
|
{
|
|
Log.Error(inner.ToString());
|
|
}
|
|
}
|
|
|
|
if (playlists == null || playlists.Length == 0)
|
|
{
|
|
Log.Info("No playlists loaded (or playlist library not initialized yet).");
|
|
return;
|
|
}
|
|
|
|
var entries = new List<(string Title, bool HasSyncUrl, string BeatLeaderGuid)>();
|
|
foreach (var playlist in playlists)
|
|
{
|
|
var hasSyncUrl = false;
|
|
string syncUrl = null;
|
|
if (playlist.TryGetCustomData("syncURL", out var syncObj) && syncObj is string url)
|
|
{
|
|
syncUrl = url;
|
|
hasSyncUrl = !string.IsNullOrWhiteSpace(url);
|
|
}
|
|
|
|
string blGuid = null;
|
|
if (hasSyncUrl && BeatLeaderPlaylistOwnership.TryExtractBeatLeaderPlaylistGuid(syncUrl, out var g))
|
|
{
|
|
blGuid = g;
|
|
}
|
|
|
|
entries.Add((playlist.Title, hasSyncUrl, blGuid));
|
|
}
|
|
|
|
if (entries.Any(e => e.BeatLeaderGuid != null))
|
|
{
|
|
BeatLeaderPlaylistOwnership.ScheduleVerifyAndLog(entries, Log);
|
|
}
|
|
else
|
|
{
|
|
foreach (var e in entries)
|
|
{
|
|
Log.Info(FormatPlaylistLogLine(e.Title, e.HasSyncUrl, e.BeatLeaderGuid, ownedGuids: null));
|
|
}
|
|
}
|
|
}
|
|
catch (Exception ex)
|
|
{
|
|
Log.Error(ex.ToString());
|
|
}
|
|
}
|
|
|
|
[OnExit]
|
|
public void OnApplicationQuit()
|
|
{
|
|
}
|
|
|
|
internal static string FormatPlaylistLogLine(
|
|
string title,
|
|
bool hasSyncUrl,
|
|
string beatLeaderGuid,
|
|
HashSet<string> ownedGuids)
|
|
{
|
|
string ownerPart;
|
|
if (!hasSyncUrl)
|
|
{
|
|
ownerPart = "beatLeaderOwnerConfirmed=n/a (no sync URL)";
|
|
}
|
|
else if (string.IsNullOrEmpty(beatLeaderGuid))
|
|
{
|
|
ownerPart = "beatLeaderOwnerConfirmed=n/a (sync URL is not a BeatLeader playlist)";
|
|
}
|
|
else if (ownedGuids == null)
|
|
{
|
|
ownerPart = "beatLeaderOwnerConfirmed=unknown (BeatLeader /user/playlists did not succeed; see prior log line)";
|
|
}
|
|
else if (ownedGuids.Contains(beatLeaderGuid))
|
|
{
|
|
ownerPart = "beatLeaderOwnerConfirmed=true";
|
|
}
|
|
else
|
|
{
|
|
ownerPart = "beatLeaderOwnerConfirmed=false";
|
|
}
|
|
|
|
return $"Playlist \"{title}\": hasSyncUrl={hasSyncUrl}, {ownerPart}";
|
|
}
|
|
}
|
|
}
|