jagrosh / MusicBot

🎶 A Discord music bot that's easy to set up and run yourself!
https://jmusicbot.com
Apache License 2.0
5.23k stars 2.51k forks source link

Playlists using UTF-16 encoding sometimes don't load #883

Open Matthew2051 opened 2 years ago

Matthew2051 commented 2 years ago

Bug Description

As mentioned on discord, the MusicBot seems unable to handle more than 128 .txt files in the Playlists folder.

Steps to Reproduce

  1. Add more than 128 files to Playlists folder
  2. Run playlist command on Discord
  3. Only returns 128 Playlists, also can't play playlists outside this range

Example Files in Explorer: explorer

Example Playlist Command: playlist

Example Error when trying to play a playlist outside of the 128 range: error

Expected Result

I expect to be able to play any playlist regardless of the quantity of playlists in the playlist folder.

Debug Output

System Properties:
  java.version = 17
  java.vm.name = Java HotSpot(TM) 64-Bit Server VM
  java.vm.specification.version = 17
  java.runtime.name = Java(TM) SE Runtime Environment
  java.runtime.version = 17+35-LTS-2724
  java.specification.version = 17
  os.arch = amd64
  os.name = Windows 10

JMusicBot Information:
  Version = 0.3.5
  Owner = 209240452371578880
  Prefix = !
  AltPrefix = null
  MaxSeconds = 0
  NPImages = false
  SongInStatus = true
  StayInChannel = true
  UseEval = false
  UpdateAlerts = true

Dependency Information:
  JDA Version = 4.3.0_312
  JDA-Utilities Version = 3.0.5
  Lavaplayer Version = 1.3.78

Runtime Information:
  Total Memory = 56
  Used Memory = 16

Discord Information:
  ID = 888173169964355604
  Guilds = 1
  Users = 2


### Additional Info

The playlists seem to be loaded alphabetically. I have also tried creating new playlists that fall at the start of the list e.g. "01 Test.txt". Adding these reduces the playlists discovered, always maintaining 128.

### Checklist

- [X] I have looked for information about this [within the documentation](https://jmusicbot.com/)
- [X] I have searched for similar issues [on the issues page](https://github.com/jagrosh/MusicBot/issues?q=is%3Aissue)
- [X] I am running the latest version of the bot: ![Release](https://img.shields.io/github/release/jagrosh/MusicBot.svg)
MichailiK commented 2 years ago

I cannot seem to reproduce this behavior on a similar environment.

Debug Output ``` System Properties: java.version = 17 java.vm.name = OpenJDK 64-Bit Server VM java.vm.specification.version = 17 java.runtime.name = OpenJDK Runtime Environment java.runtime.version = 17+35-2724 java.specification.version = 17 os.arch = amd64 os.name = Windows 10 JMusicBot Information: Version = Snapshot Owner = 384770076110487552 Prefix = t; AltPrefix = null MaxSeconds = 0 NPImages = false SongInStatus = false StayInChannel = false UseEval = false UpdateAlerts = false Dependency Information: JDA Version = 4.2.1_253 JDA-Utilities Version = 3.0.5 Lavaplayer Version = 1.3.75 Runtime Information: Total Memory = 34 Used Memory = 22 Discord Information: ID = 764832782828044328 Guilds = 2 Users = 2 ```

Could you/have you tried copying the file name (except the .txt bit)? Perhaps some kind of special/unusual hyphen in the name or other weirdness.

MichailiK commented 2 years ago

We have come to the conclusion that the PowerShell Script found in the "Advanced Config Generation" wiki results in files are encoded in UTF-16 LE BOM, which JMusicBot is sometimes unable to read.

UPDATE: The script has now been updated to ensure a UTF-8 file gets generated.

MichailiK commented 2 years ago

https://github.com/jagrosh/MusicBot/blob/48263ec60afcbcdeb576e7fdfad4a38f349349be/src/main/java/com/jagrosh/jmusicbot/playlist/PlaylistLoader.java#L99

An exception, java.nio.charset.MalformedInputException: Input length = 1, gets thrown.

idea64_2021-09-20_22-05-40

When an exception occurs, null is being returned. This is problematic in the play playlist command:

https://github.com/jagrosh/MusicBot/blob/48263ec60afcbcdeb576e7fdfad4a38f349349be/src/main/java/com/jagrosh/jmusicbot/commands/music/PlayCmd.java#L232-L237

The command falsely assumes that the playlist could not be found if the return value is null. This should be updated to error out in case of exceptions like these, to avoid further confusion.