43 lines
1006 B
Python
43 lines
1006 B
Python
import json
|
|
import coub
|
|
import os
|
|
import settings
|
|
|
|
|
|
videos, links = None, None
|
|
|
|
if os.path.exists(settings.JSON_DATA):
|
|
with open(settings.JSON_DATA, 'r', encoding='utf8') as f:
|
|
videos = coub.from_json(json.loads(f.read()))
|
|
|
|
elif os.path.exists(settings.LINKS_TXT):
|
|
with open(settings.LINKS_TXT, 'r', encoding='utf8') as f:
|
|
links = f.readlines()
|
|
|
|
else:
|
|
data = coub.get_sources()
|
|
links = coub.parse_pages(data)
|
|
with open(settings.LINKS_TXT, 'w', encoding='utf8') as f:
|
|
f.writelines([i + '\n' for i in links])
|
|
|
|
|
|
if links:
|
|
links = coub.unique(links)
|
|
print(f"Got {len(links)} unique coubs.")
|
|
|
|
print("Parsing links...")
|
|
videos = coub.get_videos(links)
|
|
with open(settings.JSON_DATA, 'w', encoding='utf8') as f:
|
|
f.write(json.dumps(coub.to_json(videos)))
|
|
|
|
for video in videos:
|
|
print(video)
|
|
coub.download_video(video)
|
|
|
|
|
|
print("Removing temporary files...")
|
|
for item in os.listdir(settings.TEMP_DIR):
|
|
os.remove(item)
|
|
|
|
|
|
print("Done.") |