欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

《2019/04/12》java下载抖音视频

程序员文章站 2022-04-11 17:09:30
...

java下载抖音视频

下载抖音视频,获取到抖音视频的下载地址之后,类似:

String url = "https://aweme.snssdk.com/aweme/v1/play/?video_id=v0300fbd0000bhkfgq7jofsleq3pk120&line=0&ratio=540p&watermark=1&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0&logo_name=aweme";

使用URLConnection不能直接下来,使用OkHttp则可以:
添加pom依赖:

<dependency>
    <groupId>com.squareup.okhttp3</groupId>
    <artifactId>okhttp</artifactId>
    <version>3.13.1</version>
</dependency>
	@RequestMapping(value = "/getVideo")
    public void test(HttpServletResponse res) throws IOException{

        String url = "https://aweme.snssdk.com/aweme/v1/play/?video_id=v0300fbd0000bhkfgq7jofsleq3pk120&line=0&ratio=540p&watermark=1&media_type=4&vr_type=0&test_cdn=None&improve_bitrate=0&logo_name=aweme";
        OkHttpClient client = new OkHttpClient();
        Request request = new Request.Builder()
                .url(url)
                .get()
                .build();
        Response response = client.newCall(request).execute();
        //创建接收文件的流
        //File file = new File( "D:\\" + fileName + ".mp4");
        //OutputStream outputStream = new FileOutputStream(file);

        OutputStream outputStream = res.getOutputStream();
        //将responseBody截取并写入到指定文件路径下
        outputStream.write(response.body().bytes());
        outputStream.flush();
        outputStream.close();
    }
相关标签: 抖音视频 OkHttp