- import jodd.io.FileUtil;
- import jodd.io.NetUtil;
- import jodd.lagarto.dom.jerry.Jerry;
- import jodd.lagarto.dom.jerry.JerryFunction;
- import jodd.util.SystemUtil;
- import java.io.File;
- import java.io.IOException;
- /**
- * 用于解析音乐台http://www.yinyuetai.com/悦单视频地址.
- */
- public class JerryYinyuetai {
- /**
- * 悦单视频播放地址.
- */
- public static String pageUrl = "http://www.yinyuetai.com/playlist/354927";
- /**
- * 视频下载地址连接串.
- */
- public static StringBuilder hrefSb = new StringBuilder();
- /**
- * 提取的视频下载地址及名称写入html文件.
- */
- public static String genHtml = "F:/音悦台/音乐台视频下载.html";
- public static void main(String[] args) throws IOException {
- File file = new File(SystemUtil.getTempDir(), "yinyuetai.html");
- NetUtil.downloadFile(pageUrl, file);
- Jerry doc = Jerry.jerry(FileUtil.readString(file));
- // System.out.println("视频个数=" + doc.$("#mvlist li").length());
- doc.$("#mvlist li").each(new JerryFunction() {
- public boolean onNode(Jerry jerry, int i) {
- String url = jerry.$("span[name=videoUrl]").html();
- hrefSb.append("<br/><a href=\\"" + url.substring(0, url.indexOf("?sc=")) + "\\">" + jerry.$("span strong").html() + "</a>\\n");
- return true;
- }
- });
- // 将提取的视频地址写入html.
- FileUtil.writeBytes(genHtml, hrefSb.toString().getBytes());
- }
- }
- import jodd.io.FileUtil;
- import jodd.lagarto.dom.jerry.Jerry;
- import jodd.lagarto.dom.jerry.JerryFunction;
- import java.io.File;
- import java.io.IOException;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * 用于对音乐台http://www.yinyuetai.com/下载的视频进行重命名.
- */
- public class JerryYinyuetaiRenameFile {
- /**
- * 视频存储地址.
- */
- public static String downloadDir = "F:/音悦台/雅尼 - 命运的神力,让我重拾本真/";
- /**
- * 视频编码字符名称对应文字名称map.
- */
- public static Map<String, String> map = new HashMap<String, String>();
- public static void main(String[] args) throws IOException {
- // 解析提取视频地址html
- Jerry doc = Jerry.jerry(FileUtil.readString(new File(JerryYinyuetai.genHtml)));
- doc.$("a").each(new JerryFunction() {
- public boolean onNode(Jerry jerry, int i) {
- String url = jerry.attr("href");
- url = url.substring(url.lastIndexOf("/") + 1);
- String name = jerry.html();
- // 替换<为<,替换>为>
- name = name.replaceAll("<", "<").replaceAll(">", ">");
- // 替换掉斜杠/
- name = name.replaceAll("/", "");
- // 替换<为《,替换>为》
- name = name.replaceAll("<", "《").replaceAll(">", "》");
- map.put(url, name + ".flv");
- return true;
- }
- });
- File[] files = new File(downloadDir).listFiles();
- for (File file : files) {
- if (map.get(file.getName()) != null) {
- file.renameTo(new File(downloadDir + map.get(file.getName())));
- }
- }
- }
- }
- //该片段来自于http://www.codesnippet.cn/detail/121220137977.html
来源: http://www.codesnippet.cn/detail/121220137977.html