B站视频下载合并

阅读: 评论:0

B站视频下载合并

B站视频下载合并

前提

        需要安装FFmpeg环境才可以生产文件

1、依赖

<dependency><groupId>al.google</groupId><artifactId>android-json</artifactId><version>0.0.20131108.vaadin1</version>
</dependency>

2、util

package util;import org.json.JSONException;
import org.json.JSONObject;import java.io.BufferedReader;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import java.nio.charset.StandardCharsets;/*** @version 1.0*/
public class JsonUtil {/*** 获取json对象** @param path json文件所在路径* @return JSONObject*/private static JSONObject getJSONObject(String path) throws JSONException {char[] c = new char[1024 * 5];int len = 0;try {BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(path), StandardCharsets.UTF_8));len = ad(c);reader.close();} catch (Exception e) {e.printStackTrace();}String json = new String(c, 0, len);return new JSONObject(json);}/*** 获取json对象中的指定json对象的键的值中的指定的键的值,值的类型为String类型** @param path      json文件所在的路径* @param objetName json对象中的json对象的键* @param jsonName  json对象中的键* @return java.lang.String*/public static String dataStringTreat(String path, String objetName, String jsonName) throws JSONException {JSONObject object = getJSONObject(path);JSONObject jsonObject = JSONObject(objetName);String(jsonName).replaceAll(" ", "");}/*** 获取json对象的键的值,且值为Integer** @param path      json文件所在的路径* @param objetName json对象中的json对象的键* @param jsonName  json对象中的键* @return java.lang.Integer*/public static Integer dataIntTreat(String path, String objetName, String jsonName) throws JSONException {JSONObject object = getJSONObject(path);JSONObject jsonObject = JSONObject(objetName);Int(jsonName);}}

3、具体实现

package bibi;import util.JsonUtil;import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;/*** @version 1.0*/
public class BiBi {private static final String PAGE_DATA = "page_data";private static final String DOWNLOAD_SUBTITLE = "download_subtitle";private static final String CID = "cid";private static final String VIDEO = "video.m4s";private static final String AUDIO = "audio.m4s";private static final String Y = "Y";private static int DECIDE = -1;private static final String[] STRINGS = new String[2];private static final Scanner SCANNER = new Scanner(System.in);private static String CUT;private static String VIDEO_PATH;private static String AUDIO_PATH;/*** 执行**/public void execute() {System.out.print("路径:");String path = Line();alter(path);Map<Integer, String> mateName = mateName(path, new HashMap<>(10));Map<String, String> matePath = matePath(path, new HashMap<>(10));write(matePath, mateName);}/*** 修改文件** @param path 路径*/private void alter(String path) {File[] files = new File(path).listFiles();int line = 0;if (files != null) {for (File file : files) {File newFileName = new File(path + "\" + Name().Name().indexOf("_") + 1));boolean b = ameTo(newFileName);if (b) {line++;}if (line == files.length - 1) {System.out.println(path + "目录下的文件全部修改成功");}}}}/*** 名字匹配** @param path 路径* @param map  存储名字匹配* @return java.util.Map<java.lang.Integer, java.lang.String>*/private Map<Integer, String> mateName(String path, Map<Integer, String> map) {File[] files = new File(path).listFiles();if (files != null) {for (File file : files) {if (!file.isDirectory()) {if (Name().toLowerCase().endsWith("entry.json")) {try {String oldFileName = JsonUtil.AbsolutePath(), PAGE_DATA, DOWNLOAD_SUBTITLE).replaceAll("&", "-");Integer filePath = JsonUtil.AbsolutePath(), PAGE_DATA, CID);String newFileName = cut(oldFileName);map.put(filePath, newFileName);} catch (Exception e) {System.out.AbsolutePath());}}} else {AbsolutePath(), map);}}}return map;}/*** 路径匹配** @param path 路径* @param map  存储路径匹配* @return java.util.Map<java.lang.String, java.lang.String>*/private Map<String, String> matePath(String path, Map<String, String> map) {File[] files = new File(path).listFiles();if (files != null) {for (File file : files) {if (!file.isDirectory()) {if (Name().equals(AUDIO)) {AUDIO_PATH = AbsolutePath();}if (Name().equals(VIDEO)) {VIDEO_PATH = AbsolutePath();}if (VIDEO_PATH != null && AUDIO_PATH != null) {map.put(VIDEO_PATH, AUDIO_PATH);VIDEO_PATH = null;AUDIO_PATH = null;}} else {AbsolutePath(), map);}}}return map;}/*** 创建一个文件,写入需要的数据** @param matePath 路径匹配* @param mateName 名字匹配*/private void write(Map<String, String> matePath, Map<Integer, String> mateName) {try {System.out.print("请输入合并之后的文件路径:");String path = Line();String newPath = path + "\" + path.substring(path.lastIndexOf("\") + 1) + ".txt";File file = new File(newPath);File parentFile = ParentFile();if (!ists()) {boolean mkdirs = parentFile.mkdirs();if (mkdirs) {System.out.println(newPath + "目录创建成功");}boolean newFile = ateNewFile();if (newFile) {System.out.println(path.substring(path.lastIndexOf("\") + 1) + ".txt文件创建成功");}}BufferedWriter bufferedWriter = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(newPath), StandardCharsets.UTF_8));List<Integer> listName = getSetListName(mateName);List<String> listPath = getSetListPath(matePath);if (listName.size() == listPath.size()) {for (String string : listPath) {for (Integer integer : listName) {if (String())) {bufferedWriter.write("FFmpeg -i " + string + " -i " + (string) + " -codec copy " + path + "\" + (integer) + ".mp4");bufferedWriter.write("rn");}}}}System.out.println(path.substring(path.lastIndexOf("\") + 1) + "的需要的数据写入成功!");bufferedWriter.close();DECIDE = -1;} catch (Exception e) {e.printStackTrace();}}/*** 拿出路径匹配中的键,形成list集合** @param matePath 路径匹配* @return java.util.List<java.lang.String>*/private List<String> getSetListPath(Map<String, String> matePath) {Set<String> matePathSet = matePath.keySet();return new ArrayList<>(matePathSet);}/*** 拿出名字匹配中的键,形成list集合** @param mateName 名字匹配* @return java.util.List<java.lang.Integer>*/private List<Integer> getSetListName(Map<Integer, String> mateName) {Set<Integer> mateNameSet = mateName.keySet();return new ArrayList<>(mateNameSet);}/*** 数据处理** @param string 需要处理的数据* @return java.lang.String*/private String cut(String string) {if (DECIDE == -1) {System.out.println("示例:" + string);System.out.print("是否需要截取(Y/N):");CUT = Line();DECIDE++;}if (Y.equals(CUT)) {if (DECIDE == 0) {System.out.print("输入数字之前的部分:");STRINGS[0] = Line();System.out.print("输入数字和内容之间的部分:");STRINGS[1] = Line();DECIDE++;}if ("".equals(STRINGS[1])) {return string.substring(STRINGS[0].length());}String number = string.substring(STRINGS[0].length());return "第" + placeFirst(STRINGS[1], "节-");}return string;}}

4、说明
        执行完会生产一个txt文件,将txt更改后缀名为bat,并修改文件保存编码,即可运行

本文发布于:2024-02-04 05:38:02,感谢您对本站的认可!

本文链接:https://www.4u4v.net/it/170700260652680.html

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。

标签:视频下载
留言与评论(共有 0 条评论)
   
验证码:

Copyright ©2019-2022 Comsenz Inc.Powered by ©

网站地图1 网站地图2 网站地图3 网站地图4 网站地图5 网站地图6 网站地图7 网站地图8 网站地图9 网站地图10 网站地图11 网站地图12 网站地图13 网站地图14 网站地图15 网站地图16 网站地图17 网站地图18 网站地图19 网站地图20 网站地图21 网站地图22/a> 网站地图23