@@ -21,20 +21,20 @@ public NeteaseCloudMusic() {
2121 public static JsonObject getMusicUrl (String musicName ) {
2222 try {
2323 Gson gson = new Gson ();
24- int musicId ;
24+ long musicId ;
2525 if (!musicName .contains ("-id:" )) {
2626 String getUrl = Config .neteaseApiRoot + "search?keywords=" + URLEncoder .encode (musicName , "UTF-8" ) + "&limit=1&type=1" ;
2727 String jsonText = NetUtils .getNetString (getUrl , null );
2828 JsonObject json = gson .fromJson (jsonText , JsonObject .class );
2929 JsonObject result = json .getAsJsonObject ("result" );
30- if (result != null || result .get ("songCount" ).getAsInt () != 0 ) {
30+ if (result != null && result .get ("songCount" ).getAsInt () != 0 ) {
3131 JsonObject jsonOut = result .getAsJsonArray ("songs" ).get (0 ).getAsJsonObject ();
32- musicId = jsonOut .get ("id" ).getAsInt ();
32+ musicId = jsonOut .get ("id" ).getAsLong ();
3333 } else {
3434 return null ;
3535 }
3636 } else {
37- musicId = Integer . parseInt (musicName .substring (musicName .indexOf ("-id:" ) + 4 ));
37+ musicId = Long . parseLong (musicName .substring (musicName .indexOf ("-id:" ) + 4 ));
3838 }
3939 String getUrl = Config .neteaseApiRoot + "song/detail?ids=" + musicId ;
4040 String jsonText = NetUtils .getNetString (getUrl , null );
@@ -45,11 +45,11 @@ public static JsonObject getMusicUrl(String musicName) {
4545 inttime = inttime / 1000 ;
4646 String time = String .valueOf (inttime );
4747 JsonArray singer = result .get ("ar" ).getAsJsonArray ();
48- String singerName = "" ;
48+ StringBuilder singerName = new StringBuilder () ;
4949 for (JsonElement j : singer ) {
50- singerName += j .getAsJsonObject ().get ("name" ).getAsString () + "/" ;
50+ singerName . append ( j .getAsJsonObject ().get ("name" ).getAsString ()). append ( "/" ) ;
5151 }
52- singerName = singerName .substring (0 , singerName .length () - 1 );
52+ singerName = new StringBuilder ( singerName .substring (0 , singerName .length () - 1 ) );
5353
5454 String lyricJsonText = NetUtils .getNetString (Config .neteaseApiRoot + "lyric?id=" + musicId , null );
5555 JsonObject lyricJson = gson .fromJson (lyricJsonText , JsonObject .class );
@@ -78,7 +78,7 @@ public static JsonObject getMusicUrl(String musicName) {
7878 returnJson .addProperty ("url" , musicUrl );
7979 returnJson .addProperty ("time" , time );
8080 returnJson .addProperty ("name" , name );
81- returnJson .addProperty ("singer" , singerName );
81+ returnJson .addProperty ("singer" , singerName . toString () );
8282 returnJson .addProperty ("lyric" , lyric );
8383 returnJson .addProperty ("lyricTr" , lyricTr );
8484 returnJson .addProperty ("error" , sb .toString ());
@@ -108,7 +108,7 @@ public static JsonArray getMusicList(String musicName) {
108108 JsonArray jsonOut = result .getAsJsonArray ("songs" );
109109 for (JsonElement j : jsonOut ) {
110110 String name = j .getAsJsonObject ().get ("name" ).getAsString ();
111- int musicID = j .getAsJsonObject ().get ("id" ).getAsInt ();
111+ long musicID = j .getAsJsonObject ().get ("id" ).getAsLong ();
112112 JsonArray singer = j .getAsJsonObject ().get ("artists" ).getAsJsonArray ();
113113 String singerName = "" ;
114114 for (JsonElement js : singer ) {
0 commit comments