Skip to content

Commit

Permalink
improve apple music import
Browse files Browse the repository at this point in the history
  • Loading branch information
th0mk committed Mar 21, 2024
1 parent 645cd49 commit 18f665e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 2 deletions.
17 changes: 16 additions & 1 deletion src/FMBot.Bot/Services/ImportService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
using System.Text;
using System.Text.Json;
using System.Threading.Tasks;
using AngleSharp.Css.Values;
using CsvHelper;
using CsvHelper.Configuration;
using Discord;
Expand Down Expand Up @@ -60,7 +61,18 @@ public ImportService(HttpClient httpClient, TimeService timeService, IOptions<Bo
var innerZipEntry = zip.GetEntry("Apple Media Services information/Apple_Media_Services.zip");
if (innerZipEntry == null)
{
return (ImportStatus.UnknownFailure, null);
var partEntry = zip.GetEntry("Apple Media Services Information Part 1 of 2/Apple_Media_Services.zip");
if (partEntry != null)
{
innerZipEntry = partEntry;
}
else
{
Log.Information("Importing: {userId} / {discordUserId} - HandleAppleMusicFiles - Could not find 'Apple_Media_Services.zip' inside first zip - {zipName}",
user.UserId, user.DiscordUserId, attachment.Filename);

return (ImportStatus.UnknownFailure, null);
}
}

await using var innerZipStream = innerZipEntry.Open();
Expand All @@ -69,6 +81,9 @@ public ImportService(HttpClient httpClient, TimeService timeService, IOptions<Bo
var csvEntry = innerZip.GetEntry("Apple_Media_Services/Apple Music Activity/Apple Music Play Activity.csv");
if (csvEntry == null)
{
Log.Information("Importing: {userId} / {discordUserId} - HandleAppleMusicFiles - Could not find 'Apple Music Play Activity.csv' inside second zip",
user.UserId, user.DiscordUserId);

return (ImportStatus.UnknownFailure, null);
}

Expand Down
4 changes: 3 additions & 1 deletion src/FMBot.Bot/SlashCommands/ImportSlashCommands.cs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,9 @@ public async Task AppleMusicAsync([Summary("file", "'Apple Media Services inform
if (imports.status == ImportStatus.UnknownFailure)
{
embed.WithColor(DiscordConstants.WarningColorOrange);
await UpdateImportEmbed(message, embed, description, $"❌ Invalid Apple Music import file, or something went wrong. Please open a help thread on [our server](https://discord.gg/fmbot).", true);
await UpdateImportEmbed(message, embed, description, $"❌ Invalid Apple Music import file, or something went wrong.\n\n" +
$"If you've uploaded a `.zip` file you can also try to find the `Apple Music Play Activity.csv` inside the .zip and attach that instead.\n\n" +
$"You can also open a help thread on [our server](https://discord.gg/fmbot).", true);
this.Context.LogCommandUsed(CommandResponse.WrongInput);
return;
}
Expand Down

0 comments on commit 18f665e

Please sign in to comment.