Skip to content
This repository has been archived by the owner on Apr 3, 2024. It is now read-only.

Commit

Permalink
修复下载功能相关问题
Browse files Browse the repository at this point in the history
  • Loading branch information
670848654 committed Oct 6, 2023
1 parent 739dc64 commit 44849db
Show file tree
Hide file tree
Showing 12 changed files with 104 additions and 20 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "my.project.sakuraproject"
minSdkVersion 21
targetSdkVersion 33
versionCode 63
versionName "2.5.8"
versionCode 64
versionName "2.5.9"
ndk{abiFilters "armeabi-v7a", "arm64-v8a", "x86_64"}
resConfigs"zh"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1173,4 +1173,19 @@ public static void updatePlayUrl() {
cursor.close();
}
}

/**
* 删除数据库中不存在的任务
* @param context
* @param taskId
*/
public static void deleteAbsentTask(Context context, long taskId) {
Cursor cursor = db.rawQuery("select * from T_DOWNLOAD_DATA where F_TASK_ID = ?", new String[]{String.valueOf(taskId)});
if (cursor.getCount() == 0) {
// 数据库中不存在 删除任务
Aria.download(context).load(taskId).ignoreCheckPermissions().cancel();
Log.e("删除不存在的任务", "TaskId:" + taskId);
}
cursor.close();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,7 @@ public void showUpdateLogs() {

public List createUpdateLogList() {
List logsList = new ArrayList();
logsList.add(new LogBean("版本:2.5.9", "修复下载功能相关问题"));
logsList.add(new LogBean("版本:2.5.8", "临时方案解决SiliSili源无法访问的问题,*如更改过源域名地址请恢复默认"));
logsList.add(new LogBean("版本:2.5.7", "修复SiliSili源No.A/X路线播放时切换集数不进行二次解析的问题"));
logsList.add(new LogBean("版本:2.5.6", "修复更新改动导致YHDM源首页更多点击失效的问题"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import android.widget.LinearLayout;
import android.widget.RelativeLayout;
import android.widget.TextView;
import android.widget.Toast;

import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.m3u8.M3U8VodOption;
Expand Down Expand Up @@ -773,17 +774,22 @@ public void showYhdmVideoSuccessView(List<String> urls, String playNumber) {
*/
private void startDownload(String url, String playNumber) {
downloadBottomSheetDialog.dismiss();
if (!url.endsWith("mp4") && !url.endsWith("m3u8")) {
/*if (!url.endsWith("mp4") && !url.endsWith("m3u8")) {
VideoUtils.showInfoDialog(this, "不支持的下载格式,该地址可能非视频地址! -> " + url);
return;
}*/
if (!url.contains("http")) {
VideoUtils.showInfoDialog(this, "不支持的下载格式,该地址可能非视频地址! -> " + url);
return;
}
long taskId;
String fileSavePath = savePath + playNumber;
boolean isM3U8 = url.endsWith("m3u8");
taskId = createDownloadTask(isM3U8, url, fileSavePath);
if (isM3U8) VideoUtils.showInfoDialog(this, "该视频资源格式为M3U8,可能无法正常下载成功!");
if (isM3U8) VideoUtils.showInfoDialog(this, "该视频资源类型为M3U8,可能无法正常下载成功!");
DatabaseUtil.insertDownload(animeTitle, source, animeListBean.getImg(), sakuraUrl);
DatabaseUtil.insertDownloadData(animeTitle, source, playNumber, 0, taskId);
Toast.makeText(this, "开始下载 -> " +playNumber, Toast.LENGTH_SHORT).show();
// 开启下载服务
startService(new Intent(this, DownloadService.class));
EventBus.getDefault().post(new Refresh(3));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,8 @@ protected View initViews(LayoutInflater inflater, ViewGroup container, Bundle sa
private void initAdapter() {
DatabaseUtil.openDB();
videoList.add(new MainBean("追番列表", 1, R.drawable.outline_movie_filter_white_48dp, DatabaseUtil.queryFavoriteCount()));
videoList.add(new MainBean("历史播放记录", 2, R.drawable.baseline_history_white_48dp, DatabaseUtil.queryHistoryCount()));
videoList.add(new MainBean("视频下载列表", 3, R.drawable.baseline_download_white_48dp, DatabaseUtil.queryAllDownloadCount()));
videoList.add(new MainBean("历史记录", 2, R.drawable.baseline_history_white_48dp, DatabaseUtil.queryHistoryCount()));
videoList.add(new MainBean("下载列表", 3, R.drawable.baseline_download_white_48dp, DatabaseUtil.queryAllDownloadCount()));
videoAdapter = new MainAdapter(getActivity(), videoList);
videoAdapter.setOnItemClickListener((adapter, view, position) -> {
switch (videoList.get(position).getType()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,12 @@ protected void init() {
initToolbar();
initAdapter();
Aria.download(this).register();
List<DownloadEntity> list = Aria.download(this).getAllNotCompleteTask();
if (list != null && list.size() > 0) {
for (DownloadEntity downloadEntity : list) {
DatabaseUtil.deleteAbsentTask(this, downloadEntity.getId());
}
}
/*if (!Utils.isServiceRunning(Sakura.getInstance(), "my.project.sakuraproject.services.DownloadService"))
new Handler().postDelayed(() -> checkNotCompleteDownloadTask(), 200);*/
startService(new Intent(this, DownloadService.class));
Expand All @@ -98,21 +104,24 @@ private void checkNotCompleteDownloadTask() {
if (list != null && list.size() > 0) {
AlertDialog alertDialog;
MaterialAlertDialogBuilder builder = new MaterialAlertDialogBuilder(this, R.style.DialogStyle);
builder.setTitle("下载任务操作");
builder.setMessage(String.format("你有%s个未完成的下载任务,是否继续下载?", list.size()+""));
builder.setPositiveButton(Utils.getString(R.string.download_positive), (dialog, which) -> {
setM3U8VodOption();
for (DownloadEntity entity : list) {
if (entity.getUrl().contains("m3u8")) {
Log.e("恢复下载M3U8", "....");
Aria.download(this).load(entity.getId()).m3u8VodOption(m3U8VodOption).resume();
Aria.download(this).load(entity.getId()).ignoreCheckPermissions().m3u8VodOption(m3U8VodOption).resume();
} else {
Aria.download(this).load(entity.getId()).resume();
Aria.download(this).load(entity.getId()).ignoreCheckPermissions().resume();
Log.e("恢复下载MP4", "....");
}
}
});
builder.setNegativeButton(Utils.getString(R.string.download_negative), (dialog, which) -> dialog.dismiss());
// builder.setNeutralButton(Utils.getString(R.string.remove_download_file), (dialog, which) -> deleteData(checkBox.isChecked(), bean, position));
/*builder.setNeutralButton(Utils.getString(R.string.download_neutral), (dialog, which) -> {
Aria.download(this).removeAllTask(false);
});*/
builder.setCancelable(false);
alertDialog = builder.create();
alertDialog.show();
Expand Down Expand Up @@ -205,7 +214,8 @@ public void onEvent(Refresh refresh) {
protected void running(DownloadTask downloadTask) {
// JSONObject obj = JSONObject.parseObject(Aria.download(this).load(downloadTask.getEntity().getId()).getExtendField());
for (int i = 0, size = downloadList.size(); i < size; i++) {
String title = (String) DatabaseUtil.queryDownloadAnimeInfo(downloadTask.getEntity().getId()).get(0);
List<Object> list = DatabaseUtil.queryDownloadAnimeInfo(downloadTask.getEntity().getId());
String title = (String) list.get(0);
if (downloadList.get(i).getAnimeTitle().equals(title)) {
TextView number = (TextView) adapter.getViewByPosition(i, R.id.number);
if (number != null) {
Expand All @@ -226,6 +236,11 @@ protected void running(DownloadTask downloadTask) {
}
}

@Download.onTaskStop
protected void stop(DownloadTask downloadTask) {
adapter.notifyDataSetChanged();
}

/*@Download.onTaskComplete
public void onTaskComplete(DownloadTask downloadTask) {
// JSONObject obj = JSONObject.parseObject(Aria.download(this).load(downloadTask.getEntity().getId()).getExtendField());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,16 +127,19 @@ private void initAdapter() {
switch (i) {
case 0:
// 继续下载
Aria.download(this).load(taskId).resume();
Aria.download(this).load(taskId).ignoreCheckPermissions().resume();
downloadDataBeans.get(position).setComplete(0);
startService(new Intent(this, DownloadService.class));
break;
case 1:
Aria.download(this).load(taskId).stop();
// 暂停任务
Aria.download(this).load(taskId).ignoreCheckPermissions().stop();
downloadDataBeans.get(position).setComplete(0);
adapter.notifyItemChanged(position);
stopService(new Intent(this, DownloadService.class));
break;
case 2:
// 删除任务
showDeleteDataDialog(downloadDataBeans.get(position), position);
break;
}
Expand Down Expand Up @@ -170,7 +173,7 @@ private void initAdapter() {
dialogInterface.dismiss();
switch (i) {
case 0:
Aria.download(this).load(taskId).resume();
Aria.download(this).load(taskId).ignoreCheckPermissions().resume();
downloadDataBeans.get(position).setComplete(0);
DatabaseUtil.updateDownloadState(taskId);
break;
Expand Down Expand Up @@ -235,12 +238,12 @@ private void deleteData(boolean removeFile, DownloadDataBean bean, int position)
// 未下载完成
if (bean.getTaskId() != -99 && bean.getTaskId() == entity.getId()) {
// 从Aria数据库中删除任务
Aria.download(this).load(entity.getId()).cancel(removeFile);
Aria.download(this).load(entity.getId()).ignoreCheckPermissions().cancel(removeFile);
break;
// 已下载完成通过path对比
} else if (bean.getPath().equals(entity.getFilePath().replaceAll("m3u8", "mp4"))) {
// 从Aria数据库中删除任务
Aria.download(this).load(entity.getId()).cancel(removeFile);
Aria.download(this).load(entity.getId()).ignoreCheckPermissions().cancel(removeFile);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public class SettingActivity extends BaseActivity {
private String[] danmuItems = {"开", "关"};
@BindView(R.id.kernel_default)
TextView kernelDefaultView;
private String[] playerKernelItems = {"ExoPlayer", "Ijkplayer"};
private String[] playerKernelItems = {"ExoPlayer", "IjkPlayer"};
@Override
protected Presenter createPresenter() {
return null;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
package my.project.sakuraproject.main.video;

import android.util.Log;

import java.io.IOException;
import java.util.List;
import java.util.regex.Pattern;

import my.project.sakuraproject.api.Api;
import my.project.sakuraproject.application.Sakura;
import my.project.sakuraproject.main.base.BaseModel;
import my.project.sakuraproject.net.HttpGet;
Expand Down Expand Up @@ -86,6 +89,40 @@ public void onFailure(Call call, IOException e) {
public void onResponse(Call call, Response response) throws IOException {
String source = getHtmlBody(response, true);
String playUrl = ImomoeJsoupUtils.getImomoePlayUrl(source);
if (!playUrl.isEmpty()) {
if (!playUrl.contains("http")) {
// 不是连接 使用第二套解析方案
getSilisiliVideoUrl(playUrl, playNumber, callback);
} else
callback.successImomoeVideoUrls(playUrl, playNumber);
}
else
callback.error(playNumber);
}
});
}

/**
* 第二套解析方案
* @param url
* @param playNumber
* @param callback
*/
public void getSilisiliVideoUrl(String url, String playNumber, DownloadVideoContract.LoadDataCallback callback) {
String parseUrl = String.format(Api.SILISILI_PARSE_API, getDomain(true), url);
callback.log(parseUrl);
Log.e("parseUrl", parseUrl);
new HttpGet(parseUrl, new Callback() {
@Override
public void onFailure(Call call, IOException e) {
callback.error(playNumber);
}

@Override
public void onResponse(Call call, Response response) throws IOException {
String source = getHtmlBody(response, false);
String playUrl = ImomoeJsoupUtils.getSilisiliVideoUrl(source);
Log.e("playUrl", playUrl);
if (!playUrl.isEmpty())
callback.successImomoeVideoUrls(playUrl, playNumber);
else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,7 @@ public static AnimeListBean getAinmeInfo(String source, String url) {
List<String> tagTitles = new ArrayList<>();
List<String> tagUrls = new ArrayList<>();
for (Element tag : tags) {
if (tag.text().isEmpty()) continue;
tagTitles.add(tag.text().toUpperCase());
tagUrls.add(tag.attr("href"));
}
Expand Down Expand Up @@ -370,7 +371,13 @@ public static AnimeDescListBean getAnimeDescList(String source, String dramaStr)
List<AnimeDramasBean> animeDramasBeans = new ArrayList<>();
for (Element element : playBox) {
AnimeDramasBean animeDramasBean = new AnimeDramasBean();
String playListTitle = element.select("div.widget-title").text();
String playListName = element.select("div.widget-title").text();
String playListTip = element.select("span.pull-right").text();
String playListTitle;
if (playListTip.isEmpty())
playListTitle = playListName;
else
playListTitle = playListName + " ["+playListTip+"]";
// if (playListTitle.toLowerCase(Locale.ROOT).contains("no.x")) playListTitle += " → 需二次解析,无法播放(网站问题?)";
if (playListTitle.contains("下载")) continue;
animeDramasBean.setListTitle(playListTitle);
Expand Down
2 changes: 1 addition & 1 deletion app/src/main/res/layout/item_history.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@
android:id="@+id/desc_view"
android:layout_alignParentStart="true"
android:layout_alignParentBottom="true"
android:layout_width="wrap_content"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="@color/colorAccent"
android:text="@string/history_detail"/>
Expand Down
4 changes: 2 additions & 2 deletions app/src/main/res/values/strings.xml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@
<string name="player_kernel_title">内置播放器内核</string>
<string name="set_player_kernel">请选择播放器内核</string>
<string name="exoplayer">ExoPlayer</string>
<string name="ijkplayer">Ijkplayer</string>
<string name="ijkplayer">IjkPlayer</string>
<!-- webViewDialog 文本 -->
<string name="other_operation">操作</string>
<string name="anthology">选集</string>
Expand Down Expand Up @@ -137,7 +137,7 @@
<string name="test_model_desc">Xiaomi 12S Ultra | XiaomiPad 5 Pro\nAndroid 13</string>
<string name="now_version">当前版本</string>
<string name="final_compile">最后编译日期</string>
<string name="final_compile_time">2023年10月5日</string>
<string name="final_compile_time">2023年10月6日</string>
<string name="cache">缓存目录</string>
<string name="cache_text">/SakuraAnime/\n卸载后自行删除此目录</string>
<string name="github">Github仓库</string>
Expand Down

0 comments on commit 44849db

Please sign in to comment.