Skip to content

Commit 67457f5

Browse files
committed
UPDATE: 修改API逻辑
自动关闭SSR(原来reflection不能获取任意package信息) TODO: 看看能不能直接从B站下资源?
1 parent e281f02 commit 67457f5

File tree

2 files changed

+42
-51
lines changed

2 files changed

+42
-51
lines changed

app/src/main/java/com/brainor/bilihelper/Api.java

Lines changed: 26 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,35 +41,25 @@ public List<Cookie> loadForRequest(@NonNull HttpUrl url) {//加载新的cookies
4141
static String _appSecret_VIP = "9b288147e5474dd2aa67085f716c560d";
4242
static String _appSecret_PlayUrl = "1c15888dc316e05a15fdd0a02ed6584f";
4343
static String BiliplusHost = "https://www.biliplus.com";
44+
4445
static String getSeasonIdURL(String ep_id) {//从ep_id网页获取season_id
4546
//需要获得season_id
46-
try {//从ep编码变成season_id编码
47-
return Objects.requireNonNull(okHttpClient.newCall(new Request.Builder()
48-
.url("https://www.bilibili.com/bangumi/play/ep" + ep_id)
49-
.build()).execute().body()).string();
50-
} catch (IOException | NullPointerException e) {
51-
return "错误:" + e.getMessage();
52-
}
47+
// try {//从ep编码变成season_id编码
48+
// return Objects.requireNonNull(okHttpClient.newCall(new Request.Builder()
49+
// .url("https://www.bilibili.com/bangumi/play/ep" + ep_id)
50+
// .build()).execute().body()).string();
51+
// } catch (IOException | NullPointerException e) {
52+
// return "错误:" + e.getMessage();
53+
// }
54+
return retrieveFromWeb("https://www.bilibili.com/bangumi/play/ep" + ep_id);
5355
}
5456

5557
static String getSeriesInfoURL(String season_id) {//利用season_id获得SeriesInfo
56-
try {//获得番剧数据
57-
return Objects.requireNonNull(okHttpClient.newCall(new Request.Builder()
58-
.url("https://bangumi.bilibili.com/view/web_api/season?season_id=" + season_id)
59-
.build()).execute().body()).string();
60-
} catch (IOException | NullPointerException e) {
61-
return "错误:" + e.getMessage();
62-
}
58+
return retrieveFromWeb("https://bangumi.bilibili.com/view/web_api/season?season_id=" + season_id);
6359
}
6460

6561
static String getMediaURL(long cid,int prefered_video_quality) {//获取视频下载地址
66-
try {
67-
return Objects.requireNonNull(okHttpClient.newCall(new Request.Builder()
68-
.url(BiliplusHost + "/BPplayurl.php?cid=" + cid + "&otype=json&qn="+prefered_video_quality)
69-
.build()).execute().body()).string();
70-
} catch (IOException | NullPointerException e) {
71-
return "错误:" + e.getMessage();
72-
}
62+
return retrieveFromWeb(BiliplusHost + "/BPplayurl.php?cid=" + cid + "&otype=json&qn="+prefered_video_quality);
7363
}
7464

7565
static String getMediaURL2(Long aid, int page, VideoType videoType) {//BiliPlus接口
@@ -99,18 +89,12 @@ static String getMediaURL3(Long cid) {//HTML5播放器获得视频地址, checke
9989

10090
static String getPageInfoURL(String aid, int page) {////利用aid获得PageInfo
10191
String url;
102-
try {//获得番剧数据
103-
if (page > 0) {//av开头的id, 获取的是视频
104-
url = "https://api.bilibili.com/view?appkey=" + appKey + "&id=" + aid + "&page=" + page;
105-
} else {//page=0表示使用BiliPlus API查pageInfo
106-
url = BiliplusHost + "/api/view?id=" + aid;
107-
}
108-
return Objects.requireNonNull(okHttpClient.newCall(new Request.Builder()
109-
.url(url)
110-
.build()).execute().body()).string();
111-
} catch (IOException | NullPointerException e) {
112-
return "错误:" + e.getMessage();
92+
if (page > 0) {//av开头的id, 获取的是视频
93+
url = "https://api.bilibili.com/view?appkey=" + appKey + "&id=" + aid + "&page=" + page;
94+
} else {//page=0表示使用BiliPlus API查pageInfo
95+
url = BiliplusHost + "/api/view?id=" + aid;
11396
}
97+
return retrieveFromWeb(url);
11498
}
11599

116100
static String getPageInfoURL2(Long aid) {//利用aid在BiliPlus获得PageInfo
@@ -126,8 +110,7 @@ private static String getSign(String url, String secret) {
126110
}
127111

128112
static String loginBiliPlus() {
129-
String loginUrl = BiliplusHost + "/login";
130-
return loginUrl;
113+
return BiliplusHost + "/login";
131114
// return "https://passport.bilibili.com/login?appkey=27eb53fc9058f8c3&api=" + loginUrl + "&sign=" + MD5("api=" + loginUrl + "c2ed53a74eeefe3cf99fbd01d8c9c375");
132115
}
133116

@@ -141,4 +124,13 @@ private static String MD5(String str) {
141124
return "";
142125
}
143126
}
127+
private static String retrieveFromWeb(String url){//联网获得信息
128+
try {//从ep编码变成season_id编码
129+
return Objects.requireNonNull(okHttpClient.newCall(new Request.Builder()
130+
.url(url)
131+
.build()).execute().body()).string();
132+
} catch (IOException | NullPointerException e) {
133+
return "错误:" + e.getMessage();
134+
}
135+
}
144136
}

app/src/main/java/com/brainor/bilihelper/MainActivity.java

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,24 +63,24 @@ protected void onCreate(Bundle savedInstanceState) {
6363
inputTextView = findViewById(R.id.inputText);
6464
// inputTextView.setText("ss25696");//调试用
6565
infoListView = findViewById(R.id.infoListView);
66-
infoListView.setAdapter(new ArrayAdapter<EpInfo>(MainActivity.this, R.layout.support_simple_spinner_dropdown_item, seriesInfo.epInfo){
66+
infoListView.setAdapter(new ArrayAdapter<EpInfo>(MainActivity.this, R.layout.support_simple_spinner_dropdown_item, seriesInfo.epInfo) {
6767
@Override
68-
public @NonNull View getView(int position, View convertView,@NonNull ViewGroup parent){
69-
View view=super.getView(position,convertView,parent);
70-
if (position==HistoryList.get(0).position){//永远是最前面的那个
71-
((TextView)view).setTextColor(Color.BLUE);
72-
}else ((TextView)view).setTextColor(Color.BLACK);
68+
public @NonNull
69+
View getView(int position, View convertView, @NonNull ViewGroup parent) {
70+
View view = super.getView(position, convertView, parent);
71+
if (position == HistoryList.get(0).position) {//永远是最前面的那个
72+
((TextView) view).setTextColor(Color.BLUE);
73+
} else ((TextView) view).setTextColor(Color.BLACK);
7374
return view;
7475
}
7576
});
7677
titleTextView = findViewById(R.id.titleTextView);
7778
LoadCookies();
7879
if (HistoryList.size() == 0) LoadHistory();
7980
Settings.videoQuality = VideoQuality.values()[Arrays.asList(VideoQuality.getEntries()).indexOf(Objects.requireNonNull(getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("quality", VideoQuality._2.description)))];
80-
Settings.clientType=Stream.of(ClientType.values()).filter(item -> Objects.equals(item.packageName, getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("clientType", ClientType.release.packageName))).findFirst().get();
81+
Settings.clientType = Stream.of(ClientType.values()).filter(item -> Objects.equals(item.packageName, getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("clientType", ClientType.release.packageName))).findFirst().get();
8182
Settings.clientDownload = getSharedPreferences("Settings", Context.MODE_PRIVATE).getBoolean("clientDown", true);
8283
searchButton.setOnClickListener(v -> {
83-
// sendBroadcast(new Intent("com.github.shadowsocks.CLOSE"));
8484
String URL = inputTextView.getText().toString();
8585
new getList().execute(URL);
8686
});
@@ -109,17 +109,17 @@ protected void onPostExecute(String successMsg) {
109109
if (successMsg.contains("成功")) {
110110
Toast.makeText(MainActivity.this, successMsg, Toast.LENGTH_LONG).show();
111111
//重启哔哩哔哩
112-
Intent intent=getPackageManager().getLaunchIntentForPackage(Settings.clientType.packageName);
112+
Intent intent = getPackageManager().getLaunchIntentForPackage(Settings.clientType.packageName);
113113
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
114-
// startActivity(intent);
115-
}
116-
else {//创建下载任务, 返回值是创建文件的路径
114+
startActivity(intent);
115+
} else {//创建下载任务, 返回值是创建文件的路径
116+
Toast.makeText(MainActivity.this, "成功: 正在下载文件\n关闭VPN", Toast.LENGTH_LONG).show();
117+
sendBroadcast(new Intent("in.zhaoj.shadowsocksr.CLOSE"));//关闭SSR
117118
for (int i = 0; i < seriesInfo.downloadSegmentInfo.size(); i++) {
118119
DownloadSegmentInfo downSegInfo = seriesInfo.downloadSegmentInfo.get(i);
119120
EpInfo epInfo = seriesInfo.epInfo.get(seriesInfo.position);
120-
DownloadTask(downSegInfo.url, successMsg + i + ".blv", seriesInfo.title + epInfo.index + epInfo.index_title + i,MainActivity.this);
121+
DownloadTask(downSegInfo.url, successMsg + i + ".blv", seriesInfo.title + epInfo.index + epInfo.index_title + i, MainActivity.this);
121122
}
122-
Toast.makeText(MainActivity.this, "成功: 正在下载文件\n需要关闭VPN", Toast.LENGTH_LONG).show();
123123
}
124124
int position = HistoryList.get(0).position;//历史记录中的位置
125125
if (position != seriesInfo.position) {
@@ -221,7 +221,7 @@ protected void onPostExecute(String HTMLBody) {
221221
HistoryInfo info = new HistoryInfo(seriesInfo.title, url + seriesInfo.season_id, -1);
222222
int position = HistoryList.indexOf(info);
223223
if (position > -1) {
224-
info.position=HistoryList.get(position).position;
224+
info.position = HistoryList.get(position).position;
225225
HistoryList.remove(position);
226226
}
227227
HistoryList.add(0, info);
@@ -315,7 +315,7 @@ static void StoreHistory(Context context) {
315315
sharedPref.edit().putStringSet("HistoryList", HistoryStrSet).apply();
316316
}
317317

318-
static Long DownloadTask(String url, String filePath, String title,Context context) {
318+
static Long DownloadTask(String url, String filePath, String title, Context context) {
319319
//关闭VPN
320320
DownloadManager downloadManager = (DownloadManager) context.getSystemService(Context.DOWNLOAD_SERVICE);
321321
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
@@ -348,5 +348,4 @@ protected void onResume() {
348348
Intent intent = getIntent();
349349
onNewIntent(intent);
350350
}
351-
352351
}

0 commit comments

Comments
 (0)