抖音去水印


//获取视频链接
String url="https://v.douyin.com/efKYWbU/"
//获取视频mid
String mid=HttpUtil.createGet(url).addHeaders(headers).execute().header("Location").split("/")[5];

//通过视频mid获取视频详情
String body= HttpUtil.createGet("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+mid).addHeaders(headers).execute().body();
 
  1 {
  2     "status_code": 0,
  3     "item_list": [{
  4         "share_info": {
  5             "share_weibo_desc": "#在抖音,记录美好生活##河南 #安阳 宝宝玩耍胳膊脱臼,还没有来得及哭,正骨师傅就治好了@抖音小助手",
  6             "share_desc": "在抖音,记录美好生活",
  7             "share_title": "#河南 #安阳 宝宝玩耍胳膊脱臼,还没有来得及哭,正骨师傅就治好了@抖音小助手"
  8         },
  9         "risk_infos": {
 10             "type": 0,
 11             "content": "",
 12             "warn": false
 13         },
 14         "author_user_id": 103678413906,
 15         "label_top_text": null,
 16         "group_id": 6963185692679736000,
 17         "create_time": 1621401607,
 18         "share_url": "https://www.iesdouyin.com/share/video/6963866852413984007/?region=&mid=6963867018181462792&u_code=48&titleType=title&did=MS4wLjABAAAANwkJuWIRFOzg5uCpDRpMj4OX-QryoDgn-yYlXQnRwQQ&iid=MS4wLjABAAAANwkJuWIRFOzg5uCpDRpMj4OX-QryoDgn-yYlXQnRwQQ&with_sec_did=1",
 19         "statistics": {
 20             "aweme_id": "6963866852413984007",
 21             "comment_count": 191,
 22             "digg_count": 107938,
 23             "play_count": 0,
 24             "share_count": 204
 25         },
 26         "aweme_type": 4,
 27         "is_preview": 0,
 28         "is_live_replay": false,
 29         "images": null,
 30         "author": {
 31             "avatar_larger": {
 32                 "uri": "1080x1080/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351",
 33                 "url_list": ["https://p6.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172", "https://p9.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172", "https://p26.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172"]
 34             },
 35             "unique_id": "hntvzmd",
 36             "followers_detail": null,
 37             "uid": "103678413906",
 38             "short_id": "1362266613",
 39             "nickname": "河南广播电视台驻马店站",
 40             "signature": "求助帮忙爆料请先关注\n并添加VX:hntvzmdnews\n注明:时间+地点+事件+联系电话",
 41             "avatar_thumb": {
 42                 "uri": "100x100/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351",
 43                 "url_list": ["https://p3.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_100x100.jpeg?from=116350172", "https://p26.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_100x100.jpeg?from=116350172", "https://p29.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_100x100.jpeg?from=116350172"]
 44             },
 45             "avatar_medium": {
 46                 "uri": "720x720/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351",
 47                 "url_list": ["https://p6.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_720x720.jpeg?from=116350172", "https://p26.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_720x720.jpeg?from=116350172", "https://p9.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_720x720.jpeg?from=116350172"]
 48             },
 49             "platform_sync_info": null,
 50             "geofencing": null,
 51             "policy_version": null,
 52             "type_label": null
 53         },
 54         "music": {
 55             "status": 1,
 56             "id": 6963867018181463000,
 57             "title": "@河南广播电视台驻马店站创作的原声",
 58             "cover_hd": {
 59                 "uri": "1080x1080/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351",
 60                 "url_list": ["https://p3.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172", "https://p9.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172", "https://p26.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172"]
 61             },
 62             "cover_large": {
 63                 "uri": "1080x1080/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351",
 64                 "url_list": ["https://p3.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172", "https://p9.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172", "https://p26.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_1080x1080.jpeg?from=116350172"]
 65             },
 66             "cover_medium": {
 67                 "uri": "720x720/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351",
 68                 "url_list": ["https://p3.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_720x720.jpeg?from=116350172", "https://p5-ipv6.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_720x720.jpeg?from=116350172", "https://p6.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_720x720.jpeg?from=116350172"]
 69             },
 70             "play_url": {
 71                 "uri": "https://sf3-cdn-tos.douyinstatic.com/obj/ies-music/6963867021574556429.mp3",
 72                 "url_list": ["https://sf3-cdn-tos.douyinstatic.com/obj/ies-music/6963867021574556429.mp3", "https://sf6-cdn-tos.douyinstatic.com/obj/ies-music/6963867021574556429.mp3"]
 73             },
 74             "position": null,
 75             "mid": "6963867018181462792",
 76             "author": "河南广播电视台驻马店站",
 77             "cover_thumb": {
 78                 "uri": "168x168/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351",
 79                 "url_list": ["https://p3.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_168x168.jpeg?from=116350172", "https://p29.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_168x168.jpeg?from=116350172", "https://p9.douyinpic.com/img/tos-cn-avt-0015/c753d5f2aeb9eba805ea30b93dad0351~c5_168x168.jpeg?from=116350172"]
 80             },
 81             "duration": 15
 82         },
 83         "cha_list": [{
 84             "user_count": 0,
 85             "connect_music": null,
 86             "hash_tag_profile": "",
 87             "desc": "",
 88             "cha_name": "河南",
 89             "type": 0,
 90             "view_count": 0,
 91             "is_commerce": false,
 92             "cid": "1573440268653582"
 93         }],
 94         "image_infos": null,
 95         "aweme_id": "6963866852413984007",
 96         "comment_list": null,
 97         "geofencing": null,
 98         "video_text": null,
 99         "long_video": null,
100         "forward_id": "0",
101         "video_labels": null,
102         "duration": 15394,
103         "text_extra": [{
104             "user_id": "6796248446",
105             "type": 0,
106             "hashtag_name": "",
107             "hashtag_id": 0,
108             "start": 33,
109             "end": 39
110         }, {
111             "start": 0,
112             "end": 3,
113             "type": 1,
114             "hashtag_name": "河南",
115             "hashtag_id": 1573440268653582
116         }, {
117             "start": 4,
118             "end": 7,
119             "type": 1,
120             "hashtag_name": "安阳",
121             "hashtag_id": 1572864661377038
122         }],
123         "promotions": null,
124         "desc": "#河南 #安阳 宝宝玩耍胳膊脱臼,还没有来得及哭,正骨师傅就治好了@抖音小助手",
125         "video": {
126             "dynamic_cover": {
127                 "uri": "tos-cn-p-0015/455f60e0025a45e3a3066d6327b71534_1621401611",
128                 "url_list": ["https://p9.douyinpic.com/obj/tos-cn-p-0015/455f60e0025a45e3a3066d6327b71534_1621401611?from=4257465056_large", "https://p5-ipv6.douyinpic.com/obj/tos-cn-p-0015/455f60e0025a45e3a3066d6327b71534_1621401611?from=4257465056_large", "https://p3.douyinpic.com/obj/tos-cn-p-0015/455f60e0025a45e3a3066d6327b71534_1621401611?from=4257465056_large"]
129             },
130             "origin_cover": {
131                 "uri": "tos-cn-p-0015/75ff489e43244f7cad033f151ef4d822_1621401609",
132                 "url_list": ["https://p3.douyinpic.com/tos-cn-p-0015/75ff489e43244f7cad033f151ef4d822_1621401609~tplv-dy-360p.jpeg?from=4257465056&s=&se=false&sh=&sc=&l=202105192140090102121600260E0015B6&biz_tag=feed_cover", "https://p11.douyinpic.com/tos-cn-p-0015/75ff489e43244f7cad033f151ef4d822_1621401609~tplv-dy-360p.jpeg?from=4257465056&s=&se=false&sh=&sc=&l=202105192140090102121600260E0015B6&biz_tag=feed_cover", "https://p26.douyinpic.com/tos-cn-p-0015/75ff489e43244f7cad033f151ef4d822_1621401609~tplv-dy-360p.jpeg?from=4257465056&s=&se=false&sh=&sc=&l=202105192140090102121600260E0015B6&biz_tag=feed_cover"]
133             },
134             "ratio": "720p",
135             "has_watermark": true,
136             "bit_rate": null,
137             "vid": "v0300fg10000c2i9vhn1u1atmr5f2o1g",
138             "play_addr": {
139                 "uri": "v0300fg10000c2i9vhn1u1atmr5f2o1g",
140                 "url_list": ["https://aweme.snssdk.com/aweme/v1/playwm/?video_id=v0300fg10000c2i9vhn1u1atmr5f2o1g&ratio=720p&line=0"]
141             },
142             "cover": {
143                 "uri": "tos-cn-p-0015/56ac3f2f30c64a789c0211193afc1137",
144                 "url_list": ["https://p9.douyinpic.com/img/tos-cn-p-0015/56ac3f2f30c64a789c0211193afc1137~c5_300x400.jpeg?from=4257465056_large", "https://p11.douyinpic.com/img/tos-cn-p-0015/56ac3f2f30c64a789c0211193afc1137~c5_300x400.jpeg?from=4257465056_large", "https://p3.douyinpic.com/img/tos-cn-p-0015/56ac3f2f30c64a789c0211193afc1137~c5_300x400.jpeg?from=4257465056_large"]
145             },
146             "height": 1906,
147             "width": 1080,
148             "duration": 15394
149         }
150     }],
151     "extra": {
152         "now": 1621431609000,
153         "logid": "202105192140090102121600260E0015B6"
154     }
155 }

 




JSONObject jsonObject = new JSONObject(body).getJSONArray("item_list").getJSONObject(0);
//获取到视频链接记得替换playwm 成play
String videoSrc=jsonObject.getJSONObject("video")
.getJSONObject("play_addr").getJSONArray("url_list").get(0).toString()
.replace("playwm","play");
//然后获取去水印后的视频地址
String videoUrl=HttpUtil.createGet(videoSrc).addHeaders(headers).execute().header("Location");

//剩下的就是视频的基本信息了 标题,背景音乐
String title=jsonObject.get("desc").toString();
String img=jsonObject.getJSONObject("video").getJSONObject("origin_cover").getJSONArray("url_list").get(0).toString();
String gif=jsonObject.getJSONObject("video").getJSONObject("dynamic_cover").getJSONArray("url_list").get(0).toString();
String music=jsonObject.getJSONObject("music").getJSONObject("play_url").getJSONArray("url_list").get(0).toString();





---------------------下面是js版本的原理同上------------------------

let res=await uniCloud.httpclient.request(
"https://v.douyin.com/efKYWbU/",{method:"GET",
dataType: 'text'})
//视频获取mid
let mid=res.headers.location.split("/")[5]
//通过mid获取视频详情
let body= await uniCloud.httpclient.request("https://www.iesdouyin.com/web/api/v2/aweme/iteminfo/?item_ids="+mid,{dataType: 'text'});

body=JSON.parse(body.data)
//初始化视频信息
res={desc:body.item_list[0].desc,video:body.item_list[0].video.play_addr.url_list[0].replace("playwm","play"),
image:body.item_list[0].video.origin_cover.url_list[0],
music:body.item_list[0].music.play_url.url_list[0]
}
//把视频地址转换成无水印的
let temp=await uniCloud.httpclient.request(
res.video,{method:"GET",
dataType: 'text'})
res.video=temp.headers.location

//打印视频结果
console.log(res)

 
posted @ 2021-05-19 17:59  kdcplus  阅读(591)  评论(0)    收藏  举报