@ -1,30 +1,3 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* Project: Eight Track, File: DiscordGuild.java
|
|
||||||
*
|
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
|
||||||
* modified, duplicated, adapted or translated into another program language in any
|
|
||||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
|
||||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
|
||||||
* affirms that Eight-Track(R) software and data is subject to United States
|
|
||||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
|
||||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
|
||||||
*
|
|
||||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
||||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
|
||||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
|
||||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
|
||||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
|
||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
|
@ -1,30 +1,3 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* Project: Eight Track, File: GuildPlaylist.java
|
|
||||||
*
|
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
|
||||||
* modified, duplicated, adapted or translated into another program language in any
|
|
||||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
|
||||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
|
||||||
* affirms that Eight-Track(R) software and data is subject to United States
|
|
||||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
|
||||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
|
||||||
*
|
|
||||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
||||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
|
||||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
|
||||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
|
||||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
|
||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
|
@ -1,30 +1,3 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* Project: Eight Track, File: GuildPlaylistSong.java
|
|
||||||
*
|
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
|
||||||
* modified, duplicated, adapted or translated into another program language in any
|
|
||||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
|
||||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
|
||||||
* affirms that Eight-Track(R) software and data is subject to United States
|
|
||||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
|
||||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
|
||||||
*
|
|
||||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
||||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
|
||||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
|
||||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
|
||||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
|
||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
|
@ -1,30 +1,3 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* Project: Eight Track, File: GuildSong.java
|
|
||||||
*
|
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
|
||||||
* modified, duplicated, adapted or translated into another program language in any
|
|
||||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
|
||||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
|
||||||
* affirms that Eight-Track(R) software and data is subject to United States
|
|
||||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
|
||||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
|
||||||
*
|
|
||||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
||||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
|
||||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
|
||||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
|
||||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
|
||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
@ -67,6 +40,9 @@ public class GuildSong implements Serializable {
|
|||||||
@Basic(optional = false)
|
@Basic(optional = false)
|
||||||
@Column(name = "id")
|
@Column(name = "id")
|
||||||
private Long id;
|
private Long id;
|
||||||
|
@Basic(optional = false)
|
||||||
|
@Column(name = "uuid")
|
||||||
|
private String uuid;
|
||||||
@Column(name = "date_added")
|
@Column(name = "date_added")
|
||||||
@Temporal(TemporalType.TIMESTAMP)
|
@Temporal(TemporalType.TIMESTAMP)
|
||||||
private Date dateAdded;
|
private Date dateAdded;
|
||||||
@ -86,6 +62,11 @@ public class GuildSong implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public GuildSong(Long id, String uuid) {
|
||||||
|
this.id = id;
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public Long getId() {
|
public Long getId() {
|
||||||
return id;
|
return id;
|
||||||
}
|
}
|
||||||
@ -94,6 +75,14 @@ public class GuildSong implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public String getUuid() {
|
||||||
|
return uuid;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUuid(String uuid) {
|
||||||
|
this.uuid = uuid;
|
||||||
|
}
|
||||||
|
|
||||||
public Date getDateAdded() {
|
public Date getDateAdded() {
|
||||||
return dateAdded;
|
return dateAdded;
|
||||||
}
|
}
|
||||||
|
@ -1,30 +1,3 @@
|
|||||||
/**
|
|
||||||
*
|
|
||||||
* Project: Eight Track, File: Song.java
|
|
||||||
*
|
|
||||||
* Copyright 2019-2019 Locusworks LLC.
|
|
||||||
* All rights reserved. Federal copyright law prohibits unauthorized reproduction by
|
|
||||||
* any means and imposes fines up to $25,000 for violation. No part of this material
|
|
||||||
* may be reproduced, transmitted, transcribed, stored in a retrieval system, copied,
|
|
||||||
* modified, duplicated, adapted or translated into another program language in any
|
|
||||||
* form or by any means, electronic, mechanical, photocopying, recording, or
|
|
||||||
* otherwise, without the prior written permission from Locusworks. Locusworks
|
|
||||||
* affirms that Eight-Track(R) software and data is subject to United States
|
|
||||||
* Government Purpose Rights. Contact Locusworks, 1313 Lawnview Drive
|
|
||||||
* Forney TX 75126, (802) 488-0438, for commercial licensing opportunities.
|
|
||||||
*
|
|
||||||
* IN NO EVENT SHALL LOCUSWORKS BE LIABLE TO ANY PARTY FOR DIRECT, INDIRECT, SPECIAL,
|
|
||||||
* INCIDENTAL, OR CONSEQUENTIAL DAMAGES, INCLUDING LOST PROFITS, ARISING OUT
|
|
||||||
* OF THE USE OF THIS SOFTWARE AND ITS DOCUMENTATION, EVEN IF LOCUSWORKS HAS BEEN
|
|
||||||
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. NO RESPONSIBILITY IS ASSUMED BY
|
|
||||||
* LOCUSWORKS FOR ITS USE, OR FOR ANY INFRINGEMENTS OF PATENTS OR OTHER RIGHTS OF
|
|
||||||
* THIRD PARTIES RESULTING FROM ITS USE. LOCUSWORKS SPECIFICALLY DISCLAIMS ANY
|
|
||||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
|
||||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE SOFTWARE AND
|
|
||||||
* ACCOMPANYING DOCUMENTATION, IF ANY, PROVIDED HEREUNDER IS PROVIDED "AS
|
|
||||||
* IS". LOCUSWORKS HAS NO OBLIGATION TO PROVIDE MAINTENANCE, SUPPORT, UPDATES,
|
|
||||||
* ENHANCEMENTS, OR MODIFICATIONS.
|
|
||||||
*/
|
|
||||||
/*
|
/*
|
||||||
* To change this license header, choose License Headers in Project Properties.
|
* To change this license header, choose License Headers in Project Properties.
|
||||||
* To change this template file, choose Tools | Templates
|
* To change this template file, choose Tools | Templates
|
||||||
@ -67,9 +40,6 @@ public class Song implements Serializable {
|
|||||||
@Column(name = "id")
|
@Column(name = "id")
|
||||||
private Long id;
|
private Long id;
|
||||||
@Basic(optional = false)
|
@Basic(optional = false)
|
||||||
@Column(name = "uuid")
|
|
||||||
private String uuid;
|
|
||||||
@Basic(optional = false)
|
|
||||||
@Column(name = "title")
|
@Column(name = "title")
|
||||||
private String title;
|
private String title;
|
||||||
@Column(name = "artist")
|
@Column(name = "artist")
|
||||||
@ -105,9 +75,8 @@ public class Song implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Song(Long id, String uuid, String title, String filePath, String fileHash) {
|
public Song(Long id, String title, String filePath, String fileHash) {
|
||||||
this.id = id;
|
this.id = id;
|
||||||
this.uuid = uuid;
|
|
||||||
this.title = title;
|
this.title = title;
|
||||||
this.filePath = filePath;
|
this.filePath = filePath;
|
||||||
this.fileHash = fileHash;
|
this.fileHash = fileHash;
|
||||||
@ -121,14 +90,6 @@ public class Song implements Serializable {
|
|||||||
this.id = id;
|
this.id = id;
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getUuid() {
|
|
||||||
return uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public void setUuid(String uuid) {
|
|
||||||
this.uuid = uuid;
|
|
||||||
}
|
|
||||||
|
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
return title;
|
return title;
|
||||||
}
|
}
|
||||||
|
@ -38,6 +38,8 @@ import net.locusworks.discord.eighttrack.database.entities.Song;
|
|||||||
|
|
||||||
public interface GuildSongRepository extends CrudRepository<GuildSong, Long> {
|
public interface GuildSongRepository extends CrudRepository<GuildSong, Long> {
|
||||||
|
|
||||||
|
GuildSong findByUuid(String uuid);
|
||||||
|
|
||||||
GuildSong findByGuildAndSong(DiscordGuild guild, Song song);
|
GuildSong findByGuildAndSong(DiscordGuild guild, Song song);
|
||||||
|
|
||||||
@Query("SELECT gs FROM GuildSong gs WHERE gs.guild.guildId = ?1 AND gs.song.fileHash = ?2")
|
@Query("SELECT gs FROM GuildSong gs WHERE gs.guild.guildId = ?1 AND gs.song.fileHash = ?2")
|
||||||
|
@ -32,8 +32,6 @@ import net.locusworks.discord.eighttrack.database.entities.Song;
|
|||||||
|
|
||||||
public interface SongRepository extends CrudRepository<Song, Long> {
|
public interface SongRepository extends CrudRepository<Song, Long> {
|
||||||
|
|
||||||
Song findByUuid(String uuid);
|
|
||||||
|
|
||||||
Song findByFileHash(String fileHash);
|
Song findByFileHash(String fileHash);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -110,7 +110,8 @@ public class DiscordEventHandler extends ListenerAdapter {
|
|||||||
private void onGuildMessageReceivedHelper(GuildMessageReceivedEvent event) throws IOException {
|
private void onGuildMessageReceivedHelper(GuildMessageReceivedEvent event) throws IOException {
|
||||||
|
|
||||||
if (!musicService.containsKey(event.getGuild().getIdLong())) {
|
if (!musicService.containsKey(event.getGuild().getIdLong())) {
|
||||||
musicService.put(event.getGuild().getIdLong(), new GuildMusicHandler(musicDir, uploadHandler, guildSongRepoService));
|
musicService.put(event.getGuild().getIdLong(),
|
||||||
|
new GuildMusicHandler(musicDir, event.getGuild().getIdLong(), uploadHandler, guildSongRepoService));
|
||||||
}
|
}
|
||||||
GuildMusicHandler gmh = musicService.get(event.getGuild().getIdLong());
|
GuildMusicHandler gmh = musicService.get(event.getGuild().getIdLong());
|
||||||
gmh.accept((id) -> musicService.remove(id));
|
gmh.accept((id) -> musicService.remove(id));
|
||||||
@ -121,10 +122,6 @@ public class DiscordEventHandler extends ListenerAdapter {
|
|||||||
case "-upload":
|
case "-upload":
|
||||||
gmh.upload(event);
|
gmh.upload(event);
|
||||||
return;
|
return;
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
switch (command) {
|
|
||||||
case "-play":
|
case "-play":
|
||||||
gmh.isPlaying(true);
|
gmh.isPlaying(true);
|
||||||
gmh.play(event);
|
gmh.play(event);
|
||||||
@ -149,6 +146,5 @@ public class DiscordEventHandler extends ListenerAdapter {
|
|||||||
default:
|
default:
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -38,7 +38,6 @@ import java.util.List;
|
|||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.stream.Collectors;
|
|
||||||
|
|
||||||
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
import com.sedmelluq.discord.lavaplayer.player.AudioPlayer;
|
||||||
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager;
|
||||||
@ -78,14 +77,16 @@ public class GuildMusicHandler {
|
|||||||
private Consumer<Long> callback;
|
private Consumer<Long> callback;
|
||||||
private Mp3UploadHandler uploadHandler;
|
private Mp3UploadHandler uploadHandler;
|
||||||
private GuildSongRepoService guildSongRepoService;
|
private GuildSongRepoService guildSongRepoService;
|
||||||
|
private long guildId;
|
||||||
|
|
||||||
public GuildMusicHandler(Path musicDir, Mp3UploadHandler uploadHandler, GuildSongRepoService guildSongRepoService) throws IOException {
|
public GuildMusicHandler(Path musicDir, long guildId, Mp3UploadHandler uploadHandler, GuildSongRepoService guildSongRepoService) throws IOException {
|
||||||
this.logger = ApplicationLoggerFactory.getLogger(GuildMusicHandler.class);
|
this.logger = ApplicationLoggerFactory.getLogger(GuildMusicHandler.class);
|
||||||
this.playing = new AtomicBoolean(false);
|
this.playing = new AtomicBoolean(false);
|
||||||
this.musicDir = musicDir;
|
this.musicDir = musicDir;
|
||||||
this.lastPlayed = OffsetDateTime.now();
|
this.lastPlayed = OffsetDateTime.now();
|
||||||
this.uploadHandler = uploadHandler;
|
this.uploadHandler = uploadHandler;
|
||||||
this.guildSongRepoService = guildSongRepoService;
|
this.guildSongRepoService = guildSongRepoService;
|
||||||
|
this.guildId = guildId;
|
||||||
this.apm = new DefaultAudioPlayerManager();
|
this.apm = new DefaultAudioPlayerManager();
|
||||||
|
|
||||||
AudioSourceManagers.registerLocalSource(apm);
|
AudioSourceManagers.registerLocalSource(apm);
|
||||||
@ -93,6 +94,7 @@ public class GuildMusicHandler {
|
|||||||
|
|
||||||
this.ts = new TrackScheduler();
|
this.ts = new TrackScheduler();
|
||||||
player.addListener(ts);
|
player.addListener(ts);
|
||||||
|
indexFiles();
|
||||||
}
|
}
|
||||||
|
|
||||||
public OffsetDateTime getLastPlayed() {
|
public OffsetDateTime getLastPlayed() {
|
||||||
@ -108,18 +110,16 @@ public class GuildMusicHandler {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void indexFiles() throws IOException {
|
public void indexFiles() throws IOException {
|
||||||
List<Path> songs = Files.walk(musicDir)
|
List<GuildSong> songs = guildSongRepoService.getGuildSongRepo().findByGuild(guildId);
|
||||||
.filter(p-> p.getFileName().toString().endsWith(".mp3"))
|
|
||||||
.collect(Collectors.toList());
|
|
||||||
|
|
||||||
logger.info("Adding %d songs from directory %s", songs.size(), musicDir);
|
logger.info("Adding %d songs from directory %s", songs.size(), musicDir);
|
||||||
|
|
||||||
for (Path song : songs) {
|
for (GuildSong song : songs) {
|
||||||
logger.debug("Loading song: %s", song);
|
logger.debug("Loading song: %s", song.getSong().getFilePath());
|
||||||
try {
|
try {
|
||||||
apm.loadItem(song.toAbsolutePath().toString(), ts);
|
apm.loadItem(song.getSong().getFilePath(), ts);
|
||||||
} catch (IllegalStateException ex) {
|
} catch (IllegalStateException ex) {
|
||||||
logger.warn("Unable to load song :%s -> %s", song.toAbsolutePath().toString(), ex.getMessage());
|
logger.warn("Unable to load song :%s -> %s", song.getSong().getFilePath(), ex.getMessage());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -222,28 +222,56 @@ public class GuildMusicHandler {
|
|||||||
for(Attachment attachment : event.getMessage().getAttachments()) {
|
for(Attachment attachment : event.getMessage().getAttachments()) {
|
||||||
attachment.retrieveInputStream().thenAccept((in) -> {
|
attachment.retrieveInputStream().thenAccept((in) -> {
|
||||||
Mp3UploadResults res = null;
|
Mp3UploadResults res = null;
|
||||||
try {
|
|
||||||
MessageEmbed embed = null;
|
MessageEmbed embed = null;
|
||||||
|
try {
|
||||||
|
|
||||||
res = uploadHandler.parse(in);
|
res = uploadHandler.parse(in);
|
||||||
if (res.validFile()) {
|
if (res.validFile()) {
|
||||||
embed =persistSong(res, event, attachment.getFileName());
|
embed = persistSong(res, event, attachment.getFileName());
|
||||||
|
} else {
|
||||||
|
embed = wrongFile(event, attachment.getFileName());
|
||||||
}
|
}
|
||||||
|
|
||||||
event.getChannel().sendMessage(embed).queue();
|
|
||||||
} catch (Exception ex) {
|
} catch (Exception ex) {
|
||||||
logger.error("Unable to get file information: %s", ex.getMessage());
|
logger.error("Unable to get file information: %s", ex.getMessage());
|
||||||
logger.error(ex);
|
logger.error(ex);
|
||||||
|
embed = error(event, ex, attachment.getFileName());
|
||||||
} finally {
|
} finally {
|
||||||
event.getMessage().delete().queue();
|
event.getMessage().delete().queue();
|
||||||
if (res != null) res.clear();
|
if (res != null) res.clear();
|
||||||
|
|
||||||
|
if (embed != null) event.getChannel().sendMessage(embed).queue();
|
||||||
}
|
}
|
||||||
|
|
||||||
}).exceptionally((err) ->{
|
}).exceptionally((err) -> {
|
||||||
|
event.getMessage().delete().queue();
|
||||||
|
MessageEmbed embed = error(event, err, attachment.getFileName());
|
||||||
|
if (embed != null) event.getChannel().sendMessage(embed).queue();
|
||||||
return null;
|
return null;
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private MessageEmbed error(GuildMessageReceivedEvent event, Throwable ex, String fileName) {
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setTitle("Unable to upload file: " + fileName)
|
||||||
|
.setDescription("There was an error uploading your file: " + ex.getMessage() + ". Please contact admin")
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
|
private MessageEmbed wrongFile(GuildMessageReceivedEvent event, String fileName) {
|
||||||
|
return new EmbedBuilder()
|
||||||
|
.setTitle("Invalid File: " + fileName)
|
||||||
|
.setDescription("Only music type files are allowed to be uploaded")
|
||||||
|
.setColor(Color.RED)
|
||||||
|
.setTimestamp(OffsetDateTime.now())
|
||||||
|
.setFooter(event.getGuild().getSelfMember().getEffectiveName(), event.getGuild().getSelfMember().getUser().getAvatarUrl())
|
||||||
|
.build();
|
||||||
|
}
|
||||||
|
|
||||||
private MessageEmbed persistSong(Mp3UploadResults result, GuildMessageReceivedEvent event, String fileName) throws Exception {
|
private MessageEmbed persistSong(Mp3UploadResults result, GuildMessageReceivedEvent event, String fileName) throws Exception {
|
||||||
|
|
||||||
DiscordGuild guild = guildSongRepoService.getGuildRepo().findByGuildId(event.getGuild().getIdLong());
|
DiscordGuild guild = guildSongRepoService.getGuildRepo().findByGuildId(event.getGuild().getIdLong());
|
||||||
@ -279,7 +307,6 @@ public class GuildMusicHandler {
|
|||||||
song.setReleaseYear(result.getReleaseDate());
|
song.setReleaseYear(result.getReleaseDate());
|
||||||
song.setTitle(result.getTitle());
|
song.setTitle(result.getTitle());
|
||||||
song.setTrackNumber(result.getTrackNumber());
|
song.setTrackNumber(result.getTrackNumber());
|
||||||
song.setUuid(UUID.nameUUIDFromBytes(result.getData()).toString());
|
|
||||||
|
|
||||||
guildSongRepoService.getSongRepo().save(song);
|
guildSongRepoService.getSongRepo().save(song);
|
||||||
|
|
||||||
@ -287,10 +314,11 @@ public class GuildMusicHandler {
|
|||||||
gs.setDateAdded(new Date());
|
gs.setDateAdded(new Date());
|
||||||
gs.setGuild(guild);
|
gs.setGuild(guild);
|
||||||
gs.setSong(song);
|
gs.setSong(song);
|
||||||
|
gs.setUuid(UUID.randomUUID().toString());
|
||||||
|
|
||||||
guildSongRepoService.getGuildSongRepo().save(gs);
|
guildSongRepoService.getGuildSongRepo().save(gs);
|
||||||
|
|
||||||
String out = String.format("```%s%n%-10s: %s```", result, "UUID", song.getUuid());
|
String out = String.format("```%s%n%-10s: %s```", result, "UUID", gs.getUuid());
|
||||||
|
|
||||||
MessageEmbed embed = new EmbedBuilder()
|
MessageEmbed embed = new EmbedBuilder()
|
||||||
.setColor(Color.GREEN)
|
.setColor(Color.GREEN)
|
||||||
|
@ -9,7 +9,6 @@ CREATE TABLE eighttrack.discord_guild (
|
|||||||
|
|
||||||
CREATE TABLE eighttrack.song (
|
CREATE TABLE eighttrack.song (
|
||||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
|
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'Primary Key',
|
||||||
uuid varchar(100) NOT NULL COMMENT 'Unique Identifier',
|
|
||||||
title varchar(500) NOT NULL COMMENT 'title of song',
|
title varchar(500) NOT NULL COMMENT 'title of song',
|
||||||
artist varchar(500) DEFAULT NULL COMMENT 'songs artist',
|
artist varchar(500) DEFAULT NULL COMMENT 'songs artist',
|
||||||
album varchar(500) DEFAULT NULL COMMENT 'songs album',
|
album varchar(500) DEFAULT NULL COMMENT 'songs album',
|
||||||
@ -22,17 +21,18 @@ CREATE TABLE eighttrack.song (
|
|||||||
file_hash varchar(40) NOT NULL COMMENT 'sha1 hash of file',
|
file_hash varchar(40) NOT NULL COMMENT 'sha1 hash of file',
|
||||||
date_added timestamp NULL DEFAULT NULL,
|
date_added timestamp NULL DEFAULT NULL,
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
UNIQUE KEY song_uuid_UN (uuid),
|
|
||||||
UNIQUE KEY song_file_hash_UN (file_hash)
|
UNIQUE KEY song_file_hash_UN (file_hash)
|
||||||
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
|
||||||
|
|
||||||
CREATE TABLE eighttrack.guild_song (
|
CREATE TABLE eighttrack.guild_song (
|
||||||
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
id bigint(20) NOT NULL AUTO_INCREMENT COMMENT 'primary key',
|
||||||
|
uuid varchar(100) NOT NULL COMMENT 'Unique Identifier',
|
||||||
guild bigint(20) NOT NULL COMMENT 'guild the song belongs to',
|
guild bigint(20) NOT NULL COMMENT 'guild the song belongs to',
|
||||||
song bigint(20) NOT NULL COMMENT 'the song',
|
song bigint(20) NOT NULL COMMENT 'the song',
|
||||||
date_added timestamp NULL DEFAULT NULL COMMENT 'date added',
|
date_added timestamp NULL DEFAULT NULL COMMENT 'date added',
|
||||||
PRIMARY KEY (id),
|
PRIMARY KEY (id),
|
||||||
UNIQUE KEY guild_song_UN (guild,song),
|
UNIQUE KEY guild_song_UN (guild,song),
|
||||||
|
UNIQUE KEY guild_song_UN2 (uuid),
|
||||||
KEY guild_song_FK_1 (song),
|
KEY guild_song_FK_1 (song),
|
||||||
CONSTRAINT guild_song_FK FOREIGN KEY (guild) REFERENCES eighttrack.discord_guild (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
CONSTRAINT guild_song_FK FOREIGN KEY (guild) REFERENCES eighttrack.discord_guild (id) ON DELETE CASCADE ON UPDATE CASCADE,
|
||||||
CONSTRAINT guild_song_FK_1 FOREIGN KEY (song) REFERENCES eighttrack.song (id) ON DELETE CASCADE ON UPDATE CASCADE
|
CONSTRAINT guild_song_FK_1 FOREIGN KEY (song) REFERENCES eighttrack.song (id) ON DELETE CASCADE ON UPDATE CASCADE
|
||||||
|
Reference in New Issue
Block a user