Downloading new video links

Downloading new video links

Recently we've seen a new type of video links with new security checks which prevent you from directly accessing the video.

After analyzing we found out that valid cookies and headers are required in order to open the link.

In order to access the video link successfully, you must make a GET request using a HTTP client library and set the right headers for the request, which are included in the JSON object response ($other -> videoLinkHeaders): 



For your convenience, a simple method for downloading and saving videos has been implemented in TikAPI's JavaScript & Python Library which does this automatically (without doing any extra API requests).

 Note: Firstly, make sure you upgrade to the latest version of the library.

Example in JavaScript (the 'saveVideo' method is available on the response object):

  1. import TikAPI from 'tikapi';

    const api = TikAPI("myAPIKey");

    (async function(){
        try{
            let response = await api.public.video({
                id: "videoIdHere"
            });

            console.log(response.json);
           
            response.saveVideo(response.json.itemInfo.itemStruct.video.downloadAddr, "video.mp4")
        }
        catch(err){
            console.log(err?.statusCode, err?.message, err?.json)
        }  
    })();

Example in Python (the 'save_video' method is available on the response object):

  1. from tikapi import TikAPI, ValidationException, ResponseException

    api = TikAPI("myAPIKey")

    try:
        response = api.public.video(
            id="videoIdHere"
        )

        json: dict = response.json()
       
        print(json)

        response.save_video(json['itemInfo']['itemStruct']['video']['downloadAddr'], 'video.mp4')

    except ValidationException as e:
        print(e, e.field)

    except ResponseException as e:
        print(e, e.response.status_code)