Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add feature to load directory of songs as playlist #1338

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 23 additions & 1 deletion src/main/java/com/jagrosh/jmusicbot/playlist/PlaylistLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public Playlist getPlaylist(String name)
{
boolean[] shuffle = {false};
List<String> list = new ArrayList<>();
Files.readAllLines(OtherUtil.getPath(config.getPlaylistsFolder()+File.separator+name+".txt")).forEach(str ->
Files.readAllLines(OtherUtil.getPath(config.getPlaylistsFolder()+File.separator+name+".txt")).forEach(str ->
{
String s = str.trim();
if(s.isEmpty())
Expand All @@ -107,6 +107,9 @@ public Playlist getPlaylist(String name)
if(s.equalsIgnoreCase("#shuffle") || s.equalsIgnoreCase("//shuffle"))
shuffle[0]=true;
}
else if(isDirectory(s)){
list.addAll(getFilePaths(s));
}
else
list.add(s);
});
Expand All @@ -125,6 +128,25 @@ public Playlist getPlaylist(String name)
return null;
}
}

public static boolean isDirectory(String filePath) {
File file = new File(filePath);
return file.isDirectory();
}

public static List<String> getFilePaths(String filePath) {
List<String> filePaths = new ArrayList<>();
File directory = new File(filePath);
File[] files = directory.listFiles();
if (files != null) {
for (File file : files) {
if (file.isFile()) {
filePaths.add(file.getAbsolutePath());
}
}
}
return filePaths;
}


private static <T> void shuffle(List<T> list)
Expand Down