mirror of
https://github.com/Alvin-Zilverstand/Twitter-X-Media-Batch-Downloader.git
synced 2026-12-02 19:11:28 +01:00
Add files via upload
This commit is contained in:
1 parent
073832f52f
commit
6a126fce80
2 files changed
+86
No files matched your search
@@ -0,0 +1,75 @@
|
|||||||
|
import json
|
||||||
|
import subprocess
|
||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from datetime import datetime
|
||||||
|
|
||||||
|
def get_metadata(username):
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
sys.stdout.reconfigure(encoding='utf-8')
|
||||||
|
|
||||||
|
url = f"https://x.com/{username}/timeline"
|
||||||
|
|
||||||
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
cookies_path = os.path.join(current_dir, 'cookies.json')
|
||||||
|
output_path = os.path.join(current_dir, f'{username}.json')
|
||||||
|
gallery_dl_path = os.path.join(current_dir, 'gallery-dl.exe')
|
||||||
|
|
||||||
|
config = {
|
||||||
|
"extractor": {
|
||||||
|
"twitter": {
|
||||||
|
"cookies": {
|
||||||
|
"auth_token": "fbaf8037664f5c4d18dafb5293a72039938991fb"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(cookies_path, 'w') as f:
|
||||||
|
json.dump(config, f)
|
||||||
|
|
||||||
|
result = subprocess.run([gallery_dl_path, '-j', '--config', cookies_path, url],
|
||||||
|
capture_output=True,
|
||||||
|
text=True,
|
||||||
|
encoding='utf-8',
|
||||||
|
check=True)
|
||||||
|
|
||||||
|
os.remove(cookies_path)
|
||||||
|
|
||||||
|
data = json.loads(result.stdout)
|
||||||
|
output = {
|
||||||
|
'account_info': {},
|
||||||
|
'timeline': []
|
||||||
|
}
|
||||||
|
|
||||||
|
for item in data:
|
||||||
|
if isinstance(item, list) and len(item) > 2 and isinstance(item[2], dict):
|
||||||
|
if not output['account_info'] and 'user' in item[2]:
|
||||||
|
user = item[2]['user']
|
||||||
|
output['account_info'] = {
|
||||||
|
'date': user.get('date', ''),
|
||||||
|
'followers_count': user.get('followers_count', ''),
|
||||||
|
'friends_count': user.get('friends_count', ''),
|
||||||
|
'name': user.get('name', ''),
|
||||||
|
'nick': user.get('nick', ''),
|
||||||
|
'profile_image': user.get('profile_image', ''),
|
||||||
|
'statuses_count': user.get('statuses_count', '')
|
||||||
|
}
|
||||||
|
if isinstance(item[1], str):
|
||||||
|
url = item[1]
|
||||||
|
if ('pbs.twimg.com' in url and 'format=jpg&name=orig' in url) or 'video.twimg.com' in url:
|
||||||
|
tweet_date = item[2].get('date')
|
||||||
|
if not tweet_date:
|
||||||
|
tweet_date = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
output['timeline'].append({
|
||||||
|
'url': url,
|
||||||
|
'date': tweet_date
|
||||||
|
})
|
||||||
|
|
||||||
|
with open(output_path, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(output, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
username = "Eririchyan"
|
||||||
|
get_metadata(username)
|
||||||
@@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" ?>
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
|
||||||
|
id="Layer_1" width="512px" height="512px" viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;"
|
||||||
|
xml:space="preserve">
|
||||||
|
<g fill="#1da0f1">
|
||||||
|
<polygon
|
||||||
|
points="12.153992,10.729553 8.088684,5.041199 5.92041,5.041199 10.956299,12.087097 11.59021,12.97345 15.900635,19.009583 18.068909,19.009583 12.785217,11.615906 " />
|
||||||
|
<path
|
||||||
|
d="M21.15979,1H2.84021C1.823853,1,1,1.823853,1,2.84021v18.31958C1,22.176147,1.823853,23,2.84021,23h18.31958 C22.176147,23,23,22.176147,23,21.15979V2.84021C23,1.823853,22.176147,1,21.15979,1z M15.235352,20l-4.362549-6.213013 L5.411438,20H4l6.246887-7.104675L4,4h4.764648l4.130127,5.881958L18.06958,4h1.411377l-5.95697,6.775635L20,20H15.235352z" />
|
||||||
|
</g>
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 876 B |
Reference in new issue
Block a user