From 18f665ec591099a3e3c3d64215b9661986338dc5 Mon Sep 17 00:00:00 2001 From: thomkaptein Date: Thu, 21 Mar 2024 16:54:51 +0100 Subject: [PATCH] improve apple music import --- src/FMBot.Bot/Services/ImportService.cs | 17 ++++++++++++++++- .../SlashCommands/ImportSlashCommands.cs | 4 +++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/FMBot.Bot/Services/ImportService.cs b/src/FMBot.Bot/Services/ImportService.cs index 76f4cc4f..cde68095 100644 --- a/src/FMBot.Bot/Services/ImportService.cs +++ b/src/FMBot.Bot/Services/ImportService.cs @@ -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; @@ -60,7 +61,18 @@ public async Task<(ImportStatus status, List result)> 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(); @@ -69,6 +81,9 @@ public async Task<(ImportStatus status, List result)> 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); } diff --git a/src/FMBot.Bot/SlashCommands/ImportSlashCommands.cs b/src/FMBot.Bot/SlashCommands/ImportSlashCommands.cs index 2288ccbf..4c0943bc 100644 --- a/src/FMBot.Bot/SlashCommands/ImportSlashCommands.cs +++ b/src/FMBot.Bot/SlashCommands/ImportSlashCommands.cs @@ -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; }