Skip to content

Commit

Permalink
2.8
Browse files Browse the repository at this point in the history
  • Loading branch information
MORIMORI0317 committed Feb 3, 2022
1 parent f7b9ba4 commit e29427a
Show file tree
Hide file tree
Showing 11 changed files with 74 additions and 36 deletions.
18 changes: 12 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -90,17 +90,18 @@ allprojects {
repositories {
maven { url = 'https://jitpack.io' }
jcenter()
mavenCentral()
}
}
dependencies {
minecraft "net.minecraftforge:forge:${mc_version}-${forge_version}"
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'
Expand All @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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=
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ public class URLNotStreamMusicPlayer implements IMusicPlayer {
protected final AudioDataFormat dataformat;
protected final AudioPlayer audioPlayer;
private final List<Integer> buffers = new ArrayList<>();
private final URL url;
protected final URL url;
protected boolean trackLoaded;
private long readyTime;
protected boolean stereo;
Expand All @@ -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();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down Expand Up @@ -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;
Expand Down
17 changes: 8 additions & 9 deletions src/main/java/red/felnull/imp/client/util/YoutubeUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,7 +12,7 @@
import java.util.*;

public class YoutubeUtils {

private static YoutubeDownloader youtubeDownloader = new YoutubeDownloader();
public static final Map<String, String> YOUTUBE_THUMBNAILURL = new HashMap<>();

public static List<AudioTrack> getVideoSearchResults(String searchText) {
Expand Down Expand Up @@ -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;
}
}
3 changes: 1 addition & 2 deletions src/main/java/red/felnull/imp/data/PlayMusicManeger.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/red/felnull/imp/lava/LavaPlayerPort.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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();
Expand All @@ -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) {
Expand All @@ -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)
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/red/felnull/imp/util/MusicUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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();
Expand Down
15 changes: 10 additions & 5 deletions version_check.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down

0 comments on commit e29427a

Please sign in to comment.