Compare commits
No commits in common. "abfab9a18dcba0d626d7ff83a57c6d6cf856af5f" and "d9a7da27f2e3e0636861d2788bc34d625bb8345e" have entirely different histories.
abfab9a18d
...
d9a7da27f2
|
@ -30,6 +30,7 @@ import net.dv8tion.jda.api.entities.*;
|
||||||
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
|
import net.dv8tion.jda.api.entities.channel.middleman.AudioChannel;
|
||||||
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
|
import net.dv8tion.jda.api.events.guild.voice.GuildVoiceUpdateEvent;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
import net.dv8tion.jda.api.hooks.ListenerAdapter;
|
||||||
import net.dv8tion.jda.api.managers.AudioManager;
|
import net.dv8tion.jda.api.managers.AudioManager;
|
||||||
import net.dv8tion.jda.api.requests.GatewayIntent;
|
import net.dv8tion.jda.api.requests.GatewayIntent;
|
||||||
|
@ -64,6 +65,8 @@ public final class Chords extends ListenerAdapter
|
||||||
|
|
||||||
private AudioChannel currentVoiceChannel = null;
|
private AudioChannel currentVoiceChannel = null;
|
||||||
|
|
||||||
|
private int trackNumber = 1;
|
||||||
|
|
||||||
private final Map<String, Playlist> playlists = new HashMap<>();
|
private final Map<String, Playlist> playlists = new HashMap<>();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -253,29 +256,49 @@ public final class Chords extends ListenerAdapter
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void queueDownload(SongRequest request)
|
public Song queueDownload(SongRequest request)
|
||||||
{
|
{
|
||||||
// Song song;
|
Song song;
|
||||||
// if (request.getUrl() != null)
|
if (request.getUrl() != null)
|
||||||
// {
|
{
|
||||||
// song = new Song(request.getUrl());
|
song = new Song(request.getUrl());
|
||||||
// } else
|
} else
|
||||||
// {
|
{
|
||||||
// // interpret search result
|
// interpret search result
|
||||||
// throw new UnsupportedOperationException("Not supported yet.");
|
throw new UnsupportedOperationException("Not supported yet.");
|
||||||
// }
|
}
|
||||||
// if (request.getInvocation().getRequestMessage() != null)
|
if (request.getInvocation().getRequestMessage() != null)
|
||||||
// {
|
{
|
||||||
//
|
song.setRequestedBy(request.getInvocation().getRequestMessage().getAuthor().getName());
|
||||||
// }
|
song.setRequestedIn(request.getInvocation().getRequestMessage().getChannel().getId());
|
||||||
// song.setNumber(trackNumber);
|
}
|
||||||
// trackNumber++;
|
song.setNumber(trackNumber);
|
||||||
// request.addSong(song);
|
trackNumber++;
|
||||||
|
request.setSong(song);
|
||||||
request.getInvocation().respond("Request pending...");
|
request.getInvocation().respond("Request pending...");
|
||||||
downloader.accept(new Downloader.DownloadTask(request, queueManager));
|
downloader.accept(new Downloader.DownloadTask(request, queueManager));
|
||||||
// return song;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// public Song queueDownload(final URL url, GuildMessageReceivedEvent event)
|
||||||
|
// {
|
||||||
|
// Song song = new Song(url);
|
||||||
|
// song.setRequestedBy(event.getAuthor().getName());
|
||||||
|
// song.setRequestedIn(event.getChannel().getId());
|
||||||
|
// song.setNumber(trackNumber);
|
||||||
|
// trackNumber++;
|
||||||
|
// downloader.accept(new Downloader.DownloadTask(song, musicHandler));
|
||||||
|
// return song;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// public Song queueDownload(Result res, GuildMessageReceivedEvent event)
|
||||||
|
// {
|
||||||
|
// Song song = queueDownload(res.getLink(), event);
|
||||||
|
// song.setArtist(res.getArtist());
|
||||||
|
// song.setTitle(res.getTitle());
|
||||||
|
// song.setNumber(trackNumber);
|
||||||
|
// return song;
|
||||||
|
// }
|
||||||
public void setStatus(Song nowPlaying)
|
public void setStatus(Song nowPlaying)
|
||||||
{
|
{
|
||||||
jda.getPresence().setActivity(Activity.listening(nowPlaying.toString()));
|
jda.getPresence().setActivity(Activity.listening(nowPlaying.toString()));
|
||||||
|
@ -391,6 +414,11 @@ public final class Chords extends ListenerAdapter
|
||||||
return queueManager;
|
return queueManager;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getTrackNumber()
|
||||||
|
{
|
||||||
|
return trackNumber;
|
||||||
|
}
|
||||||
|
|
||||||
public static Settings getSettings()
|
public static Settings getSettings()
|
||||||
{
|
{
|
||||||
return settings;
|
return settings;
|
||||||
|
@ -409,47 +437,39 @@ public final class Chords extends ListenerAdapter
|
||||||
@Override
|
@Override
|
||||||
public void accept(SongRequest request, Exception ex)
|
public void accept(SongRequest request, Exception ex)
|
||||||
{
|
{
|
||||||
String response = "";
|
Song song = request.getSong();
|
||||||
if (request.getSongs().size() > 1)
|
|
||||||
response += "Downloading " + request.getSongs().size() + " tracks:\n";
|
|
||||||
for (Song song : request.getSongs())
|
|
||||||
{
|
|
||||||
// TextChannel channel = jda.getTextChannelById(song.getRequestedIn());
|
// TextChannel channel = jda.getTextChannelById(song.getRequestedIn());
|
||||||
// String bracketNo = "[" + song.getNumber() + "] ";
|
// String bracketNo = "[" + song.getNumber() + "] ";
|
||||||
if (ex == null)
|
if (ex == null)
|
||||||
if (song.getLocation() != null && song.getProgress() >= 100)
|
if (song.getLocation() != null && request.getProgress() >= 100)
|
||||||
{
|
|
||||||
response += ("Finished downloading " + song + ", added to queue!");
|
|
||||||
log("DOWN", "Downloaded " + song);
|
|
||||||
} else
|
|
||||||
{
|
|
||||||
Format format = song.getBestFormat();
|
|
||||||
String formatDetails = "";
|
|
||||||
if (format != null)
|
|
||||||
{
|
|
||||||
final int bitrate = format.getSampleRate() / 1000;
|
|
||||||
final long size = format.getSize();
|
|
||||||
String sizeFmt = (size <= 0 ? "?.??" : String.format("%.2f", size / (1024.0 * 1024.0))) + "MiB";
|
|
||||||
String bitFmt = (bitrate <= 0 ? "??" : bitrate) + "k";
|
|
||||||
formatDetails = " (" + bitFmt + ", " + sizeFmt + ")";
|
|
||||||
}
|
|
||||||
|
|
||||||
String progressDetails = "";
|
|
||||||
if (song.getProgress() >= 0)
|
|
||||||
progressDetails = " [" + String.format("%.1f", song.getProgress()) + "%]";
|
|
||||||
|
|
||||||
response += ("Now downloading " + song + formatDetails + progressDetails + " ...");
|
|
||||||
log("DOWN", "Downloading " + song + "...");
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
{
|
||||||
response += ("Failed to download " + song + "! Reason: " + ex.getMessage());
|
request.getInvocation().respond("Finished downloading " + song + ", added to queue!");
|
||||||
log("DOWN", "Failed to download " + song + "! Reason: " + ex.getMessage());
|
log("DOWN", "Downloaded " + song);
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
Format format = song.getBestFormat();
|
||||||
|
String formatDetails = "";
|
||||||
|
if (format != null)
|
||||||
|
{
|
||||||
|
final int bitrate = format.getSampleRate() / 1000;
|
||||||
|
final long size = format.getSize();
|
||||||
|
String sizeFmt = (size <= 0 ? "?.??" : String.format("%.2f", size / (1024.0 * 1024.0))) + "MiB";
|
||||||
|
String bitFmt = (bitrate <= 0 ? "??" : bitrate) + "k";
|
||||||
|
formatDetails = " (" + bitFmt + ", " + sizeFmt + ")";
|
||||||
|
}
|
||||||
|
String progressDetails = "";
|
||||||
|
if (request.getProgress() >= 0)
|
||||||
|
{
|
||||||
|
progressDetails = " [" + String.format("%.1f", request.getProgress()) + "%]";
|
||||||
|
}
|
||||||
|
request.getInvocation().respond("Now downloading " + song + formatDetails + progressDetails + " ...");
|
||||||
|
log("DOWN", "Downloading " + song + "...");
|
||||||
}
|
}
|
||||||
response += "\n";
|
else
|
||||||
|
{
|
||||||
|
request.getInvocation().respond("Failed to download " + song + "! Reason: " + ex.getMessage());
|
||||||
|
log("DOWN", "Failed to download " + song + "! Reason: " + ex.getMessage());
|
||||||
}
|
}
|
||||||
if (!response.isEmpty())
|
|
||||||
request.getInvocation().respond(response);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -8,11 +8,15 @@ package moe.nekojimi.chords;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.io.StringReader;
|
|
||||||
import java.nio.charset.Charset;
|
import java.nio.charset.Charset;
|
||||||
import java.nio.file.Files;
|
import java.nio.file.Files;
|
||||||
import java.util.*;
|
import java.util.ArrayList;
|
||||||
import java.util.concurrent.*;
|
import java.util.LinkedList;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Scanner;
|
||||||
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
|
import java.util.concurrent.ThreadPoolExecutor;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
|
@ -35,7 +39,7 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
{
|
{
|
||||||
|
|
||||||
private static final int DOWNLOAD_TIMEOUT = 300;
|
private static final int DOWNLOAD_TIMEOUT = 300;
|
||||||
private static final int INFO_TIMEOUT = 60;
|
private static final int INFO_TIMEOUT = 30;
|
||||||
private static final int FORMAT_TIMEOUT = 5;
|
private static final int FORMAT_TIMEOUT = 5;
|
||||||
|
|
||||||
private static final int BITRATE_TARGET = (int) AudioSendHandler.INPUT_FORMAT.getSampleRate();
|
private static final int BITRATE_TARGET = (int) AudioSendHandler.INPUT_FORMAT.getSampleRate();
|
||||||
|
@ -43,19 +47,15 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
public static final Pattern DESTINATION_PATTERN = Pattern.compile("Destination: (.*\\.wav)");
|
public static final Pattern DESTINATION_PATTERN = Pattern.compile("Destination: (.*\\.wav)");
|
||||||
public static final Pattern PROGRESS_PATTERN = Pattern.compile("\\[download\\].*?([\\d\\.]+)%");
|
public static final Pattern PROGRESS_PATTERN = Pattern.compile("\\[download\\].*?([\\d\\.]+)%");
|
||||||
private static final Pattern ETA_PATTERN = Pattern.compile("\\[download\\].*?ETA\\s+(\\d{1,2}:\\d{2})");
|
private static final Pattern ETA_PATTERN = Pattern.compile("\\[download\\].*?ETA\\s+(\\d{1,2}:\\d{2})");
|
||||||
private static final Pattern DOWNLOAD_ITEM_PATTERN = Pattern.compile("\\[download\\] Downloading item (\\d+) of (\\d+)");
|
|
||||||
|
|
||||||
private final List<DownloadTask> downloadQueue = new LinkedList<>();
|
private final List<DownloadTask> downloadQueue = new LinkedList<>();
|
||||||
private final LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<>();
|
private final LinkedBlockingDeque<Runnable> workQueue = new LinkedBlockingDeque<>();
|
||||||
private final ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 4, 30, TimeUnit.SECONDS, workQueue);
|
private final ThreadPoolExecutor executor = new ThreadPoolExecutor(2, 4, 30, TimeUnit.SECONDS, workQueue);
|
||||||
private final ScheduledExecutorService scheduler = new ScheduledThreadPoolExecutor(1);
|
|
||||||
// private Consumer<Song> next;
|
// private Consumer<Song> next;
|
||||||
private BiConsumer<SongRequest, Exception> messageHandler;
|
private BiConsumer<SongRequest, Exception> messageHandler;
|
||||||
|
|
||||||
private File downloadDir = null;
|
private File downloadDir = null;
|
||||||
|
|
||||||
private int trackNumber = 1;
|
|
||||||
|
|
||||||
public Downloader()
|
public Downloader()
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -64,22 +64,21 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
@Override
|
@Override
|
||||||
public void accept(DownloadTask task)
|
public void accept(DownloadTask task)
|
||||||
{
|
{
|
||||||
// if all songs of the request are already downloaded, just skip
|
// if already downloaded, just skip
|
||||||
if (!task.request.getSongs().isEmpty() && task.request.getSongs().stream().allMatch((t) -> t.isDownloaded()))
|
Song song = task.request.getSong();
|
||||||
|
if (song.isDownloaded())
|
||||||
{
|
{
|
||||||
for (Song song : task.request.getSongs())
|
task.getDestination().accept(song);
|
||||||
task.getDestination().accept(song);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
downloadQueue.add(task);
|
downloadQueue.add(task);
|
||||||
getInfo(task.request);
|
getInfo(song);
|
||||||
// TODO: get info should also use the thread pool
|
|
||||||
executor.submit(() ->
|
executor.submit(() ->
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
// getFormats(song);
|
getFormats(song);
|
||||||
download(task);
|
download(task);
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
|
@ -88,9 +87,11 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Format> sortFormats(Collection<Format> input)
|
private void chooseFormats(Song song)
|
||||||
{
|
{
|
||||||
List<Format> formats = new ArrayList<>(input);
|
List<Format> formats = song.getFormats();
|
||||||
|
if (formats.isEmpty())
|
||||||
|
return;
|
||||||
formats.sort((Format a, Format b) ->
|
formats.sort((Format a, Format b) ->
|
||||||
{
|
{
|
||||||
// audio only preferred to video
|
// audio only preferred to video
|
||||||
|
@ -126,7 +127,7 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
}
|
}
|
||||||
return -comp;
|
return -comp;
|
||||||
});
|
});
|
||||||
return formats;
|
song.setFormats(formats);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void getFormats(Song song)
|
private void getFormats(Song song)
|
||||||
|
@ -204,52 +205,36 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private List<Song> getInfo(SongRequest request)
|
private void getInfo(Song song)
|
||||||
{
|
{
|
||||||
List<Song> ret = new ArrayList<>();
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
String cmd = Chords.getSettings().getYtdlCommand() + " --skip-download --print-json " + request.getUrl().toString();
|
String cmd = Chords.getSettings().getYtdlCommand() + " --skip-download --print-json " + song.getUrl().toString();
|
||||||
Process exec = runCommand(cmd, INFO_TIMEOUT);
|
Process exec = runCommand(cmd, INFO_TIMEOUT);
|
||||||
InputStream input = exec.getInputStream();
|
InputStream input = exec.getInputStream();
|
||||||
|
JsonReader reader = Json.createReader(input);
|
||||||
|
JsonObject object = reader.readObject();
|
||||||
|
if (song.getTitle() == null)
|
||||||
|
song.setTitle(object.getString("title", null));
|
||||||
|
if (song.getArtist() == null)
|
||||||
|
song.setArtist(object.getString("uploader", null));
|
||||||
|
|
||||||
// read each line as JSON, turn each into a song object
|
JsonArray formatsJSON = object.getJsonArray("formats");
|
||||||
Scanner sc = new Scanner(input);
|
if (formatsJSON != null)
|
||||||
while (sc.hasNextLine())
|
|
||||||
{
|
{
|
||||||
Song song = new Song(request.getUrl());
|
List<Format> formats = new ArrayList<>();
|
||||||
song.setNumber(trackNumber);
|
for (JsonObject formatJson : formatsJSON.getValuesAs(JsonObject.class))
|
||||||
trackNumber++;
|
|
||||||
request.addSong(song);
|
|
||||||
|
|
||||||
String line = sc.nextLine();
|
|
||||||
JsonReader reader = Json.createReader(new StringReader(line));
|
|
||||||
JsonObject object = reader.readObject();
|
|
||||||
if (song.getTitle() == null)
|
|
||||||
song.setTitle(object.getString("title", null));
|
|
||||||
if (song.getArtist() == null)
|
|
||||||
song.setArtist(object.getString("uploader", null));
|
|
||||||
|
|
||||||
JsonArray formatsJSON = object.getJsonArray("formats");
|
|
||||||
if (formatsJSON != null)
|
|
||||||
{
|
{
|
||||||
List<Format> formats = new ArrayList<>();
|
Format format = Format.fromJSON(formatJson);
|
||||||
for (JsonObject formatJson : formatsJSON.getValuesAs(JsonObject.class))
|
if (format != null)
|
||||||
{
|
formats.add(format);
|
||||||
Format format = Format.fromJSON(formatJson);
|
|
||||||
if (format != null)
|
|
||||||
formats.add(format);
|
|
||||||
}
|
|
||||||
song.setFormats(formats);
|
|
||||||
}
|
}
|
||||||
|
song.setFormats(formats);
|
||||||
ret.add(song);
|
|
||||||
}
|
}
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
{
|
{
|
||||||
Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, null, ex);
|
Logger.getLogger(Downloader.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
}
|
}
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private File getDownloadDir() throws IOException
|
private File getDownloadDir() throws IOException
|
||||||
|
@ -259,35 +244,15 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
return downloadDir;
|
return downloadDir;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Song getSongFromRequest(SongRequest request, int idx)
|
|
||||||
{
|
|
||||||
// if there's less songs in the request than expected, fill the array
|
|
||||||
while (idx >= request.getSongs().size())
|
|
||||||
{
|
|
||||||
Song song = new Song(request.getUrl());
|
|
||||||
song.setNumber(trackNumber);
|
|
||||||
trackNumber++;
|
|
||||||
request.addSong(song);
|
|
||||||
}
|
|
||||||
return request.getSongs().get(idx);
|
|
||||||
}
|
|
||||||
|
|
||||||
private void download(DownloadTask task)
|
private void download(DownloadTask task)
|
||||||
{
|
{
|
||||||
Set<Format> uniqueFormats = new HashSet<>();
|
Song song = task.request.getSong();
|
||||||
for (Song song : task.request.getSongs())
|
chooseFormats(song);
|
||||||
{
|
|
||||||
uniqueFormats.addAll(song.getFormats());
|
|
||||||
}
|
|
||||||
|
|
||||||
List<Format> sortedFormats = sortFormats(uniqueFormats);
|
|
||||||
String formatCodes = "";
|
String formatCodes = "";
|
||||||
final List<Format> formats = sortedFormats;
|
final List<Format> formats = song.getFormats();
|
||||||
for (int i = 0; i < 5 && i < sortedFormats.size(); i++)
|
for (int i = 0; i < 3 && i < song.getFormats().size(); i++)
|
||||||
formatCodes += formats.get(i).getCode() + "/";
|
formatCodes += formats.get(i).getCode() + "/";
|
||||||
|
|
||||||
int downloadIdx = 0;
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
messageHandler.accept(task.request, null);
|
messageHandler.accept(task.request, null);
|
||||||
|
@ -298,7 +263,7 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
+ " --no-playlist"
|
+ " --no-playlist"
|
||||||
+ " --extractor-args youtube:player_client=android"
|
+ " --extractor-args youtube:player_client=android"
|
||||||
+ " -o " + getDownloadDir().getAbsolutePath() + "/%(title)s.%(ext)s "
|
+ " -o " + getDownloadDir().getAbsolutePath() + "/%(title)s.%(ext)s "
|
||||||
+ task.request.getUrl().toString();
|
+ song.getUrl().toString();
|
||||||
|
|
||||||
Process exec = runCommand(cmd, DOWNLOAD_TIMEOUT);
|
Process exec = runCommand(cmd, DOWNLOAD_TIMEOUT);
|
||||||
InputStream in = exec.getInputStream();
|
InputStream in = exec.getInputStream();
|
||||||
|
@ -309,47 +274,30 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
String line = sc.nextLine();
|
String line = sc.nextLine();
|
||||||
System.out.println(line);
|
System.out.println(line);
|
||||||
|
|
||||||
Matcher itemMatcher = DOWNLOAD_ITEM_PATTERN.matcher(line);
|
|
||||||
if (itemMatcher.find())
|
|
||||||
{
|
|
||||||
int idx = Integer.parseInt(itemMatcher.group(1)) - 1;
|
|
||||||
int total = Integer.parseInt(cmd);
|
|
||||||
|
|
||||||
downloadIdx = idx;
|
|
||||||
}
|
|
||||||
|
|
||||||
Matcher progMatcher = PROGRESS_PATTERN.matcher(line);
|
Matcher progMatcher = PROGRESS_PATTERN.matcher(line);
|
||||||
if (progMatcher.find())
|
if (progMatcher.find())
|
||||||
{
|
{
|
||||||
getSongFromRequest(task.request, downloadIdx).setProgress(Double.parseDouble(progMatcher.group(1)));
|
task.request.setProgress(Double.parseDouble(progMatcher.group(1)));
|
||||||
messageHandler.accept(task.request, null);
|
messageHandler.accept(task.request, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
Matcher destMatcher = DESTINATION_PATTERN.matcher(line);
|
Matcher destMatcher = DESTINATION_PATTERN.matcher(line);
|
||||||
if (destMatcher.find())
|
if (destMatcher.find())
|
||||||
{
|
|
||||||
Song song = getSongFromRequest(task.request, downloadIdx);
|
|
||||||
|
|
||||||
song.setLocation(new File(destMatcher.group(1)));
|
song.setLocation(new File(destMatcher.group(1)));
|
||||||
|
|
||||||
// this is currently our criteria for completion; submit the song and move on
|
|
||||||
if (task.getDestination() != null)
|
|
||||||
task.getDestination().accept(song);
|
|
||||||
|
|
||||||
downloadIdx++;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// String output = new String(in.readAllBytes(), Charset.defaultCharset());
|
// String output = new String(in.readAllBytes(), Charset.defaultCharset());
|
||||||
String error = new String(exec.getErrorStream().readAllBytes(), Charset.defaultCharset());
|
String error = new String(exec.getErrorStream().readAllBytes(), Charset.defaultCharset());
|
||||||
// System.out.println(output);
|
// System.out.println(output);
|
||||||
|
|
||||||
if (exec.exitValue() != 0)
|
if (exec.exitValue() != 0)
|
||||||
throw new RuntimeException("youtube-dl failed with error " + exec.exitValue() + ", output:\n" + error);
|
throw new RuntimeException("youtube-dl failed with error " + exec.exitValue() + ", output:\n" + error);
|
||||||
|
|
||||||
// task.request.setProgress(100);
|
task.request.setProgress(100);
|
||||||
// return true;
|
// return true;
|
||||||
|
|
||||||
|
if (task.getDestination() != null)
|
||||||
|
task.getDestination().accept(song);
|
||||||
downloadQueue.remove(task);
|
downloadQueue.remove(task);
|
||||||
messageHandler.accept(task.request, null);
|
messageHandler.accept(task.request, null);
|
||||||
} catch (Exception ex)
|
} catch (Exception ex)
|
||||||
|
@ -366,20 +314,12 @@ public class Downloader implements Consumer<DownloadTask>
|
||||||
System.out.println("Running command: " + cmd);
|
System.out.println("Running command: " + cmd);
|
||||||
// Process exec = Runtime.getRuntime().exec().split(" "));
|
// Process exec = Runtime.getRuntime().exec().split(" "));
|
||||||
Process exec = new ProcessBuilder(cmd.split(" ")).redirectOutput(ProcessBuilder.Redirect.PIPE).redirectError(ProcessBuilder.Redirect.PIPE).start();
|
Process exec = new ProcessBuilder(cmd.split(" ")).redirectOutput(ProcessBuilder.Redirect.PIPE).redirectError(ProcessBuilder.Redirect.PIPE).start();
|
||||||
scheduler.schedule(() ->
|
boolean done = exec.waitFor(timeoutSecs, TimeUnit.SECONDS);
|
||||||
|
if (!done)
|
||||||
{
|
{
|
||||||
if (exec.isAlive())
|
exec.destroyForcibly();
|
||||||
{
|
throw new RuntimeException("Took too long, giving up.");
|
||||||
exec.destroyForcibly();
|
}
|
||||||
System.err.println("Process " + cmd + " took too long, killing process.");
|
|
||||||
}
|
|
||||||
}, timeoutSecs, TimeUnit.SECONDS);
|
|
||||||
// boolean done = exec.waitFor(timeoutSecs, TimeUnit.SECONDS);
|
|
||||||
// if (!done)
|
|
||||||
// {
|
|
||||||
// exec.destroyForcibly();
|
|
||||||
// throw new RuntimeException("Took too long, giving up.");
|
|
||||||
// }
|
|
||||||
return exec;
|
return exec;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -7,7 +7,8 @@ package moe.nekojimi.chords;
|
||||||
|
|
||||||
import com.amihaiemil.eoyaml.Yaml;
|
import com.amihaiemil.eoyaml.Yaml;
|
||||||
import com.amihaiemil.eoyaml.YamlMapping;
|
import com.amihaiemil.eoyaml.YamlMapping;
|
||||||
import java.util.Objects;
|
import java.util.regex.Matcher;
|
||||||
|
import java.util.regex.Pattern;
|
||||||
import javax.json.JsonObject;
|
import javax.json.JsonObject;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -144,42 +145,4 @@ class Format
|
||||||
return "Format{" + "code=" + code + ", extension=" + extension + ", resolution=" + resolution + ", note=" + note + '}';
|
return "Format{" + "code=" + code + ", extension=" + extension + ", resolution=" + resolution + ", note=" + note + '}';
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int hashCode()
|
|
||||||
{
|
|
||||||
int hash = 7;
|
|
||||||
hash = 97 * hash + Objects.hashCode(this.extension);
|
|
||||||
hash = 97 * hash + Objects.hashCode(this.resolution);
|
|
||||||
hash = 97 * hash + (int) (this.size ^ (this.size >>> 32));
|
|
||||||
hash = 97 * hash + this.samplerate;
|
|
||||||
hash = 97 * hash + (this.audioOnly ? 1 : 0);
|
|
||||||
return hash;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean equals(Object obj)
|
|
||||||
{
|
|
||||||
if (this == obj)
|
|
||||||
return true;
|
|
||||||
if (obj == null)
|
|
||||||
return false;
|
|
||||||
if (getClass() != obj.getClass())
|
|
||||||
return false;
|
|
||||||
final Format other = (Format) obj;
|
|
||||||
if (this.size != other.size)
|
|
||||||
return false;
|
|
||||||
if (this.samplerate != other.samplerate)
|
|
||||||
return false;
|
|
||||||
if (this.audioOnly != other.audioOnly)
|
|
||||||
return false;
|
|
||||||
if (!Objects.equals(this.code, other.code))
|
|
||||||
return false;
|
|
||||||
if (!Objects.equals(this.extension, other.extension))
|
|
||||||
return false;
|
|
||||||
if (!Objects.equals(this.resolution, other.resolution))
|
|
||||||
return false;
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,13 +7,12 @@ package moe.nekojimi.chords;
|
||||||
|
|
||||||
import java.io.*;
|
import java.io.*;
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.logging.Level;
|
import java.util.logging.Level;
|
||||||
import java.util.logging.Logger;
|
import java.util.logging.Logger;
|
||||||
import javax.sound.sampled.*;
|
import javax.sound.sampled.*;
|
||||||
import net.dv8tion.jda.api.audio.AudioSendHandler;
|
import net.dv8tion.jda.api.audio.AudioSendHandler;
|
||||||
|
import org.apache.commons.io.input.buffer.CircularByteBuffer;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
@ -38,8 +37,7 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
}
|
}
|
||||||
|
|
||||||
private Song currentSong;
|
private Song currentSong;
|
||||||
// private TrackPlayer player;
|
private TrackPlayer player;
|
||||||
private final List<TrackPlayer> playingTracks = new ArrayList<>();
|
|
||||||
|
|
||||||
private File debugOutFile;
|
private File debugOutFile;
|
||||||
private BufferedOutputStream debugOut;
|
private BufferedOutputStream debugOut;
|
||||||
|
@ -69,11 +67,12 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
nextSong(true);
|
nextSong(true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void playOver(Song song)
|
// public boolean restartSong()
|
||||||
{
|
// {
|
||||||
|
//// songQueue.addFirst(currentSong);
|
||||||
}
|
// currentSong = null;
|
||||||
|
// return nextSong(true);
|
||||||
|
// }
|
||||||
|
|
||||||
private boolean nextSong()
|
private boolean nextSong()
|
||||||
{
|
{
|
||||||
|
@ -85,7 +84,8 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
if (immediate)
|
if (immediate)
|
||||||
{
|
{
|
||||||
System.out.println("Immediate next - clearing buffer");
|
System.out.println("Immediate next - clearing buffer");
|
||||||
playingTracks.clear();
|
player = null;
|
||||||
|
// audioBuffer.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
try
|
try
|
||||||
|
@ -108,8 +108,7 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
System.out.println("Playing song " + currentSong.getLocation().getAbsolutePath());
|
System.out.println("Playing song " + currentSong.getLocation().getAbsolutePath());
|
||||||
arrayErr = false;
|
arrayErr = false;
|
||||||
byteCount = 3840;
|
byteCount = 3840;
|
||||||
TrackPlayer player = new TrackPlayer(currentSong);
|
player = new TrackPlayer(currentSong);
|
||||||
playingTracks.add(player);
|
|
||||||
// System.out.println("Queue filled to " + audioBuffer.getCurrentNumberOfBytes());
|
// System.out.println("Queue filled to " + audioBuffer.getCurrentNumberOfBytes());
|
||||||
return true;
|
return true;
|
||||||
} catch (UnsupportedAudioFileException | IOException ex)
|
} catch (UnsupportedAudioFileException | IOException ex)
|
||||||
|
@ -123,7 +122,7 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
|
|
||||||
public boolean isPlaying()
|
public boolean isPlaying()
|
||||||
{
|
{
|
||||||
return !playingTracks.isEmpty();
|
return player != null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean isShouldPlay()
|
public boolean isShouldPlay()
|
||||||
|
@ -141,12 +140,7 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
@Override
|
@Override
|
||||||
public boolean canProvide()
|
public boolean canProvide()
|
||||||
{
|
{
|
||||||
if (playingTracks.isEmpty())
|
return player != null && player.has(1);
|
||||||
return false;
|
|
||||||
for (TrackPlayer player : playingTracks)
|
|
||||||
if (player.has(1))
|
|
||||||
return true;
|
|
||||||
return false;
|
|
||||||
// If we have something in our buffer we can provide it to the send system
|
// If we have something in our buffer we can provide it to the send system
|
||||||
// return audioBuffer.getCurrentNumberOfBytes() > byteCount && shouldPlay;
|
// return audioBuffer.getCurrentNumberOfBytes() > byteCount && shouldPlay;
|
||||||
}
|
}
|
||||||
|
@ -155,35 +149,27 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
public ByteBuffer provide20MsAudio()
|
public ByteBuffer provide20MsAudio()
|
||||||
{
|
{
|
||||||
ByteBuffer ret = ByteBuffer.allocate(byteCount);
|
ByteBuffer ret = ByteBuffer.allocate(byteCount);
|
||||||
while (ret.position() < byteCount && !playingTracks.isEmpty())
|
while (ret.position() < byteCount && player != null)
|
||||||
{
|
{
|
||||||
boolean outOfInput = true;
|
// System.out.println("Position: " + ret.position() + " Remaining: " + ret.remaining());
|
||||||
List<ByteBuffer> mixes = new ArrayList<>();
|
try
|
||||||
List<TrackPlayer> emptyPlayers = new ArrayList<>();
|
|
||||||
for (TrackPlayer player : playingTracks)
|
|
||||||
{
|
{
|
||||||
try
|
ByteBuffer read = player.read(ret.remaining());
|
||||||
{
|
// System.out.println("SAMPLES from player: " + Util.printSamples(read));
|
||||||
ByteBuffer read = player.read(ret.remaining());
|
// System.out.println("Wanted: " + byteCount + " Space:" + space + " Available: " + din.available() + " To read: " + bytesToRead + " Read: " + read);
|
||||||
if (ret.limit() + read.position() >= byteCount)
|
|
||||||
outOfInput = false;
|
// System.out.println("Read: " + read.remaining());
|
||||||
mixes.add(read);
|
ret.put(read);
|
||||||
// ret.put(read);
|
} catch (TrackPlayer.OutOfInputException | IOException ex)
|
||||||
} catch (TrackPlayer.OutOfInputException | IOException ex)
|
|
||||||
{
|
|
||||||
// System.out.println("Track player " + player + " stopped giving input: " + ex.getMessage());
|
|
||||||
emptyPlayers.add(player);
|
|
||||||
// System.out.println("Track ended, starting next.");
|
|
||||||
// outOfInput = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
playingTracks.removeAll(emptyPlayers);
|
|
||||||
ret.put(mixBuffers(mixes));
|
|
||||||
if (outOfInput)
|
|
||||||
{
|
{
|
||||||
|
// System.out.println("Track ended, starting next.");
|
||||||
boolean foundNext = nextSong();
|
boolean foundNext = nextSong();
|
||||||
|
|
||||||
if (!foundNext)
|
if (!foundNext)
|
||||||
|
{
|
||||||
|
// System.out.println("Out of tracks!");
|
||||||
break;
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -194,6 +180,56 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// private void fillBuffer(boolean canSkip)
|
||||||
|
// {
|
||||||
|
// // use what we have in our buffer to send audio as PCM
|
||||||
|
// while (audioBuffer.getCurrentNumberOfBytes() < DESIRED_BUFFER_SIZE)
|
||||||
|
// if (!readData())
|
||||||
|
// if (!canSkip || !nextSong())
|
||||||
|
// break;
|
||||||
|
// }
|
||||||
|
//
|
||||||
|
// private boolean readData()
|
||||||
|
// {
|
||||||
|
// if (din == null)
|
||||||
|
// return false;
|
||||||
|
// try
|
||||||
|
// {
|
||||||
|
// // if (din.available() == 0)
|
||||||
|
// // return false;
|
||||||
|
// int bytesToRead = DESIRED_BUFFER_SIZE - audioBuffer.getCurrentNumberOfBytes();
|
||||||
|
// int space = audioBuffer.getSpace();
|
||||||
|
// if (din.available() > 0 && din.available() < bytesToRead)
|
||||||
|
// bytesToRead = din.available();
|
||||||
|
// if (bytesToRead > space)
|
||||||
|
// bytesToRead = space;
|
||||||
|
// if (bytesToRead == 0)
|
||||||
|
// return false;
|
||||||
|
// byte[] bytes = new byte[bytesToRead];
|
||||||
|
// // byte[] bytes = din.readNBytes(bytesToRead);
|
||||||
|
// int read = din.read(bytes);
|
||||||
|
//// System.out.println("Wanted: " + byteCount + " Space:" + space + " Available: " + din.available() + " To read: " + bytesToRead + " Read: " + read);
|
||||||
|
// if (read < 0)
|
||||||
|
// return false;
|
||||||
|
//// queue.add(bytes);
|
||||||
|
//
|
||||||
|
// audioBuffer.add(bytes, 0, read);
|
||||||
|
// } catch (IOException ex)
|
||||||
|
// {
|
||||||
|
// Logger.getLogger(Chords.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
// return false;
|
||||||
|
// } catch (ArrayIndexOutOfBoundsException ex)
|
||||||
|
// {
|
||||||
|
// if (!arrayErr)
|
||||||
|
// arrayErr = true;
|
||||||
|
// else
|
||||||
|
// {
|
||||||
|
// Logger.getLogger(Chords.class.getName()).log(Level.SEVERE, null, ex);
|
||||||
|
// return false;
|
||||||
|
// }
|
||||||
|
// }
|
||||||
|
// return true;
|
||||||
|
// }
|
||||||
public Song getCurrentSong()
|
public Song getCurrentSong()
|
||||||
{
|
{
|
||||||
return currentSong;
|
return currentSong;
|
||||||
|
@ -210,38 +246,4 @@ public class MusicHandler implements AudioSendHandler, Closeable
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
private ByteBuffer mixBuffers(List<ByteBuffer> mixes)
|
|
||||||
{
|
|
||||||
// System.out.println("Mixing " + mixes.size() + " buffers");
|
|
||||||
if (mixes.size() == 1)
|
|
||||||
return mixes.get(0);
|
|
||||||
|
|
||||||
int maxSize = 0;
|
|
||||||
for (ByteBuffer buf : mixes)
|
|
||||||
{
|
|
||||||
if (buf.limit() > maxSize)
|
|
||||||
maxSize = buf.position();
|
|
||||||
}
|
|
||||||
ByteBuffer ret = ByteBuffer.allocate(maxSize);
|
|
||||||
|
|
||||||
for (int i = 0; i < ret.limit(); i++)
|
|
||||||
{
|
|
||||||
int byteTotal = 0;
|
|
||||||
int mixCount = 0;
|
|
||||||
for (ByteBuffer buf : mixes)
|
|
||||||
{
|
|
||||||
if (i < buf.limit())
|
|
||||||
{
|
|
||||||
byteTotal += buf.get(i);
|
|
||||||
mixCount++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
double avg = ((double) byteTotal) / mixCount;
|
|
||||||
byte byteVal = (byte) Math.round(avg);
|
|
||||||
ret.put(byteVal);
|
|
||||||
}
|
|
||||||
ret.rewind();
|
|
||||||
return ret;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,9 +16,7 @@
|
||||||
*/
|
*/
|
||||||
package moe.nekojimi.chords;
|
package moe.nekojimi.chords;
|
||||||
|
|
||||||
import java.util.Comparator;
|
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.PriorityQueue;
|
|
||||||
import java.util.Queue;
|
import java.util.Queue;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
|
@ -30,13 +28,13 @@ public class QueueManager implements Consumer<Song>
|
||||||
{
|
{
|
||||||
|
|
||||||
private Song restartingSong = null;
|
private Song restartingSong = null;
|
||||||
private final PriorityQueue<Song> jukeboxQueue = new PriorityQueue<>();
|
private final Queue<Song> jukeboxQueue;
|
||||||
private Playlist playlist;
|
private Playlist playlist;
|
||||||
private MusicHandler handler;
|
private MusicHandler handler;
|
||||||
|
|
||||||
public QueueManager()
|
public QueueManager()
|
||||||
{
|
{
|
||||||
// jukeboxQueue = new LinkedList<>();
|
jukeboxQueue = new LinkedList<>();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -19,7 +19,7 @@ import java.util.List;
|
||||||
*
|
*
|
||||||
* @author jimj316
|
* @author jimj316
|
||||||
*/
|
*/
|
||||||
public class Song implements Comparable<Song>
|
public class Song
|
||||||
{
|
{
|
||||||
private String title;
|
private String title;
|
||||||
private String artist;
|
private String artist;
|
||||||
|
@ -28,11 +28,10 @@ public class Song implements Comparable<Song>
|
||||||
private int number;
|
private int number;
|
||||||
private List<Format> formats = new ArrayList<>();
|
private List<Format> formats = new ArrayList<>();
|
||||||
|
|
||||||
|
private String requestedBy;
|
||||||
|
private String requestedIn;
|
||||||
private boolean kept = false;
|
private boolean kept = false;
|
||||||
|
|
||||||
private double progress = -1;
|
|
||||||
private double eta = -1;
|
|
||||||
|
|
||||||
public Song(URL url)
|
public Song(URL url)
|
||||||
{
|
{
|
||||||
this.url = url;
|
this.url = url;
|
||||||
|
@ -51,8 +50,8 @@ public class Song implements Comparable<Song>
|
||||||
.add("location", location.getAbsolutePath())
|
.add("location", location.getAbsolutePath())
|
||||||
.add("num", Integer.toString(number))
|
.add("num", Integer.toString(number))
|
||||||
.add("formats", build.build())
|
.add("formats", build.build())
|
||||||
// .add("requestedBy", requestedBy)
|
.add("requestedBy", requestedBy)
|
||||||
// .add("requestedIn", requestedIn)
|
.add("requestedIn", requestedIn)
|
||||||
.add("kept", Boolean.toString(kept))
|
.add("kept", Boolean.toString(kept))
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -65,8 +64,8 @@ public class Song implements Comparable<Song>
|
||||||
song.setLocation(new File(map.string("location")));
|
song.setLocation(new File(map.string("location")));
|
||||||
song.setNumber(map.integer("num"));
|
song.setNumber(map.integer("num"));
|
||||||
song.setKept(Boolean.parseBoolean(map.string("kept")));
|
song.setKept(Boolean.parseBoolean(map.string("kept")));
|
||||||
// song.setRequestedBy(map.string("requestedBy"));
|
song.setRequestedBy(map.string("requestedBy"));
|
||||||
// song.setRequestedIn(map.string("requestedIn"));
|
song.setRequestedIn(map.string("requestedIn"));
|
||||||
|
|
||||||
List<Format> formats = new ArrayList<>();
|
List<Format> formats = new ArrayList<>();
|
||||||
YamlSequence formatSeq = map.yamlSequence("formats");
|
YamlSequence formatSeq = map.yamlSequence("formats");
|
||||||
|
@ -134,6 +133,26 @@ public class Song implements Comparable<Song>
|
||||||
location = null;
|
location = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getRequestedBy()
|
||||||
|
{
|
||||||
|
return requestedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestedBy(String requestedBy)
|
||||||
|
{
|
||||||
|
this.requestedBy = requestedBy;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getRequestedIn()
|
||||||
|
{
|
||||||
|
return requestedIn;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRequestedIn(String requestedIn)
|
||||||
|
{
|
||||||
|
this.requestedIn = requestedIn;
|
||||||
|
}
|
||||||
|
|
||||||
public boolean isKept()
|
public boolean isKept()
|
||||||
{
|
{
|
||||||
return kept;
|
return kept;
|
||||||
|
@ -178,30 +197,4 @@ public class Song implements Comparable<Song>
|
||||||
return formats.get(0);
|
return formats.get(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public double getProgress()
|
|
||||||
{
|
|
||||||
return progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setProgress(double progress)
|
|
||||||
{
|
|
||||||
this.progress = progress;
|
|
||||||
}
|
|
||||||
|
|
||||||
public double getEta()
|
|
||||||
{
|
|
||||||
return eta;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setEta(double eta)
|
|
||||||
{
|
|
||||||
this.eta = eta;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compareTo(Song o)
|
|
||||||
{
|
|
||||||
return Integer.compare(number, o.number);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,6 @@
|
||||||
package moe.nekojimi.chords;
|
package moe.nekojimi.chords;
|
||||||
|
|
||||||
import java.net.URL;
|
import java.net.URL;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import moe.nekojimi.chords.commands.Invocation;
|
import moe.nekojimi.chords.commands.Invocation;
|
||||||
import moe.nekojimi.musicsearcher.Result;
|
import moe.nekojimi.musicsearcher.Result;
|
||||||
|
@ -37,10 +36,10 @@ public class SongRequest
|
||||||
|
|
||||||
private Result result;
|
private Result result;
|
||||||
|
|
||||||
private final List<Song> songs = new ArrayList<>();
|
private Song song;
|
||||||
|
|
||||||
private String requestedBy;
|
private double progress = -1;
|
||||||
private String requestedIn;
|
private double eta = -1;
|
||||||
|
|
||||||
|
|
||||||
public List<Result> getSearchResults()
|
public List<Result> getSearchResults()
|
||||||
|
@ -71,8 +70,6 @@ public class SongRequest
|
||||||
public void setInvocation(Invocation invocation)
|
public void setInvocation(Invocation invocation)
|
||||||
{
|
{
|
||||||
this.invocation = invocation;
|
this.invocation = invocation;
|
||||||
requestedBy = invocation.getRequestMessage().getAuthor().getName();
|
|
||||||
requestedIn = invocation.getRequestMessage().getChannel().getId();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// public Message getRequestMessage()
|
// public Message getRequestMessage()
|
||||||
|
@ -115,29 +112,34 @@ public class SongRequest
|
||||||
this.url = url;
|
this.url = url;
|
||||||
}
|
}
|
||||||
|
|
||||||
public List<Song> getSongs()
|
public Song getSong()
|
||||||
{
|
{
|
||||||
return songs;
|
return song;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addSong(Song song)
|
public void setSong(Song song)
|
||||||
{
|
{
|
||||||
songs.add(song);
|
this.song = song;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void clearSongs()
|
public double getProgress()
|
||||||
{
|
{
|
||||||
songs.clear();
|
return progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRequestedBy()
|
public void setProgress(double progress)
|
||||||
{
|
{
|
||||||
return requestedBy;
|
this.progress = progress;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getRequestedIn()
|
public double getEta()
|
||||||
{
|
{
|
||||||
return requestedIn;
|
return eta;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEta(double eta)
|
||||||
|
{
|
||||||
|
this.eta = eta;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,6 +16,7 @@ public abstract class Command
|
||||||
|
|
||||||
protected final Chords bot;
|
protected final Chords bot;
|
||||||
protected final String keyword;
|
protected final String keyword;
|
||||||
|
protected String documentation;
|
||||||
|
|
||||||
public Command(Chords bot, String keyword)
|
public Command(Chords bot, String keyword)
|
||||||
{
|
{
|
||||||
|
@ -30,8 +31,9 @@ public abstract class Command
|
||||||
return keyword;
|
return keyword;
|
||||||
}
|
}
|
||||||
|
|
||||||
// public abstract String synopsis();
|
public String getDocumentation()
|
||||||
//
|
{
|
||||||
// public abstract String help();
|
return documentation;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ package moe.nekojimi.chords.commands;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import net.dv8tion.jda.api.entities.Message;
|
import net.dv8tion.jda.api.entities.Message;
|
||||||
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
import net.dv8tion.jda.api.events.message.MessageReceivedEvent;
|
||||||
|
import net.dv8tion.jda.api.requests.restaction.MessageCreateAction;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
|
|
Loading…
Reference in New Issue