This repository has been archived by the owner on Apr 3, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 117
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
670848654
committed
Aug 1, 2022
1 parent
0d580ae
commit e826420
Showing
15 changed files
with
316 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
47 changes: 47 additions & 0 deletions
47
app/src/main/java/my/project/sakuraproject/bean/DownloadEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
100 changes: 100 additions & 0 deletions
100
app/src/main/java/my/project/sakuraproject/config/M3U8DownloadConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 ************************************************************/ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.