Skip to content

Commit 63fd72c

Browse files
committed
Update: 1. 自动重启B站客户端
2. 学了一下SQL语言(map, filter) 3. 设置内添加了一项 TODO: 自动关闭SSR 看看能不能直接从B站下资源?
1 parent a1478b0 commit 63fd72c

File tree

11 files changed

+382
-140
lines changed

11 files changed

+382
-140
lines changed

.idea/vcs.xml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

app/build.gradle

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
applicationId "com.brainor.bilihelper"
77
minSdkVersion 24
88
targetSdkVersion 26
9-
versionCode 7
10-
versionName '1.6'
9+
versionCode 8
10+
versionName '1.7'
1111
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
1212
resConfigs "zh"
1313
}
@@ -40,10 +40,10 @@ dependencies {
4040
implementation fileTree(include: ['*.jar'], dir: 'libs')
4141
implementation 'androidx.appcompat:appcompat:1.0.2'
4242
implementation 'androidx.constraintlayout:constraintlayout:1.1.3'
43-
implementation 'com.google.android.material:material:1.1.0-alpha01'
43+
implementation 'com.google.android.material:material:1.1.0-alpha02'
4444
testImplementation 'junit:junit:4.12'
45-
androidTestImplementation 'androidx.test:runner:1.1.0'
46-
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.0'
45+
androidTestImplementation 'androidx.test:runner:1.1.1'
46+
androidTestImplementation 'androidx.test.espresso:espresso-core:3.1.1'
4747
implementation 'androidx.legacy:legacy-support-v4:1.0.0'
48-
implementation 'androidx.preference:preference:1.0.0'
48+
implementation 'androidx.preference:preference:1.1.0-alpha02'
4949
}

app/src/androidTest/java/com/brainor/bilihelper/ExampleInstrumentedTest.java

Lines changed: 0 additions & 27 deletions
This file was deleted.

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,8 @@
4343
android:label="@string/about"
4444
android:parentActivityName=".MainActivity"
4545
android:theme="@style/AppTheme.NoActionBar" />
46-
<activity android:name=".Settings"
46+
<activity
47+
android:name=".Settings"
4748
android:label="@string/action_settings"
4849
android:parentActivityName=".MainActivity" />
4950
</application>

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

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,8 +44,10 @@ protected void onCreate(Bundle savedInstanceState) {
4444
"<h1><a id=\"_15\"></a>已知问题</h1>\n" +
4545
"<ol>\n" +
4646
"<li>可能BiliPlus也没有相关资源的下载链接</li>\n" +
47-
"<li>B站和BiliPlus提供的链接都是acgvideo.com域名下的, 需要特定的headers或者有IP限制, 会导致下载失败. 前者可以解决, 后者无法解决</li>\n" +
48-
"</ol>\n", Html.FROM_HTML_MODE_LEGACY);
47+
"<li>B站和BiliPlus提供的链接都是acgvideo.com域名下的, 需要特定的headers或者有IP限制, 会导致下载失败. 前者可以解决, 后者无法解决.</li>\n" +
48+
"<li>B站账户必须超过5级才可以看会员视频(Biliplus限制).</li>" +
49+
"<li><font color=\"red\"><b>目前Biliplus已挂.</b></font></li>" +
50+
"</ol>\n", Html.FROM_HTML_SEPARATOR_LINE_BREAK_LIST_ITEM);
4951
aboutTextView.setText(styledText);
5052
aboutTextView.setMovementMethod(LinkMovementMethod.getInstance());
5153
}

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

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
import java.util.Objects;
3434
import java.util.regex.Matcher;
3535
import java.util.regex.Pattern;
36+
import java.util.stream.Stream;
3637

3738
import androidx.appcompat.app.AlertDialog;
3839
import androidx.appcompat.app.AppCompatActivity;
@@ -62,9 +63,11 @@ protected void onCreate(Bundle savedInstanceState) {
6263
titleTextView = findViewById(R.id.titleTextView);
6364
LoadCookies();
6465
LoadHistory();
65-
Settings.videoQuality = VideoQuality.list[Arrays.asList(VideoQuality.getEntries()).indexOf(Objects.requireNonNull(getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("quality", VideoQuality._2.description)))];
66+
Settings.videoQuality = VideoQuality.values()[Arrays.asList(VideoQuality.getEntries()).indexOf(Objects.requireNonNull(getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("quality", VideoQuality._2.description)))];
67+
Settings.clientType=Stream.of(ClientType.values()).filter(item -> Objects.equals(item.packageName, getSharedPreferences("Settings", Context.MODE_PRIVATE).getString("clientType", ClientType.release.packageName))).findFirst().get();
6668
Settings.clientDownload = getSharedPreferences("Settings", Context.MODE_PRIVATE).getBoolean("clientDown", true);
6769
searchButton.setOnClickListener(v -> {
70+
// sendBroadcast(new Intent("com.github.shadowsocks.CLOSE"));
6871
String URL = inputTextView.getText().toString();
6972
new getList().execute(URL);
7073
});
@@ -85,20 +88,25 @@ protected void onCancelled(String errMsg) {
8588
if (errMsg.contains("需要Cookies")) {
8689
PopupWebview();
8790
} else if (errMsg.contains("timeout"))
88-
Api.BiliplusHost = "https://" + (Api.BiliplusHost == "https://www.biliplus.com" ? "backup" : "www") + ".biliplus.com";
91+
Api.BiliplusHost = "https://" + (Api.BiliplusHost.equals("https://www.biliplus.com") ? "backup" : "www") + ".biliplus.com";
8992
}
9093

9194
@Override
9295
protected void onPostExecute(String successMsg) {
93-
if (successMsg.contains("成功"))
96+
if (successMsg.contains("成功")) {
9497
Toast.makeText(MainActivity.this, successMsg, Toast.LENGTH_LONG).show();
98+
//重启哔哩哔哩
99+
Intent intent=getPackageManager().getLaunchIntentForPackage(Settings.clientType.packageName);
100+
intent.addFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
101+
startActivity(intent);
102+
}
95103
else {//创建下载任务, 返回值是创建文件的路径
96104
for (int i = 0; i < seriesInfo.downloadSegmentInfo.size(); i++) {
97105
DownloadSegmentInfo downSegInfo = seriesInfo.downloadSegmentInfo.get(i);
98106
EpInfo epInfo = seriesInfo.epInfo.get(seriesInfo.position);
99107
DownloadTask(downSegInfo.url, successMsg + i + ".blv", seriesInfo.title + epInfo.index + epInfo.index_title + i);
100108
}
101-
Toast.makeText(MainActivity.this, "成功: 正在下载文件", Toast.LENGTH_LONG).show();
109+
Toast.makeText(MainActivity.this, "成功: 正在下载文件\n需要关闭VPN", Toast.LENGTH_LONG).show();
102110
}
103111
int position = HistoryList.get(0).position;//历史记录中的位置
104112
if (position != seriesInfo.position) {
@@ -301,6 +309,7 @@ static void StoreHistory(Context context) {
301309
}
302310

303311
void DownloadTask(String url, String filePath, String title) {
312+
//关闭VPN
304313
DownloadManager downloadManager = (DownloadManager) getSystemService(Context.DOWNLOAD_SERVICE);
305314
DownloadManager.Request request = new DownloadManager.Request(Uri.parse(url));
306315
request.setAllowedOverMetered(false);

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

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import java.util.ArrayList;
44
import java.util.Objects;
5+
import java.util.stream.Stream;
56

67
import androidx.annotation.NonNull;
78

@@ -56,13 +57,18 @@ public String toString() {
5657
}
5758

5859
enum ClientType {
59-
release("tv.danmaku.bili/download/"),//正式版
60-
blue("com.bilibili.app.blue/download/"),//概念版
61-
play("com.bilibili.app.in/download/");//Play商店版
60+
release("tv.danmaku.bili"),//正式版
61+
blue("com.bilibili.app.blue"),//概念版
62+
play("com.bilibili.app.in");//Play商店版
6263
String appPath;
64+
String packageName;
6365

64-
ClientType(String appPath) {
65-
this.appPath = appPath;
66+
ClientType(String packageName) {
67+
this.appPath = packageName + "/download/";
68+
this.packageName = packageName;
69+
}
70+
public static String[] getEntries() {
71+
return Stream.of(ClientType.values()).map(cT -> cT.packageName).toArray(String[]::new);
6672
}
6773
}
6874

@@ -111,11 +117,7 @@ enum VideoQuality {
111117
this.description = description;
112118
}
113119

114-
static VideoQuality[] list = VideoQuality.values();
115-
116120
public static String[] getEntries() {
117-
String[] entries = new String[list.length];
118-
for (int i = 0; i < list.length; i++) entries[i] = list[i].description;
119-
return entries;
121+
return Stream.of(VideoQuality.values()).map(vQ -> vQ.description).toArray(String[]::new);
120122
}
121123
}

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

Lines changed: 61 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,13 +5,19 @@
55
import android.os.Bundle;
66
import android.preference.PreferenceManager;
77
import android.view.View;
8+
import android.widget.RelativeLayout;
89

910
import java.util.Arrays;
11+
import java.util.Objects;
12+
import java.util.Set;
13+
import java.util.stream.Collectors;
14+
import java.util.stream.Stream;
1015

1116
import androidx.appcompat.app.ActionBar;
1217
import androidx.appcompat.app.AppCompatActivity;
1318
import androidx.preference.ListPreference;
1419
import androidx.preference.Preference;
20+
import androidx.preference.PreferenceCategory;
1521
import androidx.preference.PreferenceFragmentCompat;
1622
import androidx.preference.PreferenceGroupAdapter;
1723
import androidx.preference.PreferenceScreen;
@@ -38,6 +44,7 @@ protected void onCreate(Bundle savedInstanceState) {
3844

3945

4046
public static class MySettingsFragment extends PreferenceFragmentCompat {
47+
4148
@Override//去除前面的空白
4249
protected RecyclerView.Adapter onCreateAdapter(PreferenceScreen preferenceScreen) {
4350
return new PreferenceGroupAdapter(preferenceScreen) {
@@ -58,36 +65,75 @@ public void onBindViewHolder(PreferenceViewHolder holder, int position) {
5865
public void onCreatePreferences(Bundle savedInstanceState, String rootKey) {
5966
Context context = getPreferenceManager().getContext();
6067
PreferenceScreen screen = getPreferenceManager().createPreferenceScreen(context);
68+
screen.setIconSpaceReserved(false);
6169

62-
ListPreference quality = new ListPreference(context);
63-
quality.setKey("quality");
64-
quality.setEntries(VideoQuality.getEntries());
65-
quality.setEntryValues(VideoQuality.getEntries());
66-
quality.setTitle("视频清晰度");
67-
quality.setSummary(PreferenceManager.getDefaultSharedPreferences(quality.getContext()).getString(quality.getKey(), VideoQuality._2.description));
68-
quality.setValue((String) quality.getSummary());
69-
quality.setOnPreferenceChangeListener((preference, newValue) -> {
70-
preference.setSummary(newValue.toString());
71-
videoQuality = VideoQuality.list[Arrays.asList(VideoQuality.getEntries()).indexOf(newValue.toString())];
70+
PreferenceCategory downCategory = new PreferenceCategory(context) {
71+
@Override
72+
public void onBindViewHolder(PreferenceViewHolder holder) {
73+
super.onBindViewHolder(holder);
74+
holder.itemView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
75+
}
76+
};
77+
downCategory.setTitle("下载设置");
78+
79+
ListPreference qualityList = new ListPreference(context);
80+
qualityList.setNegativeButtonText("");
81+
qualityList.setKey("quality");
82+
qualityList.setEntries(VideoQuality.getEntries());
83+
qualityList.setEntryValues(VideoQuality.getEntries());
84+
qualityList.setTitle("视频清晰度");
85+
qualityList.setSummary(PreferenceManager.getDefaultSharedPreferences(context).getString(qualityList.getKey(), VideoQuality._2.description));
86+
qualityList.setValue((String) qualityList.getSummary());
87+
qualityList.setOnPreferenceChangeListener((preference, newValue) -> {
88+
preference.setSummary((String) newValue);
89+
videoQuality = Stream.of(VideoQuality.values()).filter(item -> Objects.equals(item.description, newValue)).findFirst().get();
90+
// videoQuality = VideoQuality.values()[Arrays.asList(VideoQuality.getEntries()).indexOf(newValue.toString())];
7291
return true;
7392
});
93+
7494
SwitchPreference clientDownloadSwitch = new SwitchPreference(context);
7595
clientDownloadSwitch.setSummaryOn("B站");
7696
clientDownloadSwitch.setSummaryOff("系统");
7797
clientDownloadSwitch.setKey("clientDown");
78-
clientDownloadSwitch.setChecked(PreferenceManager.getDefaultSharedPreferences(clientDownloadSwitch.getContext()).getBoolean(clientDownloadSwitch.getKey(), true));
98+
clientDownloadSwitch.setChecked(PreferenceManager.getDefaultSharedPreferences(context).getBoolean(clientDownloadSwitch.getKey(), true));
7999
clientDownloadSwitch.setTitle("下载方式");
80100
clientDownloadSwitch.setOnPreferenceChangeListener((preference, newValue) -> {
81101
clientDownload = (boolean) newValue;
82102
return true;
83103
});
84104

85-
screen.addPreference(quality);
86-
screen.addPreference(clientDownloadSwitch);
87-
setPreferenceScreen(screen);
105+
PreferenceCategory paraCategory = new PreferenceCategory(context) {
106+
@Override
107+
public void onBindViewHolder(PreferenceViewHolder holder) {
108+
super.onBindViewHolder(holder);
109+
holder.itemView.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
110+
}
111+
};
112+
paraCategory.setTitle("参数设置");
88113

89-
}
114+
ListPreference clientTypeList = new ListPreference(context);
115+
clientTypeList.setNegativeButtonText("");
116+
clientTypeList.setKey("clientType");
117+
clientTypeList.setEntries(ClientType.getEntries());
118+
Set<String> packageNames = context.getPackageManager().getInstalledApplications(0).stream().map(item -> item.packageName).collect(Collectors.toSet());
119+
clientTypeList.setEntries(Stream.of(ClientType.values()).map(cT -> cT.packageName).filter(item -> !packageNames.add(item)).toArray(String[]::new));
120+
clientTypeList.setEntryValues(clientTypeList.getEntries());
121+
clientTypeList.setTitle("客户端类型");
122+
clientTypeList.setSummary(PreferenceManager.getDefaultSharedPreferences(context).getString(clientTypeList.getKey(), ClientType.release.packageName));
123+
clientTypeList.setValue((String) clientTypeList.getSummary());
124+
clientTypeList.setOnPreferenceChangeListener((preference, newValue) -> {
125+
preference.setSummary(newValue.toString());
126+
clientType = ClientType.values()[Arrays.asList(ClientType.getEntries()).indexOf((String) newValue)];
127+
return true;
128+
});
90129

130+
screen.addPreference(downCategory);
131+
downCategory.addPreference(qualityList);
132+
downCategory.addPreference(clientDownloadSwitch);
133+
screen.addPreference(paraCategory);
134+
paraCategory.addPreference(clientTypeList);
135+
setPreferenceScreen(screen);
136+
}
91137
}
92138

93139
}

app/src/test/java/com/brainor/bilihelper/ExampleUnitTest.java

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)