mirror of
https://github.com/Alvin-Zilverstand/Twitter-X-Media-Batch-Downloader.git
synced 2026-11-24 15:23:11 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
dfb536f663 | ||
|
|
2b5e7985d5 | ||
|
|
81bacad4d8 | ||
|
|
aa89fda847 | ||
|
|
e98cd51cf4 | ||
|
|
6bb5348485 | ||
|
|
784bb494fc | ||
|
|
5096e18cb8 | ||
|
|
2237de2b2c | ||
|
|
4656ebc56c |
No files matched your search
@@ -53,10 +53,17 @@ def get_metadata(username):
|
|||||||
tweet_date = tweet_data.get('date', datetime.now())
|
tweet_date = tweet_data.get('date', datetime.now())
|
||||||
if isinstance(tweet_date, datetime):
|
if isinstance(tweet_date, datetime):
|
||||||
tweet_date = tweet_date.strftime("%Y-%m-%d %H:%M:%S")
|
tweet_date = tweet_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
output['timeline'].append({
|
|
||||||
|
timeline_entry = {
|
||||||
'url': media_url,
|
'url': media_url,
|
||||||
'date': tweet_date
|
'date': tweet_date,
|
||||||
})
|
'tweet_id': tweet_data.get('tweet_id', 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
if 'type' in tweet_data:
|
||||||
|
timeline_entry['type'] = tweet_data['type']
|
||||||
|
|
||||||
|
output['timeline'].append(timeline_entry)
|
||||||
output['total_urls'] += 1
|
output['total_urls'] += 1
|
||||||
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
@@ -0,0 +1,34 @@
|
|||||||
|
import json
|
||||||
|
import re
|
||||||
|
import os
|
||||||
|
from gallery_dl.extractor import twitter
|
||||||
|
|
||||||
|
def get_metadata(username):
|
||||||
|
url = f"https://x.com/{username}/timeline"
|
||||||
|
|
||||||
|
match = re.match(twitter.TwitterTimelineExtractor.pattern, url)
|
||||||
|
if not match:
|
||||||
|
raise ValueError(f"Invalid URL: {url}")
|
||||||
|
|
||||||
|
extractor = twitter.TwitterTimelineExtractor(match)
|
||||||
|
|
||||||
|
extractor.config = lambda key, default=None: {
|
||||||
|
"cookies": {
|
||||||
|
"auth_token": ""
|
||||||
|
}
|
||||||
|
}.get(key, default)
|
||||||
|
|
||||||
|
extractor.initialize()
|
||||||
|
|
||||||
|
all_items = []
|
||||||
|
for item in extractor:
|
||||||
|
all_items.append(item)
|
||||||
|
|
||||||
|
current_dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
output_file = os.path.join(current_dir, f"{username}.json")
|
||||||
|
|
||||||
|
with open(output_file, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(all_items, f, indent=2, default=str)
|
||||||
|
|
||||||
|
username = ""
|
||||||
|
get_metadata(username)
|
||||||
@@ -2,13 +2,24 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
**Twitter/X Media Batch Downloader** is a GUI tool for downloading all media, including images and videos, from Twitter/X accounts, using `gallery-dl`
|
<div align="center">
|
||||||
|
<b>Twitter/X Media Batch Downloader</b> is a GUI tool that allows users to download all media, including images and videos, in their original quality from Twitter/X accounts using <code>gallery-dl</code>
|
||||||
|
</div>
|
||||||
|
|
||||||
## Download
|
## Download
|
||||||
|
|
||||||
- Download the latest version of [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v1.1/TwitterXMediaBatchDownloader.exe)
|
- Download the latest version of [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v1.2/TwitterXMediaBatchDownloader.exe)
|
||||||
- If you're familiar with **userscripts**, please install it [here](https://greasyfork.org/en/scripts/523157-twitter-x-media-batch-downloader)
|
- If you're familiar with **userscripts**, please install it [here](https://greasyfork.org/en/scripts/523157-twitter-x-media-batch-downloader)
|
||||||
|
|
||||||
|
## Features
|
||||||
|
|
||||||
|
- Uses the powerful `gallery-dl` library, similar to `yt-dlp`
|
||||||
|
- Simple and compact GUI
|
||||||
|
- Download images and videos in original quality
|
||||||
|
- Option to choose the media type to download: **media** (image + video) or just **image/video**
|
||||||
|
- **Batch** download settings, ranging from 10 to 100 files per download
|
||||||
|
- Filename format customization
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||

|

|
||||||
@@ -17,7 +28,7 @@
|
|||||||
|
|
||||||

|

|
||||||
|
|
||||||
## How to obtain Auth Token
|
## How to Obtain Auth Token
|
||||||
|
|
||||||
1. Go to [Twitter's website](https://www.x.com/)
|
1. Go to [Twitter's website](https://www.x.com/)
|
||||||
2. Log into your account
|
2. Log into your account
|
||||||
@@ -25,6 +36,5 @@
|
|||||||
4. Navigate to the **Application** tab, then select **Storage** > **Cookies**
|
4. Navigate to the **Application** tab, then select **Storage** > **Cookies**
|
||||||
5. Find and copy the `auth_token` value or use the browser extension [Cookie-Editor](https://cookie-editor.com/)
|
5. Find and copy the `auth_token` value or use the browser extension [Cookie-Editor](https://cookie-editor.com/)
|
||||||
6. Do not log out of your account, as a new `auth_token` will be generated by Twitter
|
6. Do not log out of your account, as a new `auth_token` will be generated by Twitter
|
||||||
7. Close your browser
|
|
||||||
|
|
||||||

|

|
||||||
@@ -93,14 +93,19 @@ class MetadataFetcher(QThread):
|
|||||||
}
|
}
|
||||||
|
|
||||||
should_include = False
|
should_include = False
|
||||||
|
media_type = tweet_data.get('type', '')
|
||||||
|
|
||||||
if self.media_type == 'media':
|
if self.media_type == 'media':
|
||||||
should_include = ('pbs.twimg.com' in media_url or
|
should_include = ('pbs.twimg.com' in media_url or
|
||||||
'video.twimg.com' in media_url)
|
'video.twimg.com' in media_url)
|
||||||
elif self.media_type == 'image':
|
elif self.media_type == 'image':
|
||||||
should_include = 'pbs.twimg.com' in media_url
|
should_include = ('pbs.twimg.com' in media_url and
|
||||||
|
media_type == 'photo')
|
||||||
|
elif self.media_type == 'gif':
|
||||||
|
should_include = media_type == 'animated_gif'
|
||||||
elif self.media_type == 'video':
|
elif self.media_type == 'video':
|
||||||
should_include = 'video.twimg.com' in media_url
|
should_include = (media_type == 'video' and
|
||||||
|
'video.twimg.com' in media_url)
|
||||||
|
|
||||||
if should_include:
|
if should_include:
|
||||||
tweet_date = tweet_data.get('date', datetime.now())
|
tweet_date = tweet_data.get('date', datetime.now())
|
||||||
@@ -110,8 +115,8 @@ class MetadataFetcher(QThread):
|
|||||||
output['timeline'].append({
|
output['timeline'].append({
|
||||||
'url': media_url,
|
'url': media_url,
|
||||||
'date': tweet_date,
|
'date': tweet_date,
|
||||||
'type': ('video' if 'video.twimg.com' in media_url
|
'type': media_type,
|
||||||
else 'image')
|
'tweet_id': tweet_data.get('tweet_id', '')
|
||||||
})
|
})
|
||||||
|
|
||||||
if not output['account_info']:
|
if not output['account_info']:
|
||||||
@@ -122,6 +127,8 @@ class MetadataFetcher(QThread):
|
|||||||
message = "No media found in timeline"
|
message = "No media found in timeline"
|
||||||
elif self.media_type == 'image':
|
elif self.media_type == 'image':
|
||||||
message = "No images found in timeline"
|
message = "No images found in timeline"
|
||||||
|
elif self.media_type == 'gif':
|
||||||
|
message = "No GIFs found in timeline"
|
||||||
else:
|
else:
|
||||||
message = "No videos found in timeline"
|
message = "No videos found in timeline"
|
||||||
raise ValueError(message)
|
raise ValueError(message)
|
||||||
@@ -173,13 +180,14 @@ class MediaDownloader(QThread):
|
|||||||
url = item['url']
|
url = item['url']
|
||||||
date = datetime.strptime(item['date'], "%Y-%m-%d %H:%M:%S")
|
date = datetime.strptime(item['date'], "%Y-%m-%d %H:%M:%S")
|
||||||
formatted_date = date.strftime("%Y%m%d_%H%M%S")
|
formatted_date = date.strftime("%Y%m%d_%H%M%S")
|
||||||
|
tweet_id = str(item.get('tweet_id', ''))
|
||||||
|
|
||||||
extension = 'mp4' if 'video.twimg.com' in url else 'jpg'
|
extension = 'mp4' if 'video.twimg.com' in url else 'jpg'
|
||||||
|
|
||||||
if self.filename_format == "username_date":
|
if self.filename_format == "username_date":
|
||||||
base_filename = f"{self.username}_{formatted_date}"
|
base_filename = f"{self.username}_{formatted_date}_{tweet_id}"
|
||||||
else:
|
else:
|
||||||
base_filename = f"{formatted_date}_{self.username}"
|
base_filename = f"{formatted_date}_{self.username}_{tweet_id}"
|
||||||
|
|
||||||
filename = f"{base_filename}.{extension}"
|
filename = f"{base_filename}.{extension}"
|
||||||
counter = 1
|
counter = 1
|
||||||
@@ -318,7 +326,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
|
|
||||||
self.media_type_combo = QComboBox()
|
self.media_type_combo = QComboBox()
|
||||||
self.media_type_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
self.media_type_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||||
media_types = [('media', 'Media'), ('image', 'Image'), ('video', 'Video')]
|
media_types = [('media', 'Media'), ('image', 'Image'), ('gif', 'GIF'), ('video', 'Video')]
|
||||||
for value, display in media_types:
|
for value, display in media_types:
|
||||||
self.media_type_combo.addItem(display, value)
|
self.media_type_combo.addItem(display, value)
|
||||||
self.media_type_combo.setFixedWidth(100)
|
self.media_type_combo.setFixedWidth(100)
|
||||||
|
|||||||
Reference in new issue
Block a user