Compare commits

...
3 Commits
Author SHA1 Message Date
afkarxyz 92267dbf5e Update v1.4 2025-01-28 16:47:50 +07:00
afkarxyz 37da356f4c Update README.md 2025-01-28 16:47:25 +07:00
afkarxyz eb268f5f9f Update v1.3 2025-01-28 12:45:19 +07:00
2 changed files with 131 additions and 113 deletions

No files matched your search

+8 -8
View File
@@ -8,13 +8,13 @@
## Download
- Download the latest version of [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v1.3/TwitterXMediaBatchDownloader.exe)
- Download the latest version of [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v1.4/TwitterXMediaBatchDownloader.exe)
- 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`
- The ability to download media from **Withheld Accounts**
- The ability to download media from **Withheld Accounts** (requires unchecking the Local option)
- Simple and compact GUI
- Download images and videos in original quality
- Option to choose the media type to download: **media** (image + GIF + video) or just **image/GIF/video**
@@ -23,19 +23,19 @@
## Screenshots
![image](https://github.com/user-attachments/assets/c8af187c-fd4c-4b3d-abb8-475a4d4a6b14)
![image](https://github.com/user-attachments/assets/085cdcee-5272-41bb-8612-06737c0ebe32)
![image](https://github.com/user-attachments/assets/8e9ecb0b-59ec-43a8-9648-78838b121582)
![image](https://github.com/user-attachments/assets/3e71f14b-c4f0-4e86-87d5-9217d88cb0c2)
![image](https://github.com/user-attachments/assets/779c7f75-08fb-4ba8-977a-8a29bae4a7e3)
![image](https://github.com/user-attachments/assets/c4e086c2-d4d5-4eee-8bab-dba8e5fdd90d)
> Downloading from **Withheld Accounts**
![image](https://github.com/user-attachments/assets/8ed5d0de-e83e-4dca-bf17-f9ed78bfd2ae)
![image](https://github.com/user-attachments/assets/f5e301cf-9700-4986-a87d-8424be40db5c)
![image](https://github.com/user-attachments/assets/bb76e9f1-6fa9-416d-92f1-e9d10ff85d86)
![image](https://github.com/user-attachments/assets/92f814b1-069f-4605-b31f-8a5ff8dc0f17)
![image](https://github.com/user-attachments/assets/48bf3cc6-81d7-45dd-9d8c-40ef5b0317e9)
![image](https://github.com/user-attachments/assets/c6e7dc0d-659d-456e-b30c-6cca66fe9359)
## How to Obtain Auth Token
+123 -105
View File
@@ -37,12 +37,12 @@ class MetadataFetcher(QThread):
finished = pyqtSignal(dict)
error = pyqtSignal(str)
def __init__(self, username, media_type='media', use_api=True):
def __init__(self, username, media_type='media', use_local=False):
super().__init__()
self.username = username
self.auth_token = None
self.media_type = media_type
self.use_api = use_api
self.use_local = use_local
def normalize_url(self, url_or_username):
url_or_username = url_or_username.strip()
@@ -82,101 +82,115 @@ class MetadataFetcher(QThread):
except Exception as e:
raise ValueError(f"API request failed: {str(e)}")
async def fetch_local(self, normalized):
try:
match = re.match(twitter.TwitterTimelineExtractor.pattern, f"https://x.com/{normalized}/timeline")
if not match:
raise ValueError(f"Invalid username: {normalized}")
extractor = twitter.TwitterTimelineExtractor(match)
extractor.config = lambda key, default=None: {
"cookies": {
"auth_token": self.auth_token
}
}.get(key, default)
extractor.initialize()
output = {
'account_info': {},
'timeline': []
}
for item in extractor:
if isinstance(item, tuple) and len(item) >= 3:
media_url = item[1]
tweet_data = item[2]
if not output['account_info']:
if 'user' in tweet_data:
user = tweet_data['user']
user_date = user.get('date', '')
if isinstance(user_date, datetime):
user_date = user_date.strftime("%Y-%m-%d %H:%M:%S")
output['account_info'] = {
'name': user.get('name', ''),
'nick': user.get('nick', ''),
'date': user_date,
'followers_count': user.get('followers_count', 0),
'friends_count': user.get('friends_count', 0),
'profile_image': user.get('profile_image', ''),
'statuses_count': user.get('statuses_count', 0)
}
should_include = False
media_type = tweet_data.get('type', '')
if self.media_type == 'media':
should_include = ('pbs.twimg.com' in media_url or
'video.twimg.com' in media_url)
elif self.media_type == 'image':
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':
should_include = (media_type == 'video' and
'video.twimg.com' in media_url)
if should_include:
tweet_date = tweet_data.get('date', datetime.now())
if isinstance(tweet_date, datetime):
tweet_date = tweet_date.strftime("%Y-%m-%d %H:%M:%S")
output['timeline'].append({
'url': media_url,
'date': tweet_date,
'type': media_type,
'tweet_id': tweet_data.get('tweet_id', '')
})
if not output['account_info']:
raise ValueError("Failed to fetch account information. Please check the username and auth token.")
if not output['timeline']:
if self.media_type == 'media':
message = "No media found in timeline"
elif self.media_type == 'image':
message = "No images found in timeline"
elif self.media_type == 'gif':
message = "No GIFs found in timeline"
else:
message = "No videos found in timeline"
raise ValueError(message)
return output
except Exception as e:
raise ValueError(f"Local gallery-dl error: {str(e)}")
def run(self):
try:
normalized = self.normalize_url(self.username)
try:
data = asyncio.run(self.fetch_from_api(normalized, self.auth_token))
self.finished.emit(data)
return
except Exception as api_error:
if not self.use_local:
try:
match = re.match(twitter.TwitterTimelineExtractor.pattern, f"https://x.com/{normalized}/timeline")
if not match:
raise ValueError(f"Invalid username: {normalized}")
extractor = twitter.TwitterTimelineExtractor(match)
extractor.config = lambda key, default=None: {
"cookies": {
"auth_token": self.auth_token
}
}.get(key, default)
extractor.initialize()
output = {
'account_info': {},
'timeline': []
}
for item in extractor:
if isinstance(item, tuple) and len(item) >= 3:
media_url = item[1]
tweet_data = item[2]
if not output['account_info']:
if 'user' in tweet_data:
user = tweet_data['user']
user_date = user.get('date', '')
if isinstance(user_date, datetime):
user_date = user_date.strftime("%Y-%m-%d %H:%M:%S")
output['account_info'] = {
'name': user.get('name', ''),
'nick': user.get('nick', ''),
'date': user_date,
'followers_count': user.get('followers_count', 0),
'friends_count': user.get('friends_count', 0),
'profile_image': user.get('profile_image', ''),
'statuses_count': user.get('statuses_count', 0)
}
should_include = False
media_type = tweet_data.get('type', '')
if self.media_type == 'media':
should_include = ('pbs.twimg.com' in media_url or
'video.twimg.com' in media_url)
elif self.media_type == 'image':
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':
should_include = (media_type == 'video' and
'video.twimg.com' in media_url)
if should_include:
tweet_date = tweet_data.get('date', datetime.now())
if isinstance(tweet_date, datetime):
tweet_date = tweet_date.strftime("%Y-%m-%d %H:%M:%S")
output['timeline'].append({
'url': media_url,
'date': tweet_date,
'type': media_type,
'tweet_id': tweet_data.get('tweet_id', '')
})
if not output['account_info']:
raise ValueError("Failed to fetch account information. Please check the username and auth token.")
if not output['timeline']:
if self.media_type == 'media':
message = "No media found in timeline"
elif self.media_type == 'image':
message = "No images found in timeline"
elif self.media_type == 'gif':
message = "No GIFs found in timeline"
else:
message = "No videos found in timeline"
raise ValueError(message)
self.finished.emit(output)
except Exception as local_error:
data = asyncio.run(self.fetch_from_api(normalized, self.auth_token))
self.finished.emit(data)
return
except Exception as api_error:
print(f"API fetch failed, falling back to local: {str(api_error)}")
pass
try:
data = asyncio.run(self.fetch_local(normalized))
self.finished.emit(data)
except Exception as local_error:
if not self.use_local:
raise ValueError(f"Both API and local methods failed.\nAPI error: {str(api_error)}\nLocal error: {str(local_error)}")
else:
raise ValueError(f"Local gallery-dl failed: {str(local_error)}")
except Exception as e:
self.error.emit(str(e))
@@ -431,9 +445,9 @@ class TwitterMediaDownloaderGUI(QMainWindow):
media_layout.addWidget(self.media_type_combo)
media_layout.addSpacing(10)
self.use_api_checkbox = QCheckBox("Use API")
self.use_api_checkbox.setToolTip("Use external API instead of gallery-dl")
self.use_api_checkbox.setChecked(True)
self.use_api_checkbox = QCheckBox("Local")
self.use_api_checkbox.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
self.use_api_checkbox.setToolTip("Use local gallery-dl instead of API")
self.use_api_checkbox.stateChanged.connect(self.auto_save_settings)
media_layout.addWidget(self.use_api_checkbox)
@@ -450,7 +464,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
self.batch_size_combo.setFixedWidth(60)
for size in range(10, 101, 10):
self.batch_size_combo.addItem(str(size))
self.batch_size_combo.setCurrentText("20")
batch_layout.addWidget(batch_label)
batch_layout.addWidget(self.batch_size_combo)
@@ -575,8 +588,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
self.main_layout.addWidget(self.progress_bar)
bottom_layout = QHBoxLayout()
bottom_layout.setContentsMargins(0, 0, 0, 0)
bottom_layout.setSpacing(5)
self.status_label = QLabel("")
bottom_layout.addWidget(self.status_label, stretch=1)
@@ -602,7 +613,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
bottom_layout.addWidget(self.update_button)
self.main_layout.addLayout(bottom_layout)
self.main_layout.setAlignment(bottom_layout, Qt.AlignmentFlag.AlignBottom)
def open_update_page(self):
import webbrowser
@@ -624,7 +634,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
self.settings.setValue('filename_format',
'username_date' if self.format_username.isChecked() else 'date_username')
self.settings.setValue('media_type', self.media_type_combo.currentData())
self.settings.setValue('use_api', self.use_api_checkbox.isChecked())
self.settings.setValue('use_local', self.use_api_checkbox.isChecked())
self.settings.setValue('batch_size', self.batch_size_combo.currentText())
self.settings.sync()
@@ -643,8 +653,8 @@ class TwitterMediaDownloaderGUI(QMainWindow):
self.media_type_combo.setCurrentIndex(i)
break
use_api = self.settings.value('use_api', True, type=bool)
self.use_api_checkbox.setChecked(use_api)
use_local = self.settings.value('use_local', False, type=bool)
self.use_api_checkbox.setChecked(use_local)
batch_size = self.settings.value('batch_size', '20')
index = self.batch_size_combo.findText(batch_size)
@@ -682,8 +692,8 @@ class TwitterMediaDownloaderGUI(QMainWindow):
self.status_label.setText("Fetching profile information...")
media_type = self.media_type_combo.currentData()
use_api = self.use_api_checkbox.isChecked()
self.fetcher = MetadataFetcher(username, media_type, use_api)
use_local = self.use_api_checkbox.isChecked()
self.fetcher = MetadataFetcher(username, media_type, use_local)
self.fetcher.auth_token = auth_token
self.fetcher.finished.connect(self.handle_profile_info)
self.fetcher.error.connect(self.handle_fetch_error)
@@ -706,7 +716,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
is_withheld = not account_info.get('nick') and not account_info.get('profile_image')
name = account_info.get('name', 'Unknown')
nick = "Withheld" if is_withheld else account_info.get('nick', 'Unknown')
nick = "Withheld Account" if is_withheld else account_info.get('nick', 'Unknown')
date_str = account_info.get('date', '')
followers = account_info.get('followers_count', 0)
following = account_info.get('friends_count', 0)
@@ -783,6 +793,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
self.download_button.show()
self.cancel_button.show()
self.update_button.hide()
self.setFixedHeight(180)
try:
output_base = self.dir_input.text().strip() or self.default_pictures_dir
@@ -822,7 +833,12 @@ class TwitterMediaDownloaderGUI(QMainWindow):
def handle_fetch_error(self, error):
self.fetch_button.setEnabled(True)
self.status_label.setText(f"Error fetching profile info: {error}")
error_str = str(error)
if "Local gallery-dl error: None" in error_str and self.use_api_checkbox.isChecked():
self.status_label.setText("Please uncheck the 'Local' option to fetch metadata using the API method.")
else:
self.status_label.setText(f"Error fetching profile info: {error}")
def start_download(self):
if not self.media_info:
@@ -887,6 +903,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
self.download_button.setText("Download")
self.download_button.clicked.disconnect()
self.download_button.clicked.connect(self.start_download)
self.setFixedHeight(210)
def download_error(self, error_message):
self.progress_bar.hide()
@@ -907,6 +924,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
self.media_info = None
self.update_button.show()
self.fetch_button.setEnabled(True)
self.setFixedHeight(210)
def main():
if getattr(sys, 'frozen', False):