Skip to content

Commit

Permalink
feat: FFMPEG支持win_amd64linux_amd64win_arm64linux_arm64
Browse files Browse the repository at this point in the history
  • Loading branch information
nICEnnnnnnnLee committed Jan 24, 2024
1 parent 72d1460 commit b7d5fba
Show file tree
Hide file tree
Showing 5 changed files with 104 additions and 25 deletions.
31 changes: 26 additions & 5 deletions src/nicelee/bilibili/downloaders/impl/FFmpegDownloader.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import nicelee.bilibili.util.Encrypt;
import nicelee.bilibili.util.Logger;
import nicelee.bilibili.util.ResourcesUtil;
import nicelee.bilibili.util.SysUtil;

@Bilibili(name = "ffmpeg-downloader", weight = 22, type = "downloader", note = "ffmpeg下载")
public class FFmpegDownloader extends FLVDownloader {
Expand All @@ -21,6 +22,22 @@ public boolean matches(String url) {
return false;
}

String getSHA1(String os_arch) {
Logger.println(os_arch);
switch (os_arch) {
case "linux_amd64":
return "c396604b9c58e7164de1b79a11148c1ece3f4799";
case "linux_arm64":
return "97f718893509d37810c7c6bf759ee16398fdfc59";
case "win_amd64":
return "2d53419420c7f3d473cbd2c6827ce9347436520f";
case "win_arm64":
return "fe49da6125ec5e10441f1eda2976cc5734d06d47";
default:
return "";
}
}

/**
* 下载matches
*
Expand All @@ -32,18 +49,22 @@ public boolean matches(String url) {
*/
@Override
public boolean download(String url, String avId, int qn, int page) {
Logger.println("url:" + url);
String ffmpegEXE = "ffmpeg" + SysUtil.getEXE_SUFFIX();
convertingStatus = StatusEnum.NONE;
currentTask = 1;
if(file == null) {
file = ResourcesUtil.sourceOf("ffmpeg.exe");
if (file == null) {
file = ResourcesUtil.sourceOf(ffmpegEXE);
}
util.setSavePath(ResourcesUtil.baseDirectory());
boolean succ = util.download(url, "ffmpeg.exe", new HashMap<>());
boolean succ = util.download(url, ffmpegEXE, new HashMap<>());
if (succ) {
String sha1 = Encrypt.SHA1(util.getFileDownload());
Logger.println("url:" + url);
Logger.println("文件sha1:" + sha1);
if(!"8e633e3cedcc0ddd4c83509d959b70932400b591".equalsIgnoreCase(sha1)) {
String os_arch = String.format("%s_%s", SysUtil.getOS(), SysUtil.getARCH());
String expectedSha1 = getSHA1(os_arch);
Logger.println("期望的文件sha1:" + expectedSha1);
if (!expectedSha1.equals(sha1)) {
JOptionPane.showMessageDialog(null, "ffmpeg.exe已经下载完成, 但SHA1不匹配!!", "警告!!",
JOptionPane.WARNING_MESSAGE);
throw new RuntimeException("ffmpeg.exe SHA1不匹配");
Expand Down
19 changes: 10 additions & 9 deletions src/nicelee/bilibili/parsers/impl/FFmpegParser.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
import nicelee.bilibili.model.ClipInfo;
import nicelee.bilibili.model.VideoInfo;
import nicelee.bilibili.util.Logger;
import nicelee.bilibili.util.SysUtil;
import nicelee.ui.Global;

@Bilibili(name = "FFmpeg", note = "用于FFmpeg下载")
public class FFmpegParser extends AbstractBaseParser {


public FFmpegParser(Object... obj) {
super(obj);
}

@Override
public boolean matches(String input) {
return "ffmpeg".equals(input.trim().toLowerCase());
Expand All @@ -26,21 +26,22 @@ public boolean matches(String input) {
public String validStr(String input) {
return input;
}



@Override
public String getVideoLink(String avId, String cid, int qn, int downFormat) {
this.paramSetter.setRealQN(1000);
return getDownUrl();
}

private String getDownUrl() {
Logger.println("当前使用的更新源为: " + Global.ffmpegSourceActive);
String key = "bilibili.download.ffmpeg.url." + Global.ffmpegSourceActive;
String url = Global.settings.getOrDefault(key, "https://github.com/nICEnnnnnnnLee/BilibiliDown/releases/download/V4.5/ffmpeg.exe");
String url = Global.settings.get(key);
url = url.replace("{os}", SysUtil.getOS()).replace("{arch}", SysUtil.getARCH()).replace("{exeSuffix}",
SysUtil.getEXE_SUFFIX());
return url;
}

@Override
public VideoInfo result(String input, int videoFormat, boolean getVideoLink) {
VideoInfo vInfos = new VideoInfo();
Expand All @@ -58,11 +59,11 @@ public VideoInfo result(String input, int videoFormat, boolean getVideoLink) {
clip.setTitle("FFmpeg");
clip.setPage(1);
HashMap<Integer, String> links = new HashMap<Integer, String>();
links.put(1000, "");
links.put(799, "");
clip.setUpId("nICEnnnnnnnLee");
clip.setUpName("nICEnnnnnnnLee");
clip.setLinks(links);

clips.put(1234L, clip);
vInfos.setClips(clips);
return vInfos;
Expand Down
59 changes: 59 additions & 0 deletions src/nicelee/bilibili/util/SysUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package nicelee.bilibili.util;

public class SysUtil {
static String OS;
static String ARCH;
static String EXE_SUFFIX;

public static boolean surportFFmpegOfficially() {
String os_arch = String.format("%s_%s", SysUtil.getOS(), SysUtil.getARCH());
switch (os_arch) {
case "linux_amd64":
case "linux_arm64":
case "win_amd64":
case "win_arm64":
return true;
default:
return false;
}
}

public static String getOS() {
if (OS == null) {
String osName = System.getProperty("os.name").toLowerCase();
Logger.println(osName);
if (osName.startsWith("win"))
OS = "win";
else if (osName.startsWith("linux"))
OS = "linux";
else
OS = "unknown";
}
return OS;
}

public static String getARCH() {
if (ARCH == null) {
String arch = System.getProperty("os.arch").toLowerCase();
Logger.println(arch);
if (arch.equals("amd64") || arch.equals("x86_64"))
ARCH = "amd64";
else if (arch.equals("arm64") || arch.equals("aarch64"))
ARCH = "arm64";
else
ARCH = "unknown";
}
return ARCH;
}

public static String getEXE_SUFFIX() {
if (EXE_SUFFIX == null) {
if ("win".equals(getOS()))
EXE_SUFFIX = ".exe";
else
EXE_SUFFIX = "";
}
return EXE_SUFFIX;
}

}
7 changes: 3 additions & 4 deletions src/nicelee/ui/FrameMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
import nicelee.bilibili.util.Logger;
import nicelee.bilibili.util.RepoUtil;
import nicelee.bilibili.util.ResourcesUtil;
import nicelee.bilibili.util.SysUtil;
import nicelee.ui.item.MJTitleBar;
import nicelee.ui.thread.CookieRefreshThread;
import nicelee.ui.thread.DownloadRunnable;
Expand All @@ -44,9 +45,7 @@ public class FrameMain extends JFrame {
public static void main(String[] args) {
System.out.println();
// System.getProperties().setProperty("file.encoding", "utf-8");
String osName = System.getProperty("os.name");
boolean isWindows = osName.startsWith("Windows");
System.out.println(osName);
boolean isFFmpegSurported = SysUtil.surportFFmpegOfficially();
System.out.println("Java version:" + System.getProperty("java.specification.version"));
System.out.println(ResourcesUtil.baseDirectory());
// 读取配置文件
Expand Down Expand Up @@ -113,7 +112,7 @@ public static void main(String[] args) {
String ffmpeg = ResourcesUtil.resolve(Global.ffmpegPath);
String[] cmd = new String[] { ffmpeg, "-version" };
if (!CmdUtil.run(cmd)) {
if (isWindows) {
if (isFFmpegSurported) {
Object[] options = { "是", "否" };
int m = JOptionPane.showOptionDialog(null,
"检测到当前没有ffmpeg环境, mp4及小部分flv文件将无法转码或合并.\r\n 是否下载ffmpeg(自编译, 3M左右)?", "请选择:",
Expand Down
13 changes: 6 additions & 7 deletions src/resources/app.config
Original file line number Diff line number Diff line change
Expand Up @@ -107,14 +107,13 @@ bilibili.download.update.patterns.Supabase = https://vezfoeoqirnvcqsuiext.supaba
bilibili.download.update.patterns.Cloudinary = https://res.cloudinary.com/dcrcvyjzu/raw/upload/bili/{file}
bilibili.download.update.patterns.Twicpics = https://bilibili.twic.pics/release/V{version}/{file}
# ffmpeg源设置
bilibili.download.ffmpeg.sources = Github|Bitbucket|Supabase|Cloudinary|Imagekit|Twicpics
bilibili.download.ffmpeg.sources = Github|Bitbucket|Supabase|Cloudinary|Twicpics
bilibili.download.ffmpeg.sources.active = Bitbucket
bilibili.download.ffmpeg.url.Github = https://github.com/nICEnnnnnnnLee/BilibiliDown/releases/download/V4.5/ffmpeg_N-108857-g00b03331a0-20221027.exe
bilibili.download.ffmpeg.url.Bitbucket = https://bitbucket.org/niceleeee/bilibilidown/downloads/ffmpeg_N-108857-g00b03331a0-20221027.exe
bilibili.download.ffmpeg.url.Supabase = https://vezfoeoqirnvcqsuiext.supabase.co/storage/v1/object/public/bili/release/ffmpeg_N-108857-g00b03331a0-20221027.exe
bilibili.download.ffmpeg.url.Cloudinary = https://res.cloudinary.com/dcrcvyjzu/raw/upload/bili/ffmpeg_N-108857-g00b03331a0-20221027
bilibili.download.ffmpeg.url.Imagekit = https://ik.imagekit.io/n1ce/release/ffmpeg_N-108857-g00b03331a0-20221027.exe
bilibili.download.ffmpeg.url.Twicpics = https://bilibili.twic.pics/release/V4.5/ffmpeg_N-108857-g00b03331a0-20221027.exe
bilibili.download.ffmpeg.url.Github = https://github.com/nICEnnnnnnnLee/BilibiliDown/releases/download/V4.5/ffmpeg-20240123-{os}-{arch}{exeSuffix}
bilibili.download.ffmpeg.url.Bitbucket = https://bitbucket.org/niceleeee/bilibilidown/downloads/ffmpeg-20240123-{os}-{arch}{exeSuffix}
bilibili.download.ffmpeg.url.Supabase = https://vezfoeoqirnvcqsuiext.supabase.co/storage/v1/object/public/bili/release/ffmpeg-20240123-{os}-{arch}{exeSuffix}
bilibili.download.ffmpeg.url.Cloudinary = https://res.cloudinary.com/dcrcvyjzu/raw/upload/bili/ffmpeg-20240123-{os}-{arch}
bilibili.download.ffmpeg.url.Twicpics = https://bilibili.twic.pics/release/V4.5/ffmpeg-20240123-{os}-{arch}{exeSuffix}
#######################################################################################################
# 批量下载设置
## 0 下载每个tab页的第一个视频; 1 下载每个Tab页的全部视频
Expand Down

0 comments on commit b7d5fba

Please sign in to comment.