Skip to content

Commit

Permalink
・ニコニコ動画のプレミアムアカウントで動画を再生できない不具合を修正
Browse files Browse the repository at this point in the history
・再生が終了したニコニコ動画のセッションが残り続ける不具合を修正
・ニコニコ動画をプレミアムアカウントでリクエストした際は高音質音声をリクエストするように修正
  • Loading branch information
kosugikun committed Aug 3, 2022
1 parent e402e51 commit b92e421
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 22 deletions.
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<groupId>com.jagrosh</groupId>
<artifactId>JMusicBot</artifactId>
<!-- バージョン装飾子参考の参考に: https://kengotoda.gitbooks.io/what-is-maven/deploy/snapshot-and-stable.html -->
<version>0.7.1</version>
<version>0.7.2</version>
<packaging>jar</packaging>

<repositories>
Expand Down Expand Up @@ -47,7 +47,7 @@
<dependency>
<groupId>com.github.Cosgy-Dev</groupId>
<artifactId>lavaplayer-fork</artifactId>
<version>original-3a8f565d48-1</version>
<version>original-4feb559de4-1</version>
</dependency>
<!--
<dependency>
Expand Down
13 changes: 7 additions & 6 deletions src/main/java/com/jagrosh/jmusicbot/audio/AudioHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@
import net.dv8tion.jda.api.entities.Guild;
import net.dv8tion.jda.api.entities.Message;
import net.dv8tion.jda.api.entities.User;
import org.json.JSONObject;
import org.json.XML;

import java.awt.*;
import java.io.IOException;
import java.nio.ByteBuffer;
import java.util.HashSet;
import java.util.LinkedList;
Expand Down Expand Up @@ -239,10 +236,12 @@ public Message getNowPlaying(JDA jda) throws Exception {
"https://gensokyoradio.net/" :
GensokyoInfoAgent.getInfo().getMisc().getCirclelink();

String albumArt = GensokyoInfoAgent.getInfo().getMisc().getAlbumart().equals("") ?
String albumArt = "";
if(manager.getBot().getConfig().useNPImages()){
albumArt = GensokyoInfoAgent.getInfo().getMisc().getAlbumart().equals("") ?
"https://cdn.discordapp.com/attachments/240116420946427905/373019550725177344/gr-logo-placeholder.png" :
"https://gensokyoradio.net/images/albums/original/" + GensokyoInfoAgent.getInfo().getMisc().getAlbumart();

}
eb.setTitle(GensokyoInfoAgent.getInfo().getSonginfo().getTitle(), titleUrl)
.addField("アルバム", GensokyoInfoAgent.getInfo().getSonginfo().getAlbum(), true)
.addField("アーティスト", GensokyoInfoAgent.getInfo().getSonginfo().getArtist(), true)
Expand All @@ -259,11 +258,13 @@ public Message getNowPlaying(JDA jda) throws Exception {
+ FormatUtil.volumeIcon(audioPlayer.getVolume()));

eb.addField("リスナー", Integer.toString(GensokyoInfoAgent.getInfo().getServerinfo().getListeners()), true)
.setImage(albumArt)
.setColor(new Color(66, 16, 80))
.setFooter("コンテンツはgensokyoradio.netによって提供されています。\n" +
"GRロゴはGensokyo Radioの商標です。" +
"\nGensokyo Radio is © LunarSpotlight.", null);
if(manager.getBot().getConfig().useNPImages()){
eb.setImage(albumArt);
}
}

return mb.setEmbeds(eb.build()).build();
Expand Down
29 changes: 17 additions & 12 deletions src/main/java/dev/cosgy/agent/GensokyoInfoAgent.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,14 @@

import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.net.http.HttpClient;
import java.net.http.HttpRequest;
import java.net.http.HttpResponse;
import java.time.Duration;

public class GensokyoInfoAgent extends Thread {
private static final Logger log = LoggerFactory.getLogger(GensokyoInfoAgent.class);
private static final int INTERVAL_MILLIS = 60000; // 5 secs
private static long INTERVAL_MILLIS = 1000; // 5 secs
private static ResultSet info = null;
private static String lastSong = "";

Expand All @@ -44,12 +43,19 @@ public GensokyoInfoAgent() {
private static ResultSet fetch() throws Exception {
HttpURLConnection connection = null;
try{

if(info.getSongtimes().getPlayed() < info.getSongtimes().getDuration()){
return info;
}

// XMLの取得元URL設定
//URL url = new URL("https://gensokyoradio.net/xml");

HttpRequest req = HttpRequest.newBuilder(new URI("https://gensokyoradio.net/json"))
.GET()
.timeout(Duration.ofSeconds(10))
.setHeader("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/103.0.0.0 Safari/537.36")
.setHeader("accept-language", "ja,en-US;q=0.9,en;q=0.8")
.build();

HttpClient client = HttpClient.newBuilder()
Expand Down Expand Up @@ -82,7 +88,7 @@ private static ResultSet fetch() throws Exception {
}

public static ResultSet getInfo() throws Exception {
return info == null ? fetch() : info;
return fetch();
}

@Override
Expand All @@ -91,17 +97,16 @@ public void run() {

//noinspection InfiniteLoopStatement
while (true) {

try {
fetch();
sleep(INTERVAL_MILLIS);
} catch (Exception e) {
log.error("情報を取得中に例外が発生しました!", e);
try {
sleep(1000);
} catch (InterruptedException e1) {
log.error("エージェントの例外後にスリープ中に中断されました", e);
break;
sleep(1000);
// 現在再生中の曲が終わるまで幻想郷ラジオに曲の情報をリクエストしない。
// DDos攻撃になってしまうので...
if (info != null) {
info.getSongtimes().setPlayed(info.getSongtimes().getPlayed() + 1);
}
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/resources/logback.xml
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,9 @@
<!--<root level="DEBUG">
<appender-ref ref="Simple"/>
<appender-ref ref="File"/>
</root>-->
</root>
<!--<root level="TRACE">
<root level="TRACE">
<appender-ref ref="Simple"/>
<appender-ref ref="File"/>
</root>-->
Expand Down

0 comments on commit b92e421

Please sign in to comment.