解析
解析使用wuxianlin的GetVideo软件,打开后选择爱奇艺,输入视频链接或者直接搜索
软件地址:GetVideo
复制图中720p H265的链接,注意此链接有时效性。
复制到浏览器打开可见是m3u8的文件内容
除过#开头的行,其余行就是视频每个分段的真实地址,一个40分钟的电视剧硬是分成10秒左右的短片。
注意:解析1080p,或者会员影视需在设置中设置UID.......
下载
直接放我Java写的小工具,输入解析后的链接就可以下载了
文件:iqiyi.java
package com.ruanun.down;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
public class iqiyi {
public static ArrayList<String> getTsUrlList(String m3u8Url) throws IOException {
URL url = new URL(m3u8Url);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
conn.setConnectTimeout(10*1000);
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//System.out.println(conn.getResponseCode());
InputStream is = conn.getInputStream();
BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
ArrayList<String> tsUrlList = new ArrayList<>();
String temp = "";
while ((temp = br.readLine()) != null)
{
if (jing(temp)) //这一行第一个字符为#跳过,我们只要需要ts切片链接
continue;
if (temp.equals(""))
continue;
tsUrlList.add(temp);
}
is.close();
br.close();
//System.out.println("ok!");
//System.out.println("count:" + tsUrlList.size());
return tsUrlList;
}
public static boolean jing(String str)
{
if (str.charAt(0)=='#')
return true;
return false;
}
}
文件:down.java
package com.ruanun.down;
import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.ArrayList;
public class down {
/**
* 从网络Url中下载文件
* @param urlStr
* @param fileName
* @param savePath
* @throws IOException
*/
public static void downLoadFromUrl(String urlStr,String fileName,String savePath) throws IOException{
URL url = new URL(urlStr);
HttpURLConnection conn = (HttpURLConnection)url.openConnection();
//设置超时间为10秒
conn.setConnectTimeout(10*1000);
//防止屏蔽程序抓取而返回403错误
conn.setRequestProperty("User-Agent", "Mozilla/4.0 (compatible; MSIE 5.0; Windows NT; DigExt)");
//得到输入流
InputStream inputStream = conn.getInputStream();
//获取自己数组
byte[] getData = readInputStream(inputStream);
//文件保存位置
File saveDir = new File(savePath);
if(!saveDir.exists()){
saveDir.mkdir();
}
File file = new File(saveDir+File.separator+fileName);
FileOutputStream fos = new FileOutputStream(file);
fos.write(getData);
if(fos!=null){
fos.close();
}
if(inputStream!=null){
inputStream.close();
}
System.out.println("info:download success");
}
/**
* 从输入流中获取字节数组
* @param inputStream
* @return
* @throws IOException
*/
public static byte[] readInputStream(InputStream inputStream) throws IOException {
byte[] buffer = new byte[1024];
int len = 0;
ByteArrayOutputStream bos = new ByteArrayOutputStream();
while((len = inputStream.read(buffer)) != -1) {
bos.write(buffer, 0, len);
}
bos.close();
return bos.toByteArray();
}
public static void main(String[] args) {
try{
//从getVideo中获取的链接
String m3u8Url = "http://cache.m.iqiyi.com/mus/text/204466001/66695c128d8b2249a0b29c71d0bc491c/afbe8fd3d73448c9//20170518/b8/3f/5a32fcef82d9cd34d060cb540cff6869.m3u8?qd_originate=tmts_py&tvid=599329200&bossStatus=0&qd_vip=0&px=&qd_src=b85da1cf3ae44351&prv=&previewType=&previewTime=&from=&qd_time=1532580482923&qd_p=01519d9b&qd_asc=a0baca7bb6b0fef92856a8a3b4384ca3&qypid=599329200_04000000001000000000_17&qd_k=512322ec43d060b6bc0f7114b1b4ba53&isdol=0&code=1&iswb=0&vf=35d6b23b036120912c1e627e2e436c80&np_tag=nginx_part_tag";
String savePath = "C:\\Users\\Ruanun\\Desktop\\temp"; //保存文件的路径
ArrayList<String> list = iqiyi.getTsUrlList(m3u8Url);
System.out.println("url Count:" + list.size());
int waitCount = 0;
for (int i = 0; i<5; i++)
{
waitCount++;
System.out.println("nummber " + i);
System.out.println("download.....");
downLoadFromUrl(list.get(i), i+".ts", savePath);
if (waitCount==50) //每下载50个就停止60秒
{
System.out.println("waiting.....");
Thread.sleep(60000);
}
}
}catch (Exception e) {
// TODO: handle exception
e.printStackTrace();
}
}
}
运行后效果图
可见一共499个url,一集40分钟电视剧分成499个片段。
下载的文件
合并
视频合并这时候,首选FFmpeg
链接:http://ffmpeg.org/download.html
这东西很厉害,全平台可用。windows下安装很简单,就不说了。
合并方法
ffmpeg -f concat -i list.txt -c copy output.ts
其中list.txt文件,对要合并的视频片段进行了描述
例子:
file 01.ts
file 02.ts
file 03.ts
结束
合并后就可以愉快的观看了。。。
下图就是我从爱奇艺下载的电影《肖申克的救赎》
最后,好像FFmpeg可用直接下载m3u8的视频,不过咋这个可用控制下载的片段。
ffmpeg -i m3u8链接 "保存视频01.mp4"
没有评论