මේ දවස් වල Tiktok පොඩ්ඩක් follow කරනව. ඉතින් ඉන්න අයගෙ video download කරන්න පොඩි code කෑල්ලක් ලිව්ව Python වලින්. කාටහරි වැදගත් වෙයි කියල ඔන්න share කලා. මේකෙන් ඔයාලට පුලුවන් user කෙනෙක්ගෙ සම්පූර්ණ video list එකම එකපාර download කරගන්න. uploader video එක save කරන option එක enable කරල තියෙන්නෙ ඕනෙ නෑ. save video disable කරල තිබ්බත් download කරගන්න පුලුවන්.
Tiktok watermark එක නැතුව download වෙන එක වැඩ කරන්නෙ නෑ. මොකක් හරි අවුලක්. වැඩියෙ හෙව්වෙ නෑ ඉක්මනින් download කරගන්න ඕනෙ නිසා. තව මේකෙ වැඩකෑලි ගොඩක් තියෙනව. මම නම් බොහොම පොඩියට කලේ.
Jupyter notebook එකේ වැඩ නෑ. selenium webdriver error එකක් එනව. වැඩිය හෙව්වෙ නෑ. github එකේ issue එකක් තියෙනව දැක්ක. ඒ නිසා අතඇරල sublime එකේ කලේ.
Run කරන්න පොඩි ගයිඩ් එකක් දෙන්නම්
Installing
verifyFp value එක replace කරන්න. chrome web browser එකෙන් Cookie වලින් ගන්න "s_v_web_id" Key එක. s_v_web_id හොයා ගන්න බැරි නම් එකපාරක් tiktok වලට chrome එකෙන් login වෙලා logout වෙන්න.
profile_name = අවශ්ය කෙනාගෙ profile name එක
video_count = අවශ්ය video ගනන. මේකෙ අග ඉදන් තමා එන්නෙ. ඒ කියන්න අන්තිමට දාපු විඩියෝ එකෙන්. 20-30 වගෙ අතරමැද දාපු විඩියෝ download කරන්න පුලුවන්ද බැලුවෙ නෑ.
profile name එකෙන් folder එකක් හදාග්න්න නැත්නම් path error එකක් එයි. එහෙම නැත්නම් folder එක auto create වෙන්න දාගන්න.
tiktok dictionanry එකක් එන්නෙ. oject ඒකෙ stats attribute එකෙන් ඕනෙ stats ටික ගන්න පුලුවන්.
stats = tiktok['stats']
>>>{'diggCount': 1419, 'shareCount': 1, 'commentCount': 45, 'playCount': 16400}
මෙතනින් API එක ගැන තව විස්තර තියෙනව. එහෙනම් ඇති වෙනකම් බාගන්න. මම විඩියෝ 1000ක් වගේ download කලා. අවුලක් උනේ නෑ.
Tiktok watermark එක නැතුව download වෙන එක වැඩ කරන්නෙ නෑ. මොකක් හරි අවුලක්. වැඩියෙ හෙව්වෙ නෑ ඉක්මනින් download කරගන්න ඕනෙ නිසා. තව මේකෙ වැඩකෑලි ගොඩක් තියෙනව. මම නම් බොහොම පොඩියට කලේ.
Jupyter notebook එකේ වැඩ නෑ. selenium webdriver error එකක් එනව. වැඩිය හෙව්වෙ නෑ. github එකේ issue එකක් තියෙනව දැක්ක. ඒ නිසා අතඇරල sublime එකේ කලේ.
Run කරන්න පොඩි ගයිඩ් එකක් දෙන්නම්
Installing
Code:
pip install TikTokApi
python -m playwright install
verifyFp value එක replace කරන්න. chrome web browser එකෙන් Cookie වලින් ගන්න "s_v_web_id" Key එක. s_v_web_id හොයා ගන්න බැරි නම් එකපාරක් tiktok වලට chrome එකෙන් login වෙලා logout වෙන්න.
profile_name = අවශ්ය කෙනාගෙ profile name එක
video_count = අවශ්ය video ගනන. මේකෙ අග ඉදන් තමා එන්නෙ. ඒ කියන්න අන්තිමට දාපු විඩියෝ එකෙන්. 20-30 වගෙ අතරමැද දාපු විඩියෝ download කරන්න පුලුවන්ද බැලුවෙ නෑ.
profile name එකෙන් folder එකක් හදාග්න්න නැත්නම් path error එකක් එයි. එහෙම නැත්නම් folder එක auto create වෙන්න දාගන්න.
Python:
import os
if not os.path.exists(profile_name):
os.makedirs(profile_name)
tiktok dictionanry එකක් එන්නෙ. oject ඒකෙ stats attribute එකෙන් ඕනෙ stats ටික ගන්න පුලුවන්.
stats = tiktok['stats']
>>>{'diggCount': 1419, 'shareCount': 1, 'commentCount': 45, 'playCount': 16400}
Python:
from TikTokApi import TikTokApi
import random
import string
import datetime
def save_video(file_path):
print(file_path)
with open(file_path, 'wb') as out:
out.write(video_bytes)
print('##### Saved #####')
verifyFp = "verify_id"
# did = ''.join(random.choice(string.digits) for num in range(19))
did=str(random.randint(10000, 999999999))
# If playwright doesn't work for you try to use selenium
# api = TikTokApi.get_instance(use_selenium=True)
# Since TikTok changed their API you need to use the custom_verifyFp option.
# In your web browser you will need to go to TikTok, Log in and get the s_v_web_id value.
api = TikTokApi.get_instance(custom_verifyFp = verifyFp, use_test_endpoints = True, custom_did = did)
# If you cannot find verifyFp use without
# api = TikTokApi.get_instance(custom_did = did)
profile_name = 'harshyuofficial'
video_count = 1
# tiktoks = api.byUsername(profile_name)
tiktoks = api.byUsername(profile_name, count=video_count)
for tiktok in tiktoks:
# print(tiktok)
# print(tiktok.keys())
time = tiktok['createTime']
date_time = datetime.datetime.fromtimestamp(time).strftime('%Y-%m-%d %H-%M-%S')
# print(date_time)
desc = tiktok['desc']
video_bytes = api.get_Video_By_TikTok(tiktok)
path = f'{profile_name}\{desc} {date_time}.mp4'
try:
save_video(path)
except:
name = ("".join( x for x in desc if (x.isalnum() or x in "._- "))).strip()
path = f'{profile_name}\{date_time}_{name}.mp4'
save_video(path)
print(len(tiktoks))
print('done')
මෙතනින් API එක ගැන තව විස්තර තියෙනව. එහෙනම් ඇති වෙනකම් බාගන්න. මම විඩියෝ 1000ක් වගේ download කලා. අවුලක් උනේ නෑ.