Skip to content
This repository has been archived by the owner on Dec 28, 2021. It is now read-only.

Commit

Permalink
改进下载B站视频逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
grandiloquent committed Oct 29, 2021
1 parent ad82da5 commit 57fc229
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 12 deletions.
23 changes: 12 additions & 11 deletions app/src/main/java/euphoria/psycho/bilibili/BilibiliService.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@

import androidx.annotation.Nullable;
import euphoria.psycho.PlayerActivity;
import euphoria.psycho.explorer.R;

public class BilibiliService extends Service {

Expand Down Expand Up @@ -114,7 +115,7 @@ private void download(int index) {
mBilibiliDatabase.updateBilibiliTask(mBilibiliTask);
return;
}
notify("开始下载B站视频", mBilibiliTask.Url);
notify(getString(R.string.start_downloading_the_b_station_video), mBilibiliTask.Url);
RandomAccessFile out = new RandomAccessFile(videoFile, "rw");
long currentBytes = 0;
long totalBytes = c.getContentLengthLong();
Expand Down Expand Up @@ -212,7 +213,7 @@ private void notifyFailed() {
mHandler.post(() -> {
Builder builder = getBuilder();
builder.setSmallIcon(android.R.drawable.stat_sys_download)
.setContentTitle("下载失败")
.setContentTitle(getString(R.string.download_failed))
.setContentText(mBilibiliTask.Url)
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
Expand All @@ -238,17 +239,17 @@ private void notifyProgress(String title, String content, int progress) {
@Override
public void run() {
android.os.Process.setThreadPriority(Process.THREAD_PRIORITY_BACKGROUND);
notify("准备下载B站视频", mBilibiliTask.Url);
notify(getString(R.string.ready_to_download_station_b_video), mBilibiliTask.Url);
download(0);
notify("已成功下载视频", mBilibiliTask.Url);
notify(getString(R.string.video_downloaded_successfully), mBilibiliTask.Url);
download(1);
notify("开始合并视频", mBilibiliTask.Url);
notify(getString(R.string.start_merging_videos), mBilibiliTask.Url);
try {
Movie countVideo = MovieCreator.build(mBilibiliTask.BilibiliThreads[0].Filename);
Movie countAudioEnglish = MovieCreator.build(mBilibiliTask.BilibiliThreads[1].Filename);
Track audioTrackEnglish = countAudioEnglish.getTracks().get(0);
countVideo.addTrack(audioTrackEnglish);
Container out = new DefaultMp4Builder().build(countVideo);
Movie video = MovieCreator.build(mBilibiliTask.BilibiliThreads[0].Filename);
Movie audio = MovieCreator.build(mBilibiliTask.BilibiliThreads[1].Filename);
Track audioTrack = audio.getTracks().get(0);
video.addTrack(audioTrack);
Container out = new DefaultMp4Builder().build(video);
FileOutputStream fos = new FileOutputStream(new File(mBilibiliTask.Filename));
out.writeContainer(fos.getChannel());
fos.close();
Expand All @@ -260,7 +261,7 @@ public void run() {
intent.putExtra(PlayerActivity.KEY_VIDEO_FILE, mBilibiliTask.Filename);
Builder builder = getBuilder();
builder.setSmallIcon(android.R.drawable.stat_sys_download)
.setContentTitle("已成功合并视频")
.setContentTitle(getString(R.string.videos_successfully_merged))
.setContentText(mBilibiliTask.Url)
.setWhen(System.currentTimeMillis())
.setShowWhen(true)
Expand Down
7 changes: 6 additions & 1 deletion app/src/main/res/values-zh-rCN/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,10 @@
<string name="settings">设置</string>
<string name="whether_to_use_the_browser_to_open_the_video_link">是否使用浏览器打开视频链接</string>
<string name="unable_to_extract_video">无法解析视频</string>

<string name="start_downloading_the_b_station_video">开始下载B站视频</string>
<string name="video_downloaded_successfully">已成功下载视频</string>
<string name="start_merging_videos">开始合并视频</string>
<string name="videos_successfully_merged">已成功合并视频</string>
<string name="ready_to_download_station_b_video">准备下载B站视频</string>
<string name="download_failed">下载失败</string>
</resources>
6 changes: 6 additions & 0 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@

<string name="error_unsupported_audio">Media includes audio tracks, but none are playable by this device</string>

<string name="start_downloading_the_b_station_video">Start downloading the B station video</string>
<string name="video_downloaded_successfully">Video downloaded successfully</string>
<string name="start_merging_videos">Start merging videos</string>
<string name="videos_successfully_merged">Videos successfully merged</string>
<string name="ready_to_download_station_b_video">Ready to download station B video</string>
<string name="download_failed">download failed</string>
</resources>

0 comments on commit 57fc229

Please sign in to comment.