mirror of
https://github.com/ppy/osu.git
synced 2025-02-15 19:33:20 +08:00
Add online fetch support for online IDs
This commit is contained in:
parent
955a78e76d
commit
a775d00bd8
@ -83,10 +83,29 @@ namespace osu.Game.Beatmaps
|
|||||||
{
|
{
|
||||||
model.Beatmaps = createBeatmapDifficulties(archive);
|
model.Beatmaps = createBeatmapDifficulties(archive);
|
||||||
|
|
||||||
// remove metadata from difficulties where it matches the set
|
|
||||||
foreach (BeatmapInfo b in model.Beatmaps)
|
foreach (BeatmapInfo b in model.Beatmaps)
|
||||||
|
{
|
||||||
|
// remove metadata from difficulties where it matches the set
|
||||||
if (model.Metadata.Equals(b.Metadata))
|
if (model.Metadata.Equals(b.Metadata))
|
||||||
b.Metadata = null;
|
b.Metadata = null;
|
||||||
|
|
||||||
|
// by setting the model here, we can update the noline set id below.
|
||||||
|
b.BeatmapSet = model;
|
||||||
|
|
||||||
|
fetchAndPopulateOnlineIDs(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
// check if a set already exists with the same online id, delete if it does.
|
||||||
|
if (model.OnlineBeatmapSetID != null)
|
||||||
|
{
|
||||||
|
var existingOnlineId = beatmaps.ConsumableItems.FirstOrDefault(b => b.OnlineBeatmapSetID == model.OnlineBeatmapSetID);
|
||||||
|
if (existingOnlineId != null)
|
||||||
|
{
|
||||||
|
Delete(existingOnlineId);
|
||||||
|
beatmaps.PurgeDeletable(s => s.ID == existingOnlineId.ID);
|
||||||
|
Logger.Log($"Found existing beatmap set with same OnlineBeatmapSetID ({model.OnlineBeatmapSetID}). It has been purged.", LoggingTarget.Database);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override BeatmapSetInfo CheckForExisting(BeatmapSetInfo model)
|
protected override BeatmapSetInfo CheckForExisting(BeatmapSetInfo model)
|
||||||
@ -99,18 +118,6 @@ namespace osu.Game.Beatmaps
|
|||||||
return existingHashMatch;
|
return existingHashMatch;
|
||||||
}
|
}
|
||||||
|
|
||||||
// check if a set already exists with the same online id
|
|
||||||
if (model.OnlineBeatmapSetID != null)
|
|
||||||
{
|
|
||||||
var existingOnlineId = beatmaps.ConsumableItems.FirstOrDefault(b => b.OnlineBeatmapSetID == model.OnlineBeatmapSetID);
|
|
||||||
if (existingOnlineId != null)
|
|
||||||
{
|
|
||||||
Delete(existingOnlineId);
|
|
||||||
beatmaps.PurgeDeletable(s => s.ID == existingOnlineId.ID);
|
|
||||||
Logger.Log($"Found existing beatmap set with same OnlineBeatmapSetID ({model.OnlineBeatmapSetID}). It has been purged.", LoggingTarget.Database);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -318,7 +325,7 @@ namespace osu.Game.Beatmaps
|
|||||||
|
|
||||||
return new BeatmapSetInfo
|
return new BeatmapSetInfo
|
||||||
{
|
{
|
||||||
OnlineBeatmapSetID = beatmap.BeatmapInfo.BeatmapSet.OnlineBeatmapSetID,
|
OnlineBeatmapSetID = beatmap.BeatmapInfo.BeatmapSet?.OnlineBeatmapSetID,
|
||||||
Beatmaps = new List<BeatmapInfo>(),
|
Beatmaps = new List<BeatmapInfo>(),
|
||||||
Hash = computeBeatmapSetHash(reader),
|
Hash = computeBeatmapSetHash(reader),
|
||||||
Metadata = beatmap.Metadata
|
Metadata = beatmap.Metadata
|
||||||
@ -372,6 +379,40 @@ namespace osu.Game.Beatmaps
|
|||||||
return beatmapInfos;
|
return beatmapInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Query the API to populate mising OnlineBeatmapID / OnlineBeatmapSetID properties.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="beatmap">The beatmap to populate.</param>
|
||||||
|
/// <param name="force">Whether to re-query if the provided beatmap already has populated values.</param>
|
||||||
|
/// <returns>True if population was successful.</returns>
|
||||||
|
private bool fetchAndPopulateOnlineIDs(BeatmapInfo beatmap, bool force = false)
|
||||||
|
{
|
||||||
|
if (!force && beatmap.OnlineBeatmapID != null && beatmap.BeatmapSet.OnlineBeatmapSetID != null)
|
||||||
|
return true;
|
||||||
|
|
||||||
|
Logger.Log("Attempting online lookup for IDs...", LoggingTarget.Database);
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
var req = new GetBeatmapRequest(beatmap);
|
||||||
|
|
||||||
|
req.Perform(api);
|
||||||
|
|
||||||
|
var res = req.Result;
|
||||||
|
|
||||||
|
Logger.Log($"Successfully mapped to {res.OnlineBeatmapSetID} / {res.OnlineBeatmapID}.", LoggingTarget.Database);
|
||||||
|
|
||||||
|
beatmap.BeatmapSet.OnlineBeatmapSetID = res.OnlineBeatmapSetID;
|
||||||
|
beatmap.OnlineBeatmapID = res.OnlineBeatmapID;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
catch (Exception e)
|
||||||
|
{
|
||||||
|
Logger.Log($"Failed ({e})", LoggingTarget.Database);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// A dummy WorkingBeatmap for the purpose of retrieving a beatmap for star difficulty calculation.
|
/// A dummy WorkingBeatmap for the purpose of retrieving a beatmap for star difficulty calculation.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
Loading…
Reference in New Issue
Block a user