且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

自己开发的在线视频下载工具,基于Java多线程

更新时间:2022-09-12 13:40:35

自己开发的在线视频下载工具,基于Java多线程这个片段的url:


http://d2vvqvds83fsd.cloudfront.net/vin02/vsmedia/definst/smil:event/18/36/06/3/rt/1/resources/180919_PID_Intelligent_Enterprise_Gruenewald_720p-5F92.smil/media_b433000_10.ts


那么这个片段一共有多少个片段呢?在所有片段开始下载之前,有这样一个请求:chunklist即是视频片段的清单。

自己开发的在线视频下载工具,基于Java多线程

自己开发的在线视频下载工具,基于Java多线程

private void download(){

URL task = null;

String path = DownloadLauncher.LOCALPATH + this.mIndex +

DownloadLauncher.POSTFIX;

String url = this.mTask;

try {

task = new URL(url);

DataInputStream dataInputStream = new DataInputStream(task.openStream());

FileOutputStream fileOutputStream = new FileOutputStream(new File(path));

ByteArrayOutputStream output = new ByteArrayOutputStream();

byte[] buffer = new byte[1024];

int length;

while ((length = dataInputStream.read(buffer)) > 0) {

output.write(buffer, 0, length);

}

fileOutputStream.write(output.toByteArray());

dataInputStream.close();

fileOutputStream.close();

System.out.println("File: " + this.mIndex + " downloaded ok");

}

catch (MalformedURLException e) {

e.printStackTrace();

}

catch (IOException e) {

e.printStackTrace();

}

}

自己开发的在线视频下载工具,基于Java多线程

自己开发的在线视频下载工具,基于Java多线程

private static void run() throws IOException{

FileInputStream in = null;

String destFile = DownloadLauncher.LOCALPATH +

DownloadLauncher.MERGED;

FileOutputStream out = new FileOutputStream(destFile,true);

for( int i = 0; i <= DownloadLauncher.LAST; i++){

byte[] buf = new byte[1024];

int len = 0;

String sourceFile = DownloadLauncher.LOCALPATH + i +

DownloadLauncher.POSTFIX;

in = new FileInputStream(sourceFile);

while( (len = in.read(buf)) != -1 ){

out.write(buf,0,len);

}

}

out.close();

}

public static void main(String[] args) {

try {

run();

} catch (IOException e) {

e.printStackTrace();

}

System.out.println("Merged ok!");

}

自己开发的在线视频下载工具,基于Java多线程

完整的代码在我的github上:

https://github.com/i042416/JavaTwoPlusTwoEquals5/tree/master/src/flick