freyacodes / archived-bot

A Discord music bot serving music in over 3 million discord servers
https://fredboat.com/docs
MIT License
487 stars 210 forks source link

Local files support for selfhosting #422

Open LordXerus opened 6 years ago

LordXerus commented 6 years ago

Basically, Fred only reads playlists from paste services, fred should be able to read and create playlists using the same format(link newline link newline...)from text\plain files, and it should also be able to scan directories for audio files if it is asked to play one.

I have self-hosted fredboat and saw that fredboat doesn't know what to do with text files or directories. Is it possible to make fred:

  1. If fred is passed ;;play \, fred scans directory for music files.
  2. If fred is passed ;;play <text\plain file>, fred treats all files as playlists, not just hastebin links. Currently fred only recognizes the first link if I format it as
    localhost/music/file.mp3
    localhost/music/file2.mp3
    localhost/music/file3.mp3
    localhost/music/file4.mp3
    ...

    If I link fred to a file like ^above^ Fred will say "file has been added to the queue." and all later songs like file2-4 are ignored.

I am running fredboat.jar on a ubuntu 16.04.3LTS with LAMP Apache2 Web Server

Reserved memory:                58MB
-> Of which is used:            29MB
-> Of which is free:            28MB
Max reservable:                 119MB

----------

Sharding:                       [0 / 1]
Players playing:                1
Known servers:                  1
Known users in servers:         11
Distribution:                   PATRON
JDA responses total:            178
JDA version:                    3.3.1_308
FredBoat version:               1.1_1417
Lavaplayer version:             1.2.45

----------

Last agent run times:
DBConnectionWatchdogAgent       20.12.2017 01:42:25 CET
StatsAgent                      20.12.2017 01:42:14 CET

If these features are already within fred, please tell me how to use them. I know minimal java.

The stuff below is relevant information that I could use to fix this once I figure out how fredboat is structured/works, text in the text\plain files that I pointed fred to with ;;play path/to/text, and an error that fred sent me when I tried to feed text files. . Possibly Helpful Stuff: In java.nio.file.Files

   String fileType = "Undetermined";
   final File file = new File(fileName);
   try
   {
      fileType = Files.probeContentType(file.toPath());
   }
   catch (IOException ioException)
   {
      out.println(
           "ERROR: Unable to determine file type for " + fileName
              + " due to exception " + ioException);
   }

copied from https://dzone.com/articles/determining-file-types-java

for directories using String[] list() then for-looping it to test each file type. Then feeding the matching strings to fredboat playlist system. for text\plain files directly parse it as a playlist

copied from http://www.codejava.net/java-se/file-io/how-to-list-files-and-directories-in-a-directory

In order to distinguish between file and directory, use java.io.File.isDirectory() and java.io.File.isFile() from docs.oracle.com and https://www.tutorialspoint.com/java/io/file_isdirectory.htm

---------------------------------------------------------FILE------------------------------------------------------------------- I have tried to replace the file breaks(\n) with \\n, [space]( ),[comma](,) but yield errors saying it's a invalid url the file is a text/plain named all I linked fred to:

http://localhost/LordXerusPrivate/Alan%20Walker%20-%20Fade.mp3
http://localhost/LordXerusPrivate/Alan%20Walker%20-%20Force.mp3
http://localhost/LordXerusPrivate/Alan%20Walker%20-%20Spectre.mp3
http://localhost/LordXerusPrivate/Itro%20&%20Tobu%20-%20Cloud%209.mp3
http://localhost/LordXerusPrivate/Itro%20&%20Tobu%20-%20Holiday.mp3
http://localhost/LordXerusPrivate/Jim%20Yosef%20-%20Link.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Caelum.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Candyland.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Colors.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Crime%20(Instrumental).mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Dreams.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Floating%20(Instrumental).mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Hope%20(Original%20Mix).mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Infectious%20(Original%20Mix).mp3
http://localhost/LordXerusPrivate/Tobu%20&%20Itro%20-%20Fantasy.mp3
http://localhost/LordXerusPrivate/Tobu%20&%20Itro%20-%20Magic%20(Original%20Mix).mp3
http://localhost/LordXerusPrivate/Tobu%20&%20Itro%20-%20Sunburst.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Legacy.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Life.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Lightness%20(Original%20Mix).mp3
http://localhost/LordXerusPrivate/Tobu%20&%20Marcus%20Mouya%20-%20Running%20Away%20(Instrumental).mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Mesmerize.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20My%20Own%20Paradise.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Reflection.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Sapphire.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Seven.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Something%20Right%20(Instrumental).mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Sound%20of%20Goodbye.mp3
http://localhost/LordXerusPrivate/Tobu%20-%20Sweet%20Story.mp3

--------------------------------------------------EDIT----------------------------------------------------------------------- I found something: Suspicious error when loading info for http://localhost/raw/all2. @Lord Xerus an error occured :anger:

java.lang.NullPointerException
    fredboat.audio.source.HttpSourceManager.detectContainerWithClient(HttpSourceManager.java:155)
    fredboat.audio.source.HttpSourceManager.detectContainer(HttpSourceManager.java:130)
    fredboat.audio.source.HttpSourceManager.loadItem(HttpSourceManager.java:114)
    com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager.checkSourcesForItemOnce(DefaultAudioPlayerManager.java:429)
    com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager.checkSourcesForItem(DefaultAudioPlayerManager.java:415)
    com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager.lambda$createItemLoader$0(DefaultAudioPlayerManager.java:219)
    java.util.concurrent.FutureTask.run(FutureTask.java:266)
    java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    java.lang.Thread.run(Thread.java:748)
    ...

When I tried to play this text\plain file: "http://localhost/LordXerusPrivate/Alan%20Walker%20-%20Fade.mp3","http://localhost/LordXerusPrivate/Alan%20Walker%20-%20Force.mp3","http://localhost/LordXerusPrivate/Alan%20Walker%20-%20Spectre.mp3","http://localhost/LordXerusPrivate/Itro%20&%20Tobu%20-%20Cloud%209.mp3","http://localhost/LordXerusPrivate/Itro%20&%20Tobu%20-%20Holiday.mp3","http://localhost/LordXerusPrivate/Jim%20Yosef%20-%20Link.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Caelum.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Candyland.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Colors.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Crime%20(Instrumental).mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Dreams.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Floating%20(Instrumental).mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Hope%20(Original%20Mix).mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Infectious%20(Original%20Mix).mp3","http://localhost/LordXerusPrivate/Tobu%20&%20Itro%20-%20Fantasy.mp3","http://localhost/LordXerusPrivate/Tobu%20&%20Itro%20-%20Magic%20(Original%20Mix).mp3","http://localhost/LordXerusPrivate/Tobu%20&%20Itro%20-%20Sunburst.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Legacy.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Life.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Lightness%20(Original%20Mix).mp3","http://localhost/LordXerusPrivate/Tobu%20&%20Marcus%20Mouya%20-%20Running%20Away%20(Instrumental).mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Mesmerize.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20My%20Own%20Paradise.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Reflection.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Sapphire.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Seven.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Something%20Right%20(Instrumental).mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Sound%20of%20Goodbye.mp3","http://localhost/LordXerusPrivate/Tobu%20-%20Sweet%20Story.mp3" ------------------------------------------------------------UPDATE----------------------------------------------------------- Managed to open a strange version of the source in eclipse(6000 errors, which look like missing dependencies) but I think a way to achieve the objectives here is to add a MIME type check before or after an exception...

freyacodes commented 6 years ago

It is possible that FredBoat may accept .m3u or .pls playlists linking to URLs.

You might otherwise want to write your own AudioSourceManager. I believe Lavaplayer has an AudioSourceManager that accepts local files

schnapster commented 6 years ago

https://github.com/Frederikam/FredBoat/commit/819ced0af3c7b384c758d1eca72af2e94037df36 (and the commits before it) add local file support, though it doesnt accept directories / files names with whitespace in it currently.

LordXerus commented 6 years ago

Frederikam, I have failed to do so. I think I've catched a PATTERN object that describe .m3u or .pls strings. However, because I'm running on local host or XX.XXX.XXX.XXX(public IP), discord won't link the target unless I add http:// which doesn't seem to be included in the PATTERN object that I think fredboat uses to determine playlists. Therefore, FredBoat will search for that instead of recognizing it as a URL, but when I do https://localhost/path/to/list.m3u it seems to still have the same effect as the .txt file. I also have failed to compile lavaplayer.jar on ubuntu (something like OPUS ./configure script not exiting properly and stopping gradlew jar?) and will try to do it on Windows again (have tried it but missing cmake and it wasn't my computer at the time...)