网易云的MV下载

最近想把自己喜欢的MV放在个人站点上面,但是Mac客户端和网页版的网易云连个下载按钮都没有!好吧, 是时候自己动手…丰衣足食了,网页上能播放出来的肯定是能拿到的,最神奇最稳定的办法当然是开启录屏软件啦。但是本次为了播放效果,能不用最低端的方式就尽量不用啦!

很久没写过IO方面的东西了,现在拿这个例子来练练手:

mark

我们要拿到的无非就是HTTP的请求链接和请求头信息:

mark
public static void main(String[] args) throws Exception{
//请输入视频地址
String url = "https://vodkgeyttp8.vod.126.net/cloudmusic/MCQ4IjAxICAwICEhICAgIQ==/294001/672888e4902fac1298f8e984182690c7.mp4?wsSecret=809e59d2b289d82917dedef9c05c64b2&wsTime=1556853453";

File file = new File("/Users/tim/Desktop/a"+".mp4");
//创建文件
if(!file.createNewFile()) throw new RuntimeException("文件创建失败");

HttpURLConnection con;
FileOutputStream fs = null;
InputStream is;
BufferedInputStream bs = null;

try {
con = (HttpURLConnection) new URL(url).openConnection();
con.setRequestProperty("User-Agent", "Mozilla/5.0 (Macintosh; Intel Mac OS X 10_14_0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/74.0.3729.131 Safari/537.36");

//输入流
is = con.getInputStream();
bs = new BufferedInputStream(is);
fs = new FileOutputStream(file);
byte[] bytes = new byte[1024 * 10];

int line ;
while((line = bs.read(bytes))!= -1){
fs.write(bytes, 0, line);
fs.flush();
}

} catch (Exception e) {
e.printStackTrace();
} finally{
if(fs!= null){
try {
fs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
if(bs!=null){
try {
bs.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}

好了,首页的MV就是这样完成了下载,所以想要下载MV就是这么简单!

mark
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值