import builtins import json import os import re import sys import time import hashlib import shutil import unicodedata from datetime import datetime from pathlib import Path from urllib.parse import unquote # all the external dependencies are imported inside the functions, # so we can use this file in other projects without installing them. # or to copy and paste the functions to other public projects directly. # to install them all, you can do: # pip install requests lxml beautifulsoup4 python-dateutil pytz pyperclip wcwidth rich browsercookie # ==================== CONSTANTS ==================== '''Twitter media name handle The filename format I use, inherited from good old twMediaDownloader (RIP: here is a mirror: https://github.com/fireattack/twMediaDownloader). The first version must start with screen_name and ended with type[index][ dupe].suffix The second one allows optional arbitrary prefix or suffix. NOTE: to make it simpler, the returned m['extra'] and m['dupe'] will have leading space or hyphen with it. ''' TWITTER_FILENAME_RE = re.compile(r'^(?P\w+)-(?P\d+)-(?P\d{8})_(?P