Skip to content

Commit

Permalink
修复咪咕音乐接口
Browse files Browse the repository at this point in the history
提升匹配准确率
提高酷我音乐响应速度
  • Loading branch information
ndroi committed Jul 22, 2020
1 parent 8e6bb4c commit 9b184fd
Show file tree
Hide file tree
Showing 13 changed files with 19 additions and 53 deletions.
5 changes: 0 additions & 5 deletions Easy163/app/src/main/java/org/ndroi/easy163/core/Cache.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,9 @@
package org.ndroi.easy163.core;

import org.ndroi.easy163.utils.Keyword;

import java.util.LinkedHashMap;
import java.util.Map;

/**
* Created by andro on 2020/5/5.
*/

public class Cache
{
interface AddAction
Expand Down
2 changes: 0 additions & 2 deletions Easy163/app/src/main/java/org/ndroi/easy163/core/Find.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@
package org.ndroi.easy163.core;

import com.alibaba.fastjson.JSONObject;

import org.ndroi.easy163.providers.utils.ReadStream;
import org.ndroi.easy163.utils.Keyword;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
Expand Down
6 changes: 3 additions & 3 deletions Easy163/app/src/main/java/org/ndroi/easy163/core/Search.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ public class Search
{
private static List<Provider> providers = Arrays.asList(
new KuwoMusic(),
new QQMusic(),
new MiguMusic()
new MiguMusic(),
new QQMusic()
);

public static Song search(Keyword keyword)
Expand Down Expand Up @@ -66,7 +66,7 @@ public void run()
}
if (!songs.isEmpty())
{
Log.d("search", "from provider: " + songs.get(0).toString());
Log.d("search", "from provider:\n" + songs.get(0).toString());
return songs.get(0);
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ private void setHooks()

private void setHttpsBlock()
{
/*not used yet*/
BlockHttps.getInstance().addHost("music.163.com");
BlockHttps.getInstance().addHost("interface3.music.163.com");
BlockHttps.getInstance().addHost("interface.music.163.com");
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.ndroi.easy163.hooks;

import android.util.Log;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

Expand Down Expand Up @@ -61,7 +63,7 @@ private String preDownloadForMd5(String url)
{
MessageDigest messageDigest = MessageDigest.getInstance("md5");
InputStream inputStream = connection.getInputStream();
byte[] bytes = new byte[4096];
byte[] bytes = new byte[4096*2];
while (true)
{
int readLen = inputStream.read(bytes);
Expand Down Expand Up @@ -109,7 +111,7 @@ private void handleDownload(JSONObject jsonObject)
{
String id = songObject.getString("id");
Song providerSong = (Song) Cache.providerSongs.get(id);
if (providerSong.md5.isEmpty())
if (providerSong.md5.equals("unknown"))
{
providerSong.md5 = preDownloadForMd5(providerSong.url);
//Log.d("DownloadHook", "Pre-download for md5: " + providerSong.md5);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,35 +1,25 @@
package org.ndroi.easy163.providers;

import android.util.Log;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import org.ndroi.easy163.providers.utils.KeywordMatch;
import org.ndroi.easy163.providers.utils.ReadStream;
import org.ndroi.easy163.utils.Keyword;
import org.ndroi.easy163.utils.Song;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.List;
import java.util.Map;

/**
* Created by andro on 2020/5/3.
*/
public class KuwoMusic extends Provider
{
@Override
public Song match(Keyword keyword)
{
String query = keyword2Query(keyword);
String token = getToken(query);
if (token == null)
{
return null;
}
String token = "1234567890";
String mId = getMId(query, token, keyword);
if (mId == null)
{
Expand All @@ -39,7 +29,7 @@ public Song match(Keyword keyword)
return song;
}

private boolean IsOriginal(String songName)
private boolean IsNonOriginal(String songName)
{
int p1 = songName.indexOf('(');
int p2 = songName.indexOf(')');
Expand All @@ -53,15 +43,14 @@ private JSONObject selectBestMatch(JSONArray candidates, Keyword keyword)
JSONObject info = (JSONObject) infoObj;
Keyword candidateKeyword = new Keyword();
candidateKeyword.songName = info.getString("name");
if (IsOriginal(candidateKeyword.songName))
if (IsNonOriginal(candidateKeyword.songName))
{
Log.d("KuwoMusic", "Ignore Non-Original Version");
Log.d("KuwoMusic", "Skip Non-Original Version");
continue;
}
candidateKeyword.singers.add(info.getString("artist"));
if (KeywordMatch.match(keyword, candidateKeyword))
{
Log.d("KuwoMusic:selectBestMatch", info.toString());
return info;
}
}
Expand All @@ -70,7 +59,6 @@ private JSONObject selectBestMatch(JSONArray candidates, Keyword keyword)

private String getToken(String query)
{

String token = null;
String url = "http://kuwo.cn/search/list?key=" + query;
try
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

import org.ndroi.easy163.providers.utils.KeywordMatch;
import org.ndroi.easy163.providers.utils.MiguCrypto;
import org.ndroi.easy163.providers.utils.ReadStream;
import org.ndroi.easy163.utils.Keyword;
import org.ndroi.easy163.utils.Song;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,21 @@
import org.ndroi.easy163.providers.utils.ReadStream;
import org.ndroi.easy163.utils.Keyword;
import org.ndroi.easy163.utils.Song;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLEncoder;

/**
* Created by andro on 2020/5/3.
*/
public abstract class Provider
{
static protected String keyword2Query(Keyword keyword)
{
String str = keyword.songName + " ";
String str = keyword.songName;
for (String singer : keyword.singers)
{
str += (singer + " ");
str += (" " + singer);
}
str = str.trim();
try
{
str = URLEncoder.encode(str, "UTF-8");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@
import java.net.HttpURLConnection;
import java.net.URL;

/**
* Created by andro on 2020/5/3.
*/
public class QQMusic extends Provider
{
@Override
Expand Down Expand Up @@ -46,7 +43,7 @@ private JSONObject selectBestMatch(JSONArray candidates, Keyword keyword)
String title = info.getString("title");
if (title.toLowerCase().endsWith("(live)"))
{
Log.d("QQMusic", "Ignore Live Version");
Log.d("QQMusic", "Skip Live Version");
continue;
}
Keyword candidateKeyword = new Keyword();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package org.ndroi.easy163.providers.utils;

import android.util.Base64;

import java.io.UnsupportedEncodingException;
import java.net.URLEncoder;
import java.security.InvalidAlgorithmParameterException;
Expand All @@ -10,7 +9,6 @@
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.List;

import javax.crypto.BadPaddingException;
import javax.crypto.Cipher;
import javax.crypto.IllegalBlockSizeException;
Expand All @@ -23,10 +21,6 @@
*/
public class MiguCrypto
{
private static String pubKey = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBg" +
"QC8asrfSaoOb4je+DSmKdriQJKWVJ2oDZrs3wi5W67m3LwTB9QVR+cE3XWU21Nx+YBxS0yu" +
"n8wDcjgQvYt625ZCcgin2ro/eOkNyUOTBIbuj9CvMnhUYiR61lC1f1IGbrSYYimqBVSjpifVu" +
"fxtx/I3exReZosTByYp4Xwpb1+WAQIDAQAB";
private static String password = "00000000000000000000000000000000";
private static String salt = "00000000";
private static String skeyB64 = "OMYm0ulbQZgEd21abq1wQI7CnLeAY5CT4RPRLBmAzSUdBWgPHq3n" +
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import android.widget.CompoundButton;
import android.widget.Toast;
import android.widget.ToggleButton;

import org.ndroi.easy163.R;
import org.ndroi.easy163.core.Server;
import org.ndroi.easy163.vpn.LocalVPNService;
Expand Down Expand Up @@ -46,7 +45,6 @@ protected void onCreate(Bundle savedInstanceState)
navigationView.setNavigationItemSelectedListener(this);
ToggleButton toggleButton = findViewById(R.id.bt_start);
toggleButton.setOnCheckedChangeListener(this);

Server.getInstance().start();
}

Expand Down
6 changes: 3 additions & 3 deletions Easy163/app/src/main/java/org/ndroi/easy163/utils/Song.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
public class Song
{
public int size = 10 * 1000 * 1000;
public int br = 192000; // fake
public String url = "";
public String md5 = "";
public int br = 192000;
public String url = "unknown";
public String md5 = "unknown";

@Override
public String toString()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ public void run()
{
while (true)
{
ByteBuffer buffer = ByteBuffer.allocate(4 * 1024);
ByteBuffer buffer = ByteBuffer.allocateDirect(4 * 1024);
if (tunnel.destSocket == null)
{
throw new ProxyException("tunnel maybe closed");
Expand Down

0 comments on commit 9b184fd

Please sign in to comment.