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

Commit

Permalink
fix malimali source
Browse files Browse the repository at this point in the history
  • Loading branch information
670848654 committed Aug 1, 2022
1 parent 0d580ae commit e826420
Show file tree
Hide file tree
Showing 15 changed files with 316 additions and 205 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 30
versionCode 43
versionName "2.3.4"
versionCode 44
versionName "2.3.5"
ndk{abiFilters "arm64-v8a", "x86_64"}
resConfigs"zh"
}
Expand Down
8 changes: 4 additions & 4 deletions app/src/main/java/my/project/sakuraproject/api/Api.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package my.project.sakuraproject.api;

import com.arialyy.annotations.M3U8;

public class Api {
//检测更新
public final static String CHECK_UPDATE = "https://api.github.com/repos/670848654/SakuraAnime/releases/latest";
Expand All @@ -14,8 +12,10 @@ public class Api {
// malimali 搜索
public final static String MALIMALI_SEARCH = "/vodsearch/%s----------%s---.html";
// malimali 分类
public final static String MALIMALI_TAG = "/vodshow/%s-%s-%s-%s-%s-%s.html"; // 1, 排序, 分类, 字母, 分页, 年代
public final static String MALIMALI_TAG_DEFAULT = "1";
// https://www.malimali6.com/vodshow/10--hits-%E6%90%9E%E7%AC%91--B---1---2022.html
public final static String MALIMALI_TAG = "/vodshow/%s--%s-%s--%s---%s---%s.html"; // 1, 排序, 分类, 字母, 分页, 年代
// public final static String MALIMALI_TAG = "/vodshow/%s-%s-%s-%s-%s-%s.html"; // 1, 排序, 分类, 字母, 分页, 年代
public final static String MALIMALI_TAG_DEFAULT = "1"; // 默认分类【全部】
public final static String MALIMALI_CHINA = "9";
public final static String MALIMALI_JAPAN = "10";
public final static String MALIMALI_EUROPE = "11";
Expand Down
47 changes: 47 additions & 0 deletions app/src/main/java/my/project/sakuraproject/bean/DownloadEvent.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package my.project.sakuraproject.bean;

public class DownloadEvent {
private String title;
private String drama;
private String filePath;
private long fileSize;

public DownloadEvent(String title, String drama, String filePath, long fileSize) {
this.title = title;
this.drama = drama;
this.filePath = filePath;
this.fileSize = fileSize;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public String getDrama() {
return drama;
}

public void setDrama(String drama) {
this.drama = drama;
}

public String getFilePath() {
return filePath;
}

public void setFilePath(String filePath) {
this.filePath = filePath;
}

public long getFileSize() {
return fileSize;
}

public void setFileSize(long fileSize) {
this.fileSize = fileSize;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
package my.project.sakuraproject.config;

import android.util.Log;

import androidx.annotation.Nullable;

import com.arialyy.aria.core.download.M3U8Entity;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.processor.IVodTsUrlConverter;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import my.project.sakuraproject.util.VideoUtils;

/**
* M3U8下载配置类
*/
public class M3U8DownloadConfig {

/************************************************************ m3u8下载配置 START ************************************************************/
public static class BandWidthUrlConverter implements IBandWidthUrlConverter {
@Override
public String convert(String m3u8Url, String bandWidthUrl) {
try {
URL url = new URL(m3u8Url);
m3u8Url = m3u8Url.replace(url.getPath(), "");
} catch (MalformedURLException e) {
e.printStackTrace();
}
return m3u8Url + bandWidthUrl;
}
}

public static class VodTsUrlConverter implements IVodTsUrlConverter {
@Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
// 转换ts文件的url地址
try {
URL url = new URL(m3u8Url);
m3u8Url = m3u8Url.replace(url.getPath(), "").replaceAll("\\?.*", "");;
} catch (MalformedURLException e) {
e.printStackTrace();
}
List<String> newUrls = new ArrayList<>();
for (String url : tsUrls) {
newUrls.add(url.contains("http") ? url : m3u8Url + url);
}
return newUrls; // 返回有效的ts文件url集合
}
}

public static class TsMergeHandler implements ITsMergeHandler {
public boolean merge(@Nullable M3U8Entity m3U8Entity, List<String> tsPath) {
Log.e("TsMergeHandler", "合并TS....");
String tsKey = m3U8Entity.getKeyPath() == null ? "" : VideoUtils.readKeyInfo(new File(m3U8Entity.getKeyPath()));
byte[] tsIv = m3U8Entity.getIv() == null ? new byte[16] : m3U8Entity.getIv().getBytes();
OutputStream outputStream = null;
InputStream inputStream = null;
FileOutputStream fileOutputStream = null;
List<File> finishedFiles = new ArrayList<>();
for (String path : tsPath) {
try {
File pathFile = new File(path);
if (!tsKey.isEmpty()) {
Log.e("TsMergeHandler", "存在加密");
// 存在加密
inputStream= new FileInputStream(pathFile);
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
fileOutputStream = new FileOutputStream(pathFile);
// 解密ts片段
fileOutputStream.write(VideoUtils.decrypt(bytes, tsKey, tsIv));
}
finishedFiles.add(pathFile);
}catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (outputStream != null) outputStream.close();
if (inputStream != null) inputStream.close();
if (fileOutputStream != null) fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return VideoUtils.merge(m3U8Entity.getFilePath(), finishedFiles);
}
}
/************************************************************ m3u8下载配置 END ************************************************************/
}
Original file line number Diff line number Diff line change
Expand Up @@ -774,15 +774,15 @@ public static void updateDownloadSuccess(String animeTitle, int source, String p
if (path.contains(".m3u8")) {
path = path.replaceAll("m3u8", "mp4");
File file = new File(path);
db.execSQL("update T_DOWNLOAD_DATA set F_COMPLETE = 1, F_PATH=?, F_FILE_SIZE=? where F_LINK_ID=? AND F_TASK_ID=?",
db.execSQL("update T_DOWNLOAD_DATA set F_COMPLETE = 1, F_PATH=?, F_FILE_SIZE=?, F_TASK_ID = -99 where F_LINK_ID=? AND F_TASK_ID=?",
new Object[]{
path,
file.length(),
downloadId,
taskId
});
} else
db.execSQL("update T_DOWNLOAD_DATA set F_COMPLETE = 1, F_PATH=?, F_FILE_SIZE=? where F_LINK_ID=? AND F_TASK_ID=?",
db.execSQL("update T_DOWNLOAD_DATA set F_COMPLETE = 1, F_PATH=?, F_FILE_SIZE=?, F_TASK_ID = -99 where F_LINK_ID=? AND F_TASK_ID=?",
new Object[]{
path,
fileSize,
Expand Down Expand Up @@ -958,9 +958,11 @@ public static List<Object> queryDownloadAnimeInfo(long taskId) {
new String[]{String.valueOf(taskId)});
List<Object> objects = new ArrayList<>();
cursor.moveToNext();
objects.add(cursor.getString(0));
objects.add(cursor.getInt(1));
Log.e("????" , cursor.getString(0) + cursor.getInt(1));
if (cursor.getCount() > 0) {
objects.add(cursor.getString(0));
objects.add(cursor.getInt(1));
Log.e("????" , cursor.getString(0) + cursor.getInt(1));
}
cursor.close();
return objects;
}
Expand Down Expand Up @@ -1063,4 +1065,12 @@ public static void deleteDistinctData(Context context) {
db.execSQL("delete from T_DOWNLOAD_DATA where F_TASK_ID in (select F_TASK_ID from T_DOWNLOAD_DATA group by F_TASK_ID having count(*) > 1) and F_COMPLETE = 0", new String[]{});
db.execSQL("delete from T_DOWNLOAD where F_ID not in (select F_LINK_ID from T_DOWNLOAD_DATA group by F_LINK_ID)", new String[]{});
}

/**
* 删除所有下载记录
*/
public static void deleteAllDownloads() {
db.execSQL("delete from T_DOWNLOAD");
db.execSQL("delete from T_DOWNLOAD_DATA");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ public void showUpdateLogs() {

public List createUpdateLogList() {
List logsList = new ArrayList();
logsList.add(new LogBean("版本:2.3.5", "修复malimali源部分图片显示失败的问题\n修复malimali源分类解析方法\n修复删除下载的视频后下载其他视频时出现TaskId重复导致下载异常闪退的问题,如已出现需删除所有下载记录(设置->清除所有下载记录)\n**malimali源站点搜索功能异常,需等待站点修复"));
logsList.add(new LogBean("版本:2.3.4", "修复malimali源站点UI改版(又变回原来的UI了。。。)导致所有相关解析出错的问题\n修复在下载列表界面中出现下载成功但显示下载失败的问题"));
logsList.add(new LogBean("版本:2.3.3", "malimali域名变更为https://www.malimali6.com\n修复malimali源站点UI改版导致所有相关解析出错的问题\nmalimali源新增当视频地址是链接到腾讯视频等视频网站资源时,在播放失败时选择网页嗅探时加入了几个免费的VIP视频解析接口(不保证长期有效),下载该类型的视频时同理,但不保证一定能嗅探成功\n**由于malimali源站点改版导致部分番剧的地址发生变化可能导致在我的收藏、历史记录等界面操作时出现崩溃的情况,如出现请手动删除相关信息"));
logsList.add(new LogBean("版本:2.3.2", "修复在下载过程中应用异常退出后再进行继续下载时TS转换器被回收导致下载完成后无法合并的问题\n修复Aria下载框架使用不当存在内存泄露的问题\n*本次更新后建议先手动删除所有下载失败的剧集,否则可能出现数据错乱...\n**选择多集批量下载时有时会出现未创建下载任务的情况,如出现该问题请删除未执行下载剧集后自行重新下载"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,7 @@

import com.alibaba.fastjson.JSONObject;
import com.arialyy.aria.core.Aria;
import com.arialyy.aria.core.download.M3U8Entity;
import com.arialyy.aria.core.download.m3u8.M3U8VodOption;
import com.arialyy.aria.core.processor.IBandWidthUrlConverter;
import com.arialyy.aria.core.processor.ITsMergeHandler;
import com.arialyy.aria.core.processor.IVodTsUrlConverter;
import com.bumptech.glide.Glide;
import com.bumptech.glide.load.DecodeFormat;
import com.bumptech.glide.load.model.GlideUrl;
Expand All @@ -43,17 +39,9 @@
import org.greenrobot.eventbus.ThreadMode;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AlertDialog;
import androidx.appcompat.widget.AppCompatTextView;
import androidx.coordinatorlayout.widget.CoordinatorLayout;
Expand Down Expand Up @@ -82,14 +70,13 @@
import my.project.sakuraproject.bean.Event;
import my.project.sakuraproject.bean.Refresh;
import my.project.sakuraproject.bean.YhdmVideoUrlBean;
import my.project.sakuraproject.config.M3U8DownloadConfig;
import my.project.sakuraproject.custom.CustomToast;
import my.project.sakuraproject.custom.MyTextView;
import my.project.sakuraproject.database.DatabaseUtil;
import my.project.sakuraproject.main.animeList.AnimeListActivity;
import my.project.sakuraproject.main.base.BaseActivity;
import my.project.sakuraproject.main.base.BaseModel;
import my.project.sakuraproject.main.search.SearchActivity;
import my.project.sakuraproject.main.tag.MaliTagActivity;
import my.project.sakuraproject.main.video.DownloadVideoContract;
import my.project.sakuraproject.main.video.DownloadVideoPresenter;
import my.project.sakuraproject.main.video.VideoContract;
Expand Down Expand Up @@ -827,9 +814,9 @@ private void createDownloadConfig() {
m3U8VodOption = new M3U8VodOption();
m3U8VodOption.ignoreFailureTs();
m3U8VodOption.setUseDefConvert(false);
m3U8VodOption.setBandWidthUrlConverter(new BandWidthUrlConverter());
m3U8VodOption.setVodTsUrlConvert(new VodTsUrlConverter());
m3U8VodOption.setMergeHandler(new TsMergeHandler());
m3U8VodOption.setBandWidthUrlConverter(new M3U8DownloadConfig.BandWidthUrlConverter());
m3U8VodOption.setVodTsUrlConvert(new M3U8DownloadConfig.VodTsUrlConverter());
m3U8VodOption.setMergeHandler(new M3U8DownloadConfig.TsMergeHandler());
// m3U8VodOption.generateIndexFile();
}

Expand Down Expand Up @@ -943,76 +930,6 @@ public void showSuccessImomoeVideoUrlsView(String url, String playNumber) {
startDownloadService();
});
}
/************************************************************ m3u8下载配置 START ************************************************************/
static class BandWidthUrlConverter implements IBandWidthUrlConverter {
@Override
public String convert(String m3u8Url, String bandWidthUrl) {
try {
URL url = new URL(m3u8Url);
m3u8Url = m3u8Url.replace(url.getPath(), "");
} catch (MalformedURLException e) {
e.printStackTrace();
}
return m3u8Url + bandWidthUrl;
}
}

static class VodTsUrlConverter implements IVodTsUrlConverter {
@Override public List<String> convert(String m3u8Url, List<String> tsUrls) {
// 转换ts文件的url地址
try {
URL url = new URL(m3u8Url);
m3u8Url = m3u8Url.replace(url.getPath(), "").replaceAll("\\?.*", "");;
} catch (MalformedURLException e) {
e.printStackTrace();
}
List<String> newUrls = new ArrayList<>();
for (String url : tsUrls) {
newUrls.add(url.contains("http") ? url : m3u8Url + url);
}
return newUrls; // 返回有效的ts文件url集合
}
}

static class TsMergeHandler implements ITsMergeHandler {
public boolean merge(@Nullable M3U8Entity m3U8Entity, List<String> tsPath) {
Log.e("TsMergeHandler", "合并TS....");
String tsKey = m3U8Entity.getKeyPath() == null ? "" : VideoUtils.readKeyInfo(new File(m3U8Entity.getKeyPath()));
byte[] tsIv = m3U8Entity.getIv() == null ? new byte[16] : m3U8Entity.getIv().getBytes();
OutputStream outputStream = null;
InputStream inputStream = null;
FileOutputStream fileOutputStream = null;
List<File> finishedFiles = new ArrayList<>();
for (String path : tsPath) {
try {
File pathFile = new File(path);
if (!tsKey.isEmpty()) {
Log.e("TsMergeHandler", "存在加密");
// 存在加密
inputStream= new FileInputStream(pathFile);
byte[] bytes = new byte[inputStream.available()];
inputStream.read(bytes);
fileOutputStream = new FileOutputStream(pathFile);
// 解密ts片段
fileOutputStream.write(VideoUtils.decrypt(bytes, tsKey, tsIv));
}
finishedFiles.add(pathFile);
}catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (outputStream != null) outputStream.close();
if (inputStream != null) inputStream.close();
if (fileOutputStream != null) fileOutputStream.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
return VideoUtils.merge(m3U8Entity.getFilePath(), finishedFiles);
}
}
/************************************************************ m3u8下载配置 END ************************************************************/

/**
* 创建下载任务
Expand Down
Loading

0 comments on commit e826420

Please sign in to comment.