[~] Refactor

This commit is contained in:
Siarhei Siniak 2024-07-06 14:40:59 +03:00
parent 858332d657
commit c28d9a19cc
2 changed files with 41 additions and 0 deletions

@ -7,6 +7,7 @@ RUN pip3 install pyktok yt-dlp playwright==1.44.0 TikTokApi
RUN pip3 install numpy pandas browser_cookie3 ipdb asgiref RUN pip3 install numpy pandas browser_cookie3 ipdb asgiref
RUN python3 -m playwright install-deps RUN python3 -m playwright install-deps
RUN python3 -m playwright install RUN python3 -m playwright install
RUN pip3 install tqdm
WORKDIR /app WORKDIR /app

@ -1,7 +1,9 @@
import logging import logging
import os
import sys import sys
import json import json
from typing import ( from typing import (
Any,
Optional, Optional,
Iterable, Iterable,
) )
@ -79,3 +81,41 @@ async def tiktok_videos_links_get(
))) )))
return links return links
def tiktok_videos_meta(links: Iterable[str]) -> Iterable[dict[str, Any]]:
res = []
for o in links:
parts = o.split('/')
res.append(dict(
url=o,
fname='_'.join(parts[-3:]) +'.mp4',
))
return res
def tiktok_videos_fetch(
meta: Iterable[dict[str, Any]]
) -> Iterable[dict[str, Any]]:
import pyktok
import tqdm
stats = dict(
saved=0,
total=0,
skipped=0,
error=0,
)
for o in tqdm.tqdm(meta):
stats['total'] += 1
if not os.path.exists(o['fname']):
try:
pyktok.save_tiktok(o['url'])
stats['saved'] += 1
except:
stats['error'] += 1
else:
stats['skipped'] += 1
return stats