1
0
mirror of synced 2024-11-28 09:20:53 +01:00

Fix song names with invalid characters on online lounge and limit the new filename length to avoid failed downloads due to path_max exceeded

This commit is contained in:
0aubsq 2022-06-20 07:18:47 +02:00
parent 9bc9b1d465
commit 52a0680bfa
4 changed files with 19 additions and 3 deletions

View File

@ -110,6 +110,7 @@ namespace TJAPlayer3
Menu_Title = TxC(@"Menu_Title.png"); Menu_Title = TxC(@"Menu_Title.png");
Menu_Highlight = TxC(@"Menu_Highlight.png"); Menu_Highlight = TxC(@"Menu_Highlight.png");
Enum_Song = TxC(@"Enum_Song.png"); Enum_Song = TxC(@"Enum_Song.png");
Loading = TxC(@"Loading.png");
Scanning_Loudness = TxC(@"Scanning_Loudness.png"); Scanning_Loudness = TxC(@"Scanning_Loudness.png");
Overlay = TxC(@"Overlay.png"); Overlay = TxC(@"Overlay.png");
Network_Connection = TxC(@"Network_Connection.png"); Network_Connection = TxC(@"Network_Connection.png");
@ -1646,6 +1647,7 @@ namespace TJAPlayer3
Menu_Title, Menu_Title,
Menu_Highlight, Menu_Highlight,
Enum_Song, Enum_Song,
Loading,
Scanning_Loudness, Scanning_Loudness,
NamePlateBase, NamePlateBase,
Overlay, Overlay,

View File

@ -529,6 +529,8 @@ namespace TJAPlayer3
else if (iCurrentMenu == 1) else if (iCurrentMenu == 1)
{ {
//TJAPlayer3.Tx.Loading?.t2D描画(TJAPlayer3.app.Device, 18, 7);
// Reload character, a bit time expensive but with a O(N) memory complexity instead of O(N * M) // Reload character, a bit time expensive but with a O(N) memory complexity instead of O(N * M)
TJAPlayer3.Tx.ReloadCharacter(TJAPlayer3.NamePlateConfig.data.Character[iPlayer], iCharacterCurrent, iPlayer); TJAPlayer3.Tx.ReloadCharacter(TJAPlayer3.NamePlateConfig.data.Character[iPlayer], iCharacterCurrent, iPlayer);
TJAPlayer3.NamePlateConfig.data.Character[iPlayer] = iCharacterCurrent; TJAPlayer3.NamePlateConfig.data.Character[iPlayer] = iCharacterCurrent;

View File

@ -456,7 +456,7 @@ namespace TJAPlayer3
if (this.cdnSongListIndex < apiMethods.FetchedSongsList.Length) if (this.cdnSongListIndex < apiMethods.FetchedSongsList.Length)
{ {
var song = apiMethods.FetchedSongsList[this.cdnSongListIndex - 1]; var song = apiMethods.FetchedSongsList[this.cdnSongListIndex - 1];
var zipPath = $@"Cache\{song.Md5}.zip"; //var zipPath = $@"Cache\{song.Md5}.zip";
var downloadLink = GetDownloadLink(song); var downloadLink = GetDownloadLink(song);
if (CSongDict.tContainsSongUrl(downloadLink)) if (CSongDict.tContainsSongUrl(downloadLink))
@ -532,6 +532,16 @@ namespace TJAPlayer3
#region [Song Downloading] #region [Song Downloading]
public string ReplaceInvalidChars(string filename, string substitute = "_")
{
return string.Join(substitute, filename.Split(Path.GetInvalidFileNameChars()));
}
public string TruncateString(string s, int length)
{
return s.Substring(0, Math.Min(length, s.Length));
}
private string GetAssignedLanguageValue(Dictionary<string, string> ens) private string GetAssignedLanguageValue(Dictionary<string, string> ens)
{ {
if (ens.ContainsKey(TJAPlayer3.ConfigIni.sLang)) if (ens.ContainsKey(TJAPlayer3.ConfigIni.sLang))
@ -551,8 +561,10 @@ namespace TJAPlayer3
// Create Cache folder if does not exist // Create Cache folder if does not exist
Directory.CreateDirectory($@"Cache\"); Directory.CreateDirectory($@"Cache\");
var song = apiMethods.FetchedSongsList[this.cdnSongListIndex - 1]; var song = apiMethods.FetchedSongsList[this.cdnSongListIndex - 1];
var zipPath = $@"Cache\{song.SongTitle}-{song.Md5}.zip"; var zipName = ReplaceInvalidChars($@"{TruncateString(song.SongTitle, 16)}-{TruncateString(song.Md5, 10)}");
var zipPath = $@"Cache\{zipName}.zip";
var downloadLink = GetDownloadLink(song); var downloadLink = GetDownloadLink(song);
try try
@ -633,7 +645,7 @@ namespace TJAPlayer3
} }
var songPath = $@"{genredPath}{song.SongTitle}-{song.Md5}"; var songPath = $@"{genredPath}{zipName}";
System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, songPath); System.IO.Compression.ZipFile.ExtractToDirectory(zipPath, songPath);

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB