This document defines functions to download videos from Douyin (TikTok) accounts. It includes:
- A getid function that makes an API call to fetch video data with a user ID and cursor.
- A download function that takes a video URL, ID, and description to download the video file.
- A waitforme function that pauses execution for a specified time in milliseconds.
- A run function that calls getid in a loop to retrieve all video data, calls download to save each one, and handles errors.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
172 views2 pages
Douyin Cod 1
This document defines functions to download videos from Douyin (TikTok) accounts. It includes:
- A getid function that makes an API call to fetch video data with a user ID and cursor.
- A download function that takes a video URL, ID, and description to download the video file.
- A waitforme function that pauses execution for a specified time in milliseconds.
- A run function that calls getid in a loop to retrieve all video data, calls download to save each one, and handles errors.
var waitforme=function(millisec) { return new Promise(resolve => { setTimeout(() => { resolve('') }, millisec); }) }
var run=async function(){
var result=[]; var hasMore=1; var sec_user_id=location.pathname.replace("/user/",""); var max_cursor=0; var download_from=prompt("Enter id video(Enter 0 if want to download all video):",""); if(download_from==null || download_from=="") { alert("Please, Enter id of video!"); return; } while(hasMore==1){ var moredata=await getid(sec_user_id,max_cursor); hasMore=moredata['has_more']; max_cursor=moredata['max_cursor']; for(var i in moredata['aweme_list']){ if(moredata['aweme_list'][i]['aweme_id'] == download_from){ hasMore=0; break; } if(moredata['aweme_list'][i]['video']['play_addr']['url_list'] [0].startsWith("https")) result.push([moredata['aweme_list'][i]['video']['play_addr']['url_list'] [0],moredata['aweme_list'][i]['aweme_id'],moredata['aweme_list'][i]['desc']]); else result.push([moredata['aweme_list'][i]['video']['play_addr']['url_list'] [0].replace("http","https"),moredata['aweme_list'][i] ['aweme_id'],moredata['aweme_list'][i]['desc']]); console.clear(); console.log("Number of videos: "+result.length); } } for(var i=result.length-1;i>=0;i--){ await waitforme(5000); try{download(result[i][0],result[i][1],result[i][2]);}catch{} } } run();