diff --git a/build.gradle b/build.gradle index 40587109..c0a27f89 100644 --- a/build.gradle +++ b/build.gradle @@ -90,6 +90,7 @@ allprojects { repositories { maven { url = 'https://jitpack.io' } jcenter() + mavenCentral() } } dependencies { @@ -97,10 +98,10 @@ dependencies { compileOnly fg.deobf("mezz.jei:jei-${jei_version}:api") runtimeOnly fg.deobf("mezz.jei:jei-${jei_version}") compile fg.deobf("red.felnull:otyacraftengine:${oe_version}") - shadowAll 'com.sedmelluq:lavaplayer:1.3.75' + shadowAll 'com.sedmelluq:lavaplayer:1.3.78' shadowAll 'org.apache.httpcomponents:httpclient:4.5.13' - shadowAll 'dev.felnull:felnull-java-library:1.8' - shadowAll 'com.github.sealedtx:java-youtube-downloader:2.4.3' + shadowAll 'dev.felnull:felnull-java-library:1.41' + shadowAll 'com.github.sealedtx:java-youtube-downloader:3.0.2' implementation 'com.madgag:animated-gif-lib:1.4'; } tasks.withType(AbstractCompile)*.options*.encoding = tasks.withType(GroovyCompile)*.groovyOptions*.encoding = 'UTF-8' @@ -120,9 +121,14 @@ shadowJar { relocate 'org.apache.http', 'red.felnull.imp.libs.org.apache.http' relocate 'com.alibaba.fastjson', 'red.felnull.imp.libs.com.alibaba.fastjson' relocate 'dev.felnull.fnjl', 'red.felnull.imp.libs.dev.felnull.fnjl' - relocate 'org.apache.commons.codec', 'red.felnull.imp.libs.org.apache.commons.codec' - relocate 'org.apache.commons.logging', 'red.felnull.imp.libs.org.apache.commons.logging' - relocate 'org.apache.commons.io', 'red.felnull.imp.libs.org.apache.commons.io' + relocate('org.apache.commons', 'dev.felnull.imp.libs.org.apache.commons') { + include 'org.apache.commons.logging.**' + include 'org.apache.commons.io.**' + include 'org.apache.commons.codec.**' + } + relocate ('com.sedmelluq.discord.lavaplayer', 'dev.felnull.imp.libs.com.sedmelluq.discord.lavaplayer'){ + exclude 'com.sedmelluq.discord.lavaplayer.natives.**' + } } afterEvaluate { diff --git a/gradle.properties b/gradle.properties index a6748849..514afed3 100644 --- a/gradle.properties +++ b/gradle.properties @@ -4,7 +4,7 @@ forge_mapping=20201028-1.16.3 forge_version=36.2.8 mod_name=IamMusicPlayer mod_group=red.felnull -mod_version=2.7 +mod_version=2.8 mod_changelog= mod_vendor=TeamFelNull mc_version=1.16.5 @@ -17,6 +17,6 @@ modrinth_id=ZHHXRhiU release_type=beta loader_type=Forge support_versions=1.16.5 -required_mods= +required_mods=otyacraft-engine optional_mods= embedded_mods= \ No newline at end of file diff --git a/src/main/java/red/felnull/imp/client/data/MusicSourceClientReferencesType.java b/src/main/java/red/felnull/imp/client/data/MusicSourceClientReferencesType.java index 6726486e..ddb0b4c0 100644 --- a/src/main/java/red/felnull/imp/client/data/MusicSourceClientReferencesType.java +++ b/src/main/java/red/felnull/imp/client/data/MusicSourceClientReferencesType.java @@ -15,7 +15,6 @@ import red.felnull.imp.music.resource.PlayMusic; import java.io.IOException; -import java.net.URL; import java.util.Arrays; public enum MusicSourceClientReferencesType { @@ -56,7 +55,7 @@ public IMusicPlayer getMusicPlayer(String src) throws YoutubeException, IOExcept case YOUTUBE: return new YoutubeMusicPlayer(rerytime, src, urlMusicLoader, youtubeMusicLoader); case URL: - return new URLNotStreamMusicPlayer(rerytime, new URL(src), urlMusicLoader); + return new URLNotStreamMusicPlayer(rerytime, src, urlMusicLoader); // case LOCAL_FILE: // return new WorldFileMusicPlayer(rerytime, src); default: diff --git a/src/main/java/red/felnull/imp/client/music/MusicRinger.java b/src/main/java/red/felnull/imp/client/music/MusicRinger.java index c3e19e31..1687151a 100644 --- a/src/main/java/red/felnull/imp/client/music/MusicRinger.java +++ b/src/main/java/red/felnull/imp/client/music/MusicRinger.java @@ -60,7 +60,7 @@ public void setVolume(float volume) { public void volumeUpdate() { if (musicPlayer != null) { float rarnge = 30f * volume; - float vol = SoundMath.calculateVolume(volume/5, ClientWorldMusicManager.instance().getEventuallyMusicVolume()); + float vol = SoundMath.calculateVolume(volume / 2f, ClientWorldMusicManager.instance().getEventuallyMusicVolume()); if (musicPlayer instanceof URLNotStreamMusicPlayer) { if (!((URLNotStreamMusicPlayer) musicPlayer).isSpatial()) vol = SoundMath.calculatePseudoAttenuation(getPosition(), rarnge, vol); diff --git a/src/main/java/red/felnull/imp/client/music/player/URLNotStreamMusicPlayer.java b/src/main/java/red/felnull/imp/client/music/player/URLNotStreamMusicPlayer.java index 04eb9b1d..a2ef6e56 100644 --- a/src/main/java/red/felnull/imp/client/music/player/URLNotStreamMusicPlayer.java +++ b/src/main/java/red/felnull/imp/client/music/player/URLNotStreamMusicPlayer.java @@ -28,7 +28,7 @@ public class URLNotStreamMusicPlayer implements IMusicPlayer { protected final AudioDataFormat dataformat; protected final AudioPlayer audioPlayer; private final List buffers = new ArrayList<>(); - private final URL url; + protected final URL url; protected boolean trackLoaded; private long readyTime; protected boolean stereo; @@ -46,8 +46,14 @@ public class URLNotStreamMusicPlayer implements IMusicPlayer { private int trig; protected boolean ready; - public URLNotStreamMusicPlayer(long readyTime, URL url, LavaMusicLoader loader) { - this.url = url; + public URLNotStreamMusicPlayer(long readyTime, String url, LavaMusicLoader loader) { + URL url1 = null; + try { + if (url != null) + url1 = new URL(url); + } catch (Exception ignored) { + } + this.url = url1; this.readyTime = readyTime; this.dataformat = loader.getFormat(); this.audioPlayerManager = loader.getAudioPlayerManager(); diff --git a/src/main/java/red/felnull/imp/client/music/player/YoutubeMusicPlayer.java b/src/main/java/red/felnull/imp/client/music/player/YoutubeMusicPlayer.java index 751589e5..8329bf02 100644 --- a/src/main/java/red/felnull/imp/client/music/player/YoutubeMusicPlayer.java +++ b/src/main/java/red/felnull/imp/client/music/player/YoutubeMusicPlayer.java @@ -10,20 +10,23 @@ import red.felnull.imp.client.util.YoutubeUtils; import java.io.IOException; -import java.net.URL; public class YoutubeMusicPlayer extends URLNotStreamMusicPlayer { private final LavaMusicLoader youtubeMusicLoader; private final String videoID; public YoutubeMusicPlayer(long rery, String videoID, LavaMusicLoader loader, LavaMusicLoader youtubeLoader) throws IOException, YoutubeException { - super(rery, new URL(YoutubeUtils.getYoutubeMa4DirectLink(videoID)), loader); + super(rery, YoutubeUtils.getYoutubeMa4DirectLink(videoID), loader); this.videoID = videoID; this.youtubeMusicLoader = youtubeLoader; } @Override public void ready(long position) throws Exception { + if (url != null) { + super.ready(position); + if (ready) return; + } startPosition = position; this.trackLoaded = false; youtubeMusicLoader.getAudioPlayerManager().loadItem(videoID, new AudioLoadResultHandler() { @@ -63,7 +66,6 @@ public void loadFailed(FriendlyException ex) { if (exception != null) { exception = null; trackLoaded = false; - super.ready(position); } else { stream = AudioPlayerInputStream.createStream(audioPlayer, dataformat, dataformat.frameDuration(), false); stereo = AudioDataFormatTools.toAudioFormat(dataformat).getChannels() >= 2; diff --git a/src/main/java/red/felnull/imp/client/util/YoutubeUtils.java b/src/main/java/red/felnull/imp/client/util/YoutubeUtils.java index bb9a3dbf..464ee0c6 100644 --- a/src/main/java/red/felnull/imp/client/util/YoutubeUtils.java +++ b/src/main/java/red/felnull/imp/client/util/YoutubeUtils.java @@ -1,9 +1,8 @@ package red.felnull.imp.client.util; import com.github.kiulian.downloader.YoutubeDownloader; -import com.github.kiulian.downloader.YoutubeException; -import com.github.kiulian.downloader.model.YoutubeVideo; -import com.github.kiulian.downloader.model.formats.AudioFormat; +import com.github.kiulian.downloader.downloader.request.RequestVideoInfo; +import com.github.kiulian.downloader.model.videos.VideoInfo; import com.sedmelluq.discord.lavaplayer.player.AudioLoadResultHandler; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; @@ -13,7 +12,7 @@ import java.util.*; public class YoutubeUtils { - + private static YoutubeDownloader youtubeDownloader = new YoutubeDownloader(); public static final Map YOUTUBE_THUMBNAILURL = new HashMap<>(); public static List getVideoSearchResults(String searchText) { @@ -69,10 +68,10 @@ public static String getYoutubeIDFromURL(String url) { return ur[ur.length - 1]; } - public static String getYoutubeMa4DirectLink(String videoID) throws YoutubeException { - YoutubeDownloader yd = new YoutubeDownloader(); - YoutubeVideo yv = yd.getVideo(videoID); - AudioFormat audioformat = yv.audioFormats().get(0); - return audioformat.url(); + public static String getYoutubeMa4DirectLink(String videoID) { + VideoInfo video = youtubeDownloader.getVideoInfo(new RequestVideoInfo(videoID)).data(); + if (video != null) + return video.bestAudioFormat().url(); + return null; } } diff --git a/src/main/java/red/felnull/imp/data/PlayMusicManeger.java b/src/main/java/red/felnull/imp/data/PlayMusicManeger.java index 939f8060..7224e6a4 100644 --- a/src/main/java/red/felnull/imp/data/PlayMusicManeger.java +++ b/src/main/java/red/felnull/imp/data/PlayMusicManeger.java @@ -5,7 +5,6 @@ import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import red.felnull.imp.client.data.MusicSourceClientReferencesType; -import red.felnull.imp.client.util.YoutubeUtils; import red.felnull.imp.handler.MusicReceiveHandler; import red.felnull.imp.music.resource.PlayImage; import red.felnull.imp.music.resource.PlayList; @@ -139,7 +138,7 @@ public void run() { } } else if (uploadtype == MusicSourceClientReferencesType.YOUTUBE) { try { - leth = MusicUtils.getMillisecondDuration(new URL(YoutubeUtils.getYoutubeMa4DirectLink(location.getIdOrURL()))); + leth = MusicUtils.getMillisecondDuration(location.getIdOrURL()); } catch (Exception ex) { ex.printStackTrace(); } diff --git a/src/main/java/red/felnull/imp/lava/LavaPlayerPort.java b/src/main/java/red/felnull/imp/lava/LavaPlayerPort.java index cfb9fb12..4fd88cd0 100644 --- a/src/main/java/red/felnull/imp/lava/LavaPlayerPort.java +++ b/src/main/java/red/felnull/imp/lava/LavaPlayerPort.java @@ -6,6 +6,7 @@ import com.sedmelluq.discord.lavaplayer.player.DefaultAudioPlayerManager; import com.sedmelluq.discord.lavaplayer.source.http.HttpAudioSourceManager; import com.sedmelluq.discord.lavaplayer.source.local.LocalAudioSourceManager; +import com.sedmelluq.discord.lavaplayer.source.youtube.YoutubeAudioSourceManager; import com.sedmelluq.discord.lavaplayer.tools.FriendlyException; import com.sedmelluq.discord.lavaplayer.track.AudioPlaylist; import com.sedmelluq.discord.lavaplayer.track.AudioTrack; @@ -18,6 +19,7 @@ public class LavaPlayerPort { private static AudioPlayerManager localAudioPlayerManager; private static AudioPlayerManager urlAudioPlayerManager; + private static AudioPlayerManager youtubeAudioPlayerManager; public static void init() { localAudioPlayerManager = new DefaultAudioPlayerManager(); @@ -27,6 +29,10 @@ public static void init() { urlAudioPlayerManager = new DefaultAudioPlayerManager(); managerInit(urlAudioPlayerManager); urlAudioPlayerManager.registerSourceManager(new HttpAudioSourceManager()); + + youtubeAudioPlayerManager = new DefaultAudioPlayerManager(); + managerInit(youtubeAudioPlayerManager); + youtubeAudioPlayerManager.registerSourceManager(new YoutubeAudioSourceManager()); } private static void managerInit(AudioPlayerManager audioPlayerManager) { @@ -41,6 +47,13 @@ public static boolean isSupport(String url) { return track != null && !track.getInfo().isStream; } + public static long getDurationByYoutube(String videoID) { + AudioTrack track = search(youtubeAudioPlayerManager, videoID); + if (track == null) + return 0; + return track.getInfo().length; + } + public static long getDuration(String url) { AudioTrack track = search(urlAudioPlayerManager, url); if (track == null) diff --git a/src/main/java/red/felnull/imp/util/MusicUtils.java b/src/main/java/red/felnull/imp/util/MusicUtils.java index 91829aaf..a9e46446 100644 --- a/src/main/java/red/felnull/imp/util/MusicUtils.java +++ b/src/main/java/red/felnull/imp/util/MusicUtils.java @@ -1,6 +1,6 @@ package red.felnull.imp.util; -import red.felnull.imp.exception.IMPFFmpegException; +import red.felnull.imp.client.util.YoutubeUtils; import red.felnull.imp.lava.LavaPlayerPort; import java.io.File; @@ -16,14 +16,23 @@ public class MusicUtils { public static float getMP3MillisecondPerFrame(File file) throws IOException, BitstreamException { return getMP3MillisecondPerFrame(new BufferedInputStream(new FileInputStream(file))); }*/ + public static long getMillisecondDuration(String videoID) { + try { + String url = YoutubeUtils.getYoutubeMa4DirectLink(videoID); + if (url != null) + return LavaPlayerPort.getDuration(url); + } catch (Exception ignored) { + } + return LavaPlayerPort.getDurationByYoutube(videoID); + } - public static long getMillisecondDuration(URL url) throws IMPFFmpegException { + public static long getMillisecondDuration(URL url) { return LavaPlayerPort.getDuration(url.toString()); // MultimediaObject mo = FFmpegUtils.createMultimediaObject(url); // return FFmpegUtils.getInfo(mo).getDuration(); } - public static long getMillisecondDuration(File file) throws IMPFFmpegException { + public static long getMillisecondDuration(File file) { return LavaPlayerPort.getDuration(file); // MultimediaObject mo = FFmpegUtils.createMultimediaObject(file); // return FFmpegUtils.getInfo(mo).getDuration(); diff --git a/version_check.json b/version_check.json index efb83e35..8e577ab2 100644 --- a/version_check.json +++ b/version_check.json @@ -1,15 +1,20 @@ { "homepage": "https://www.curseforge.com/minecraft/mc-mods/iammusicplayer", + "1.16.5": { + "2.8": "Added ru_ru language and update library version" + }, "1.16.1": { - "1.3": "-The 1.16.1 Frist,Quite unstable.", - "1.4": "-Fix forge106 Crash" + "1.3": "The 1.16.1 Frist,Quite unstable.", + "1.4": "Fix forge106 Crash" }, "1.15.2": { - "1.2": "-Resume music when boombox is stopped or broken\n-Simultaneously proceed downloading and listening\n-The One Probe is supported\n-Fix crash when Cassette Deck finishes recording on Mac or Linux", - "1.1": "-Name Change(Ikisugi Music Player -> Iam Music Player)\n-Other change iroiro.", - "1.0": "-The Frist Release." + "1.2": "Resume music when boombox is stopped or broken\n-Simultaneously proceed downloading and listening\n-The One Probe is supported\n-Fix crash when Cassette Deck finishes recording on Mac or Linux", + "1.1": "Name Change(Ikisugi Music Player -> Iam Music Player)\n-Other change iroiro.", + "1.0": "The Frist Release." }, "promos": { + "1.16.5-latest": "2.8", + "1.16.5-recommended": "2.8", "1.16.1-latest": "1.4", "1.16.1-recommended": "1.4", "1.15.2-latest": "1.2",