Compare commits

...
6 Commits
Author SHA1 Message Date
afkarxyz befe838e79 v3.4 2025-08-08 15:20:30 +07:00
afkarxyz b534bc278e Update README.md 2025-08-08 15:17:31 +07:00
afkarxyz 2e882635eb v3.3 2025-07-31 12:08:25 +07:00
afkarxyz 5d5b778c8e v3.3 2025-07-30 05:26:56 +07:00
afkarxyz 7cf134f681 v3.3 2025-07-30 05:24:47 +07:00
afkarxyz 7d90eb7cb2 v3.3 2025-07-26 21:27:45 +07:00
7 changed files with 608 additions and 124 deletions

No files matched your search

+12 -12
View File
@@ -8,40 +8,40 @@
## 📥 Download ## 📥 Download
- **Windows (Latest)**: [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v3.2/TwitterXMediaBatchDownloader.exe) - [**Windows**](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v3.3/TwitterXMediaBatchDownloader_Windows.exe)
- **Linux**: [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v3.1/TwitterXMediaBatchDownloader) - [**Linux**](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v3.3/TwitterXMediaBatchDownloader_Linux)
- **Mac**: [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v3.1/TwitterXMediaBatchDownloader.app.zip) - [**Mac**](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v3.3/TwitterXMediaBatchDownloader_Mac.app.zip)
- If you're familiar with **userscripts**, please install it [here](https://greasyfork.org/en/scripts/523157) - If you're familiar with **userscripts**, please install it [**here**](https://greasyfork.org/en/scripts/523157)
### The downloaded application won't run❓ ### The downloaded application won't run❓
🐧 **Solution (Ubuntu/Linux)**: Open your terminal and run: 🐧 **Solution (Ubuntu/Linux)**: Open your terminal and run:
```bash ```bash
chmod +x TwitterXMediaBatchDownloader chmod +x TwitterXMediaBatchDownloader_Linux
``` ```
https://github.com/user-attachments/assets/41231de2-e665-4d61-a4f4-62f424973af3 https://github.com/user-attachments/assets/ab65e53f-2986-4386-9e09-e4c8e33ec90b
🍎 **Solution (macOS)**: Open your terminal and run: 🍎 **Solution (macOS)**: Open your terminal and run:
```bash ```bash
xattr -rd com.apple.quarantine ~/Downloads/TwitterXMediaBatchDownloader.app xattr -rd com.apple.quarantine ~/Downloads/TwitterXMediaBatchDownloader_Mac.app
``` ```
https://github.com/user-attachments/assets/56a89c03-29ab-45f1-979f-4317f45191f7 https://github.com/user-attachments/assets/5f9a1cf6-a7a8-4943-ad71-d2831b406137
## ✨ Features ## ✨ Features
- Powered by `gallery-dl`, similar to `yt-dlp` - Powered by `gallery-dl`, similar to `yt-dlp`
- **Bulk download**: Download multiple items at once - **Bulk download**: Download multiple accounts at once
- Media-type selection: All (Images + GIFs + Videos) or specific (Images / GIFs / Videos) - Media-type selection: All (Images + GIFs + Videos) or specific (Images / GIFs / Videos)
- **MP4 → GIF conversion:** Convert downloaded MP4 videos into GIF format - **MP4 → GIF conversion:** Convert downloaded MP4 videos into GIF format
- Downloads at original quality - Downloads at original quality
## 🖼️ Screenshots ## 🖼️ Screenshots
![image](https://github.com/user-attachments/assets/216cfa1d-90eb-4b48-bacf-42e943f5bbee) ![image](https://github.com/user-attachments/assets/bae739f3-c6be-415f-8e9b-18cceae659f6)
![image](https://github.com/user-attachments/assets/cfb57b60-661d-4d82-a1f3-1e859a33e8c4) ![image](https://github.com/user-attachments/assets/cfb57b60-661d-4d82-a1f3-1e859a33e8c4)
@@ -77,7 +77,7 @@ pip install pyinstaller
### 5. Build the Application ### 5. Build the Application
```bash ```bash
pyinstaller --onefile --windowed TwitterXMediaBatchDownloader.py pyinstaller --onefile --windowed TwitterXMediaBatchDownloader_Linux.py
``` ```
The compiled binary will be located in the `dist/` folder. The compiled binary will be located in the `dist/` folder.
@@ -121,7 +121,7 @@ pip install pyinstaller
### 6. Build the Application ### 6. Build the Application
```bash ```bash
pyinstaller --onefile --windowed --icon=Archived/icon.icns TwitterXMediaBatchDownloader.py pyinstaller --onefile --windowed --icon=Archived/icon.icns TwitterXMediaBatchDownloader_Mac.py
``` ```
The `.app` bundle will be generated inside the `dist/` folder. The `.app` bundle will be generated inside the `dist/` folder.
+198 -38
View File
@@ -13,7 +13,7 @@ from packaging import version
from dataclasses import dataclass from dataclasses import dataclass
from PyQt6.QtWidgets import ( from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLineEdit, QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLineEdit,
QLabel, QFileDialog, QListWidget, QTextEdit, QTabWidget, QAbstractItemView, QSpacerItem, QSizePolicy, QProgressBar, QCheckBox, QDialog, QLabel, QFileDialog, QListWidget, QTextEdit, QTabWidget, QAbstractItemView, QProgressBar, QCheckBox, QDialog,
QDialogButtonBox, QComboBox, QListWidgetItem QDialogButtonBox, QComboBox, QListWidgetItem
) )
from PyQt6.QtCore import Qt, QThread, pyqtSignal, QUrl, QTimer, QTime, QSettings, QSize from PyQt6.QtCore import Qt, QThread, pyqtSignal, QUrl, QTimer, QTime, QSettings, QSize
@@ -31,6 +31,8 @@ class Account:
media_type: str media_type: str
profile_image: str = None profile_image: str = None
media_list: list = None media_list: list = None
fetch_mode: str = 'all'
fetch_timestamp: str = None
class MetadataFetchWorker(QThread): class MetadataFetchWorker(QThread):
finished = pyqtSignal(dict) finished = pyqtSignal(dict)
@@ -342,7 +344,7 @@ class UpdateDialog(QDialog):
class TwitterMediaDownloaderGUI(QWidget): class TwitterMediaDownloaderGUI(QWidget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.current_version = "3.3" self.current_version = "3.4"
self.accounts = [] self.accounts = []
self.temp_dir = os.path.join(tempfile.gettempdir(), "twitterxmediabatchdownloader") self.temp_dir = os.path.join(tempfile.gettempdir(), "twitterxmediabatchdownloader")
os.makedirs(self.temp_dir, exist_ok=True) os.makedirs(self.temp_dir, exist_ok=True)
@@ -384,6 +386,42 @@ class TwitterMediaDownloaderGUI(QWidget):
if self.check_for_updates: if self.check_for_updates:
QTimer.singleShot(0, self.check_updates) QTimer.singleShot(0, self.check_updates)
def get_time_ago(self, timestamp_str):
if not timestamp_str:
return "Unknown"
try:
fetch_time = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
now = datetime.now(fetch_time.tzinfo) if fetch_time.tzinfo else datetime.now()
diff = now - fetch_time
days = diff.days
hours = diff.seconds // 3600
minutes = (diff.seconds % 3600) // 60
if days > 0:
return f"{days} day{'s' if days != 1 else ''} ago"
elif hours > 0:
return f"{hours} hour{'s' if hours != 1 else ''} ago"
elif minutes > 0:
return f"{minutes} minute{'s' if minutes != 1 else ''} ago"
else:
return "Just now"
except:
return "Unknown"
def format_fetch_info(self, timestamp_str):
if not timestamp_str:
return "Fetched: Unknown"
try:
fetch_time = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
formatted_datetime = fetch_time.strftime("%Y/%m/%d • %H:%M")
age = self.get_time_ago(timestamp_str)
return f"Fetched: {formatted_datetime} ({age})"
except:
return "Fetched: Unknown"
def check_updates(self): def check_updates(self):
try: try:
response = requests.get("https://raw.githubusercontent.com/afkarxyz/Twitter-X-Media-Batch-Downloader/refs/heads/main/version.json") response = requests.get("https://raw.githubusercontent.com/afkarxyz/Twitter-X-Media-Batch-Downloader/refs/heads/main/version.json")
@@ -469,25 +507,21 @@ class TwitterMediaDownloaderGUI(QWidget):
dashboard_layout = QVBoxLayout() dashboard_layout = QVBoxLayout()
self.account_list = QListWidget() self.account_list = QListWidget()
self.account_list.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) self.account_list.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
self.account_list.itemSelectionChanged.connect(self.update_button_states) self.account_list.itemSelectionChanged.connect(self.update_button_states)
self.account_list.setIconSize(QSize(48, 48)) self.account_list.setIconSize(QSize(48, 48))
self.account_list.setWordWrap(True) self.account_list.setWordWrap(True)
self.account_list.setStyleSheet(""" self.account_list.setStyleSheet("""
QListWidget { QListWidget {
background-color: palette(base); background-color: palette(base);
border: 1px solid palette(mid);
padding: 4px; padding: 4px;
outline: none; outline: none;
font-size: 13px; }
}
QListWidget::item { QListWidget::item {
padding: 8px 12px; padding: 3px 6px;
margin: 1px 0px; margin: 0px 0px;
border: none; border: none;
outline: none; outline: none;
min-height: 65px;
max-height: 75px;
} }
QListWidget::item:selected { QListWidget::item:selected {
background-color: palette(highlight); background-color: palette(highlight);
@@ -515,21 +549,21 @@ class TwitterMediaDownloaderGUI(QWidget):
def setup_account_buttons(self): def setup_account_buttons(self):
self.btn_layout = QHBoxLayout() self.btn_layout = QHBoxLayout()
self.download_selected_btn = QPushButton('Download Selected') self.download_selected_btn = QPushButton('Download Selected')
self.download_all_btn = QPushButton('Download All') self.update_selected_btn = QPushButton('Update Selected')
self.remove_btn = QPushButton('Remove Selected') self.remove_btn = QPushButton('Remove Selected')
self.clear_btn = QPushButton('Clear') self.clear_btn = QPushButton('Clear')
for btn in [self.download_selected_btn, self.download_all_btn, self.remove_btn, self.clear_btn]: for btn in [self.download_selected_btn, self.update_selected_btn, self.remove_btn, self.clear_btn]:
btn.setMinimumWidth(120) btn.setMinimumWidth(120)
btn.setCursor(Qt.CursorShape.PointingHandCursor) btn.setCursor(Qt.CursorShape.PointingHandCursor)
self.download_selected_btn.clicked.connect(self.download_selected) self.download_selected_btn.clicked.connect(self.download_selected)
self.download_all_btn.clicked.connect(self.download_all) self.update_selected_btn.clicked.connect(self.update_selected)
self.remove_btn.clicked.connect(self.remove_selected_accounts) self.remove_btn.clicked.connect(self.remove_selected_accounts)
self.clear_btn.clicked.connect(self.clear_accounts) self.clear_btn.clicked.connect(self.clear_accounts)
self.btn_layout.addStretch() self.btn_layout.addStretch()
for btn in [self.download_selected_btn, self.download_all_btn, self.remove_btn, self.clear_btn]: for btn in [self.download_selected_btn, self.update_selected_btn, self.remove_btn, self.clear_btn]:
self.btn_layout.addWidget(btn, 1) self.btn_layout.addWidget(btn, 1)
self.btn_layout.addStretch() self.btn_layout.addStretch()
@@ -804,20 +838,19 @@ class TwitterMediaDownloaderGUI(QWidget):
section_layout.setContentsMargins(0, 0, 0, 0) section_layout.setContentsMargins(0, 0, 0, 0)
label = QLabel(title) label = QLabel(title)
label.setStyleSheet("color: palette(text); font-weight: bold;") label.setStyleSheet("font-weight: bold;")
label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setAlignment(Qt.AlignmentFlag.AlignCenter)
section_layout.addWidget(label) section_layout.addWidget(label)
button = QPushButton(button_text) button = QPushButton(button_text)
button.setFixedSize(120, 25) button.setFixedSize(100, 25)
button.setCursor(Qt.CursorShape.PointingHandCursor) button.setCursor(Qt.CursorShape.PointingHandCursor)
button.clicked.connect(lambda _, url=url: QDesktopServices.openUrl(QUrl(url if url.startswith(('http://', 'https://')) else f'https://{url}'))) button.clicked.connect(lambda _, url=url: QDesktopServices.openUrl(QUrl(url if url.startswith(('http://', 'https://')) else f'https://{url}')))
section_layout.addWidget(button, alignment=Qt.AlignmentFlag.AlignCenter) section_layout.addWidget(button, alignment=Qt.AlignmentFlag.AlignCenter)
about_layout.addWidget(section_widget) about_layout.addWidget(section_widget)
footer_label = QLabel(f"v{self.current_version} | gallery-dl v1.30.1 | July 2025") footer_label = QLabel(f"v{self.current_version} | gallery-dl v1.30.2 | August 2025")
footer_label.setStyleSheet("font-size: 12px; margin-top: 20px;")
about_layout.addWidget(footer_label, alignment=Qt.AlignmentFlag.AlignCenter) about_layout.addWidget(footer_label, alignment=Qt.AlignmentFlag.AlignCenter)
about_tab.setLayout(about_layout) about_tab.setLayout(about_layout)
@@ -1030,7 +1063,9 @@ class TwitterMediaDownloaderGUI(QWidget):
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
profile_image=profile_image_url, profile_image=profile_image_url,
media_list=timeline media_list=timeline,
fetch_mode='batch' if cached_data.get('is_batch', False) else 'all',
fetch_timestamp=cached_data.get('fetch_timestamp')
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1107,7 +1142,9 @@ class TwitterMediaDownloaderGUI(QWidget):
following=following, following=following,
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
media_list=timeline media_list=timeline,
fetch_mode='batch' if cached_data.get('is_batch', False) else 'all',
fetch_timestamp=cached_data.get('fetch_timestamp')
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1192,7 +1229,9 @@ class TwitterMediaDownloaderGUI(QWidget):
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
profile_image=profile_image_url, profile_image=profile_image_url,
media_list=timeline media_list=timeline,
fetch_mode='batch' if self.batch_mode else 'all',
fetch_timestamp=datetime.now().isoformat()
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1202,7 +1241,9 @@ class TwitterMediaDownloaderGUI(QWidget):
updated_data = { updated_data = {
'account_info': account_info, 'account_info': account_info,
'timeline': existing_account.media_list, 'timeline': existing_account.media_list,
'metadata': metadata 'metadata': metadata,
'is_batch': self.batch_mode,
'fetch_timestamp': existing_account.fetch_timestamp
} }
self.save_cached_data(username, media_type, updated_data, is_batch=self.batch_mode) self.save_cached_data(username, media_type, updated_data, is_batch=self.batch_mode)
@@ -1240,7 +1281,12 @@ class TwitterMediaDownloaderGUI(QWidget):
self.log_output.append(f'All batches complete! Total: {total_items:,} media items for {username}') self.log_output.append(f'All batches complete! Total: {total_items:,} media items for {username}')
self.twitter_url.clear() self.twitter_url.clear()
self.tab_widget.setCurrentIndex(0)
if hasattr(self, 'accounts_to_update') and hasattr(self, 'current_update_index'):
self.current_update_index += 1
self.update_next_account()
else:
self.tab_widget.setCurrentIndex(0)
except Exception as e: except Exception as e:
self.log_output.append(f'Error: {str(e)}') self.log_output.append(f'Error: {str(e)}')
self.update_account_list() self.update_account_list()
@@ -1257,6 +1303,10 @@ class TwitterMediaDownloaderGUI(QWidget):
self.enable_batch_buttons() self.enable_batch_buttons()
if hasattr(self, 'accounts_to_update') and hasattr(self, 'current_update_index'):
self.current_update_index += 1
self.update_next_account()
self.update_account_list() self.update_account_list()
def update_account_list(self): def update_account_list(self):
@@ -1267,21 +1317,22 @@ class TwitterMediaDownloaderGUI(QWidget):
line1 = f"{i}. {account.username} ({account.nick})" line1 = f"{i}. {account.username} ({account.nick})"
line2 = f"Followers: {account.followers:,} • Following: {account.following:,} • Posts: {account.posts:,} • {media_type_display}: {media_count:,}" line2 = f"Followers: {account.followers:,} • Following: {account.following:,} • Posts: {account.posts:,} • {media_type_display}: {media_count:,}"
display_text = f"{line1}\n{line2}" line3 = self.format_fetch_info(account.fetch_timestamp)
display_text = f"{line1}\n{line2}\n{line3}"
item = QListWidgetItem() item = QListWidgetItem()
item.setText(display_text) item.setText(display_text)
item.setSizeHint(QSize(0, 75)) item.setSizeHint(QSize(0, 70))
if account.profile_image: if account.profile_image:
if account.profile_image in self.profile_image_cache: if account.profile_image in self.profile_image_cache:
item.setIcon(QIcon(self.profile_image_cache[account.profile_image])) item.setIcon(QIcon(self.profile_image_cache[account.profile_image]))
else: else:
self.download_profile_image(account.profile_image) self.download_profile_image(account.profile_image)
placeholder = self.create_placeholder_icon(64) placeholder = self.create_placeholder_icon(48)
if placeholder: if placeholder:
item.setIcon(QIcon(placeholder)) item.setIcon(QIcon(placeholder))
else: else:
placeholder = self.create_placeholder_icon(64) placeholder = self.create_placeholder_icon(48)
if placeholder: if placeholder:
item.setIcon(QIcon(placeholder)) item.setIcon(QIcon(placeholder))
@@ -1289,7 +1340,7 @@ class TwitterMediaDownloaderGUI(QWidget):
self.update_button_states() self.update_button_states()
def create_placeholder_icon(self, size=36): def create_placeholder_icon(self, size=48):
pixmap = QPixmap(size, size) pixmap = QPixmap(size, size)
pixmap.fill(Qt.GlobalColor.transparent) pixmap.fill(Qt.GlobalColor.transparent)
@@ -1308,7 +1359,7 @@ class TwitterMediaDownloaderGUI(QWidget):
painter.end() painter.end()
return pixmap return pixmap
def create_square_pixmap(self, original_pixmap, size=36): def create_square_pixmap(self, original_pixmap, size=48):
if original_pixmap.isNull(): if original_pixmap.isNull():
return self.create_placeholder_icon(size) return self.create_placeholder_icon(size)
@@ -1356,7 +1407,7 @@ class TwitterMediaDownloaderGUI(QWidget):
data = reply.readAll() data = reply.readAll()
pixmap = QPixmap() pixmap = QPixmap()
if pixmap.loadFromData(data): if pixmap.loadFromData(data):
square_pixmap = self.create_square_pixmap(pixmap, 64) square_pixmap = self.create_square_pixmap(pixmap, 48)
self.profile_image_cache[image_url] = square_pixmap self.profile_image_cache[image_url] = square_pixmap
self.update_account_list() self.update_account_list()
@@ -1372,14 +1423,16 @@ class TwitterMediaDownloaderGUI(QWidget):
def update_button_states(self): def update_button_states(self):
has_accounts = len(self.accounts) > 0 has_accounts = len(self.accounts) > 0
self.download_selected_btn.setEnabled(has_accounts) has_selected = len(self.account_list.selectedItems()) > 0
self.download_all_btn.setEnabled(has_accounts)
self.remove_btn.setEnabled(has_accounts) self.download_selected_btn.setEnabled(has_accounts and has_selected)
self.update_selected_btn.setEnabled(has_accounts and has_selected)
self.remove_btn.setEnabled(has_accounts and has_selected)
self.clear_btn.setEnabled(has_accounts) self.clear_btn.setEnabled(has_accounts)
if has_accounts: if has_accounts:
self.download_selected_btn.show() self.download_selected_btn.show()
self.download_all_btn.show() self.update_selected_btn.show()
self.remove_btn.show() self.remove_btn.show()
self.clear_btn.show() self.clear_btn.show()
else: else:
@@ -1388,7 +1441,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def hide_account_buttons(self): def hide_account_buttons(self):
buttons = [ buttons = [
self.download_selected_btn, self.download_selected_btn,
self.download_all_btn, self.update_selected_btn,
self.remove_btn, self.remove_btn,
self.clear_btn self.clear_btn
] ]
@@ -1405,6 +1458,113 @@ class TwitterMediaDownloaderGUI(QWidget):
def download_all(self): def download_all(self):
self.download_accounts(range(len(self.accounts))) self.download_accounts(range(len(self.accounts)))
def update_selected(self):
selected_items = self.account_list.selectedItems()
if not selected_items:
self.log_output.append('Warning: Please select accounts to update.')
return
selected_accounts = []
for item in selected_items:
index = self.account_list.row(item)
if index < len(self.accounts):
selected_accounts.append(self.accounts[index])
if not selected_accounts:
return
self.tab_widget.setCurrentIndex(1)
self.log_output.clear()
self.log_output.append(f'Starting update for {len(selected_accounts)} account(s)...')
self.accounts_to_update = selected_accounts.copy()
self.current_update_index = 0
self.update_next_account()
def update_next_account(self):
if not hasattr(self, 'accounts_to_update') or self.current_update_index >= len(self.accounts_to_update):
self.log_output.append('All selected accounts have been updated!')
if hasattr(self, 'accounts_to_update'):
delattr(self, 'accounts_to_update')
if hasattr(self, 'current_update_index'):
delattr(self, 'current_update_index')
return
account = self.accounts_to_update[self.current_update_index]
self.log_output.append(f'Updating account {self.current_update_index + 1}/{len(self.accounts_to_update)}: {account.username} ({account.media_type})')
self.update_account(account)
def update_account(self, account):
original_batch_mode = self.batch_mode
original_batch_size = self.batch_size
original_media_type = self.media_type_combo.currentData()
self.batch_mode = (account.fetch_mode == 'batch')
if self.batch_mode:
self.batch_size = self.settings.value('batch_size', 100, type=int)
for i in range(self.media_type_combo.count()):
if self.media_type_combo.itemData(i) == account.media_type:
self.media_type_combo.setCurrentIndex(i)
break
self.twitter_url.setText(account.username)
self.tab_widget.setCurrentIndex(1)
self.log_output.append(f'Updating {account.username} ({account.media_type}) using {account.fetch_mode} mode...')
username = account.username
media_type = account.media_type
for is_batch in [True, False]:
cache_file = self.get_cache_file_path(username, media_type, is_batch=is_batch)
try:
if os.path.exists(cache_file):
os.remove(cache_file)
self.log_output.append(f'Removed existing cache: {os.path.basename(cache_file)}')
except Exception as e:
self.log_output.append(f'Warning: Could not remove cache {os.path.basename(cache_file)}: {str(e)}')
for i, existing_account in enumerate(self.accounts):
if existing_account.username == account.username and existing_account.media_type == account.media_type:
self.accounts.pop(i)
break
self.update_account_list()
self.start_fetch_process(username, media_type)
self.batch_mode = original_batch_mode
self.batch_size = original_batch_size
for i in range(self.media_type_combo.count()):
if self.media_type_combo.itemData(i) == original_media_type:
self.media_type_combo.setCurrentIndex(i)
break
def start_fetch_process(self, username, media_type):
if not self.auth_token_input.text().strip():
self.log_output.append("Error: Please enter your auth token")
return
self.current_page = 0
self.disable_batch_buttons()
self.worker = MetadataFetchWorker(
username,
media_type,
batch_mode=self.batch_mode,
batch_size=self.batch_size if self.batch_mode else 0,
page=0
)
self.worker.auth_token = self.auth_token_input.text().strip()
self.worker.finished.connect(lambda data: self.on_metadata_fetched(data, username, media_type))
self.worker.error.connect(self.on_metadata_error)
self.worker.start()
def download_accounts(self, indices): def download_accounts(self, indices):
self.log_output.clear() self.log_output.clear()
outpath = self.output_dir.text() outpath = self.output_dir.text()
@@ -1443,7 +1603,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def update_ui_for_download_start(self, account_count): def update_ui_for_download_start(self, account_count):
self.download_selected_btn.setEnabled(False) self.download_selected_btn.setEnabled(False)
self.download_all_btn.setEnabled(False) self.update_selected_btn.setEnabled(False)
self.stop_btn.show() self.stop_btn.show()
self.pause_resume_btn.show() self.pause_resume_btn.show()
@@ -1527,7 +1687,7 @@ class TwitterMediaDownloaderGUI(QWidget):
self.stop_timer() self.stop_timer()
self.download_selected_btn.setEnabled(True) self.download_selected_btn.setEnabled(True)
self.download_all_btn.setEnabled(True) self.update_selected_btn.setEnabled(True)
if (self.batch_mode and self.current_fetch_metadata and if (self.batch_mode and self.current_fetch_metadata and
self.current_fetch_metadata.get('has_more', False) and not self.is_auto_fetching): self.current_fetch_metadata.get('has_more', False) and not self.is_auto_fetching):
@@ -1674,7 +1834,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def show_account_buttons(self): def show_account_buttons(self):
self.download_selected_btn.show() self.download_selected_btn.show()
self.download_all_btn.show() self.update_selected_btn.show()
self.remove_btn.show() self.remove_btn.show()
self.clear_btn.show() self.clear_btn.show()
+199 -35
View File
@@ -13,7 +13,7 @@ from packaging import version
from dataclasses import dataclass from dataclasses import dataclass
from PyQt6.QtWidgets import ( from PyQt6.QtWidgets import (
QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLineEdit, QApplication, QWidget, QVBoxLayout, QHBoxLayout, QPushButton, QLineEdit,
QLabel, QFileDialog, QListWidget, QTextEdit, QTabWidget, QAbstractItemView, QSpacerItem, QSizePolicy, QProgressBar, QCheckBox, QDialog, QLabel, QFileDialog, QListWidget, QTextEdit, QTabWidget, QAbstractItemView, QProgressBar, QCheckBox, QDialog,
QDialogButtonBox, QComboBox, QListWidgetItem QDialogButtonBox, QComboBox, QListWidgetItem
) )
from PyQt6.QtCore import Qt, QThread, pyqtSignal, QUrl, QTimer, QTime, QSettings, QSize from PyQt6.QtCore import Qt, QThread, pyqtSignal, QUrl, QTimer, QTime, QSettings, QSize
@@ -31,6 +31,8 @@ class Account:
media_type: str media_type: str
profile_image: str = None profile_image: str = None
media_list: list = None media_list: list = None
fetch_mode: str = 'all'
fetch_timestamp: str = None
class MetadataFetchWorker(QThread): class MetadataFetchWorker(QThread):
finished = pyqtSignal(dict) finished = pyqtSignal(dict)
@@ -342,7 +344,7 @@ class UpdateDialog(QDialog):
class TwitterMediaDownloaderGUI(QWidget): class TwitterMediaDownloaderGUI(QWidget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.current_version = "3.3" self.current_version = "3.4"
self.accounts = [] self.accounts = []
self.temp_dir = os.path.join(tempfile.gettempdir(), "twitterxmediabatchdownloader") self.temp_dir = os.path.join(tempfile.gettempdir(), "twitterxmediabatchdownloader")
os.makedirs(self.temp_dir, exist_ok=True) os.makedirs(self.temp_dir, exist_ok=True)
@@ -384,6 +386,42 @@ class TwitterMediaDownloaderGUI(QWidget):
if self.check_for_updates: if self.check_for_updates:
QTimer.singleShot(0, self.check_updates) QTimer.singleShot(0, self.check_updates)
def get_time_ago(self, timestamp_str):
if not timestamp_str:
return "Unknown"
try:
fetch_time = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
now = datetime.now(fetch_time.tzinfo) if fetch_time.tzinfo else datetime.now()
diff = now - fetch_time
days = diff.days
hours = diff.seconds // 3600
minutes = (diff.seconds % 3600) // 60
if days > 0:
return f"{days} day{'s' if days != 1 else ''} ago"
elif hours > 0:
return f"{hours} hour{'s' if hours != 1 else ''} ago"
elif minutes > 0:
return f"{minutes} minute{'s' if minutes != 1 else ''} ago"
else:
return "Just now"
except:
return "Unknown"
def format_fetch_info(self, timestamp_str):
if not timestamp_str:
return "Fetched: Unknown"
try:
fetch_time = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
formatted_datetime = fetch_time.strftime("%Y/%m/%d • %H:%M")
age = self.get_time_ago(timestamp_str)
return f"Fetched: {formatted_datetime} ({age})"
except:
return "Fetched: Unknown"
def check_updates(self): def check_updates(self):
try: try:
response = requests.get("https://raw.githubusercontent.com/afkarxyz/Twitter-X-Media-Batch-Downloader/refs/heads/main/version.json") response = requests.get("https://raw.githubusercontent.com/afkarxyz/Twitter-X-Media-Batch-Downloader/refs/heads/main/version.json")
@@ -471,17 +509,17 @@ class TwitterMediaDownloaderGUI(QWidget):
self.account_list = QListWidget() self.account_list = QListWidget()
self.account_list.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) self.account_list.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
self.account_list.itemSelectionChanged.connect(self.update_button_states) self.account_list.itemSelectionChanged.connect(self.update_button_states)
self.account_list.setIconSize(QSize(36, 36)) self.account_list.setIconSize(QSize(48, 48))
self.account_list.setWordWrap(True)
self.account_list.setStyleSheet(""" self.account_list.setStyleSheet("""
QListWidget { QListWidget {
background-color: palette(base); background-color: palette(base);
border: 1px solid palette(mid); padding: 4px;
padding: 0px;
outline: none; outline: none;
} }
QListWidget::item { QListWidget::item {
padding: 8px 12px; padding: 3px 6px;
margin: 2px 0px; margin: 0px 0px;
border: none; border: none;
outline: none; outline: none;
} }
@@ -511,21 +549,21 @@ class TwitterMediaDownloaderGUI(QWidget):
def setup_account_buttons(self): def setup_account_buttons(self):
self.btn_layout = QHBoxLayout() self.btn_layout = QHBoxLayout()
self.download_selected_btn = QPushButton('Download Selected') self.download_selected_btn = QPushButton('Download Selected')
self.download_all_btn = QPushButton('Download All') self.update_selected_btn = QPushButton('Update Selected')
self.remove_btn = QPushButton('Remove Selected') self.remove_btn = QPushButton('Remove Selected')
self.clear_btn = QPushButton('Clear') self.clear_btn = QPushButton('Clear')
for btn in [self.download_selected_btn, self.download_all_btn, self.remove_btn, self.clear_btn]: for btn in [self.download_selected_btn, self.update_selected_btn, self.remove_btn, self.clear_btn]:
btn.setMinimumWidth(120) btn.setMinimumWidth(120)
btn.setCursor(Qt.CursorShape.PointingHandCursor) btn.setCursor(Qt.CursorShape.PointingHandCursor)
self.download_selected_btn.clicked.connect(self.download_selected) self.download_selected_btn.clicked.connect(self.download_selected)
self.download_all_btn.clicked.connect(self.download_all) self.update_selected_btn.clicked.connect(self.update_selected)
self.remove_btn.clicked.connect(self.remove_selected_accounts) self.remove_btn.clicked.connect(self.remove_selected_accounts)
self.clear_btn.clicked.connect(self.clear_accounts) self.clear_btn.clicked.connect(self.clear_accounts)
self.btn_layout.addStretch() self.btn_layout.addStretch()
for btn in [self.download_selected_btn, self.download_all_btn, self.remove_btn, self.clear_btn]: for btn in [self.download_selected_btn, self.update_selected_btn, self.remove_btn, self.clear_btn]:
self.btn_layout.addWidget(btn, 1) self.btn_layout.addWidget(btn, 1)
self.btn_layout.addStretch() self.btn_layout.addStretch()
@@ -800,20 +838,19 @@ class TwitterMediaDownloaderGUI(QWidget):
section_layout.setContentsMargins(0, 0, 0, 0) section_layout.setContentsMargins(0, 0, 0, 0)
label = QLabel(title) label = QLabel(title)
label.setStyleSheet("color: palette(text); font-weight: bold;") label.setStyleSheet("font-weight: bold;")
label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setAlignment(Qt.AlignmentFlag.AlignCenter)
section_layout.addWidget(label) section_layout.addWidget(label)
button = QPushButton(button_text) button = QPushButton(button_text)
button.setFixedSize(120, 25) button.setFixedSize(100, 25)
button.setCursor(Qt.CursorShape.PointingHandCursor) button.setCursor(Qt.CursorShape.PointingHandCursor)
button.clicked.connect(lambda _, url=url: QDesktopServices.openUrl(QUrl(url if url.startswith(('http://', 'https://')) else f'https://{url}'))) button.clicked.connect(lambda _, url=url: QDesktopServices.openUrl(QUrl(url if url.startswith(('http://', 'https://')) else f'https://{url}')))
section_layout.addWidget(button, alignment=Qt.AlignmentFlag.AlignCenter) section_layout.addWidget(button, alignment=Qt.AlignmentFlag.AlignCenter)
about_layout.addWidget(section_widget) about_layout.addWidget(section_widget)
footer_label = QLabel(f"v{self.current_version} | gallery-dl v1.30.1 | July 2025") footer_label = QLabel(f"v{self.current_version} | gallery-dl v1.30.2 | August 2025")
footer_label.setStyleSheet("font-size: 12px; margin-top: 20px;")
about_layout.addWidget(footer_label, alignment=Qt.AlignmentFlag.AlignCenter) about_layout.addWidget(footer_label, alignment=Qt.AlignmentFlag.AlignCenter)
about_tab.setLayout(about_layout) about_tab.setLayout(about_layout)
@@ -1026,7 +1063,9 @@ class TwitterMediaDownloaderGUI(QWidget):
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
profile_image=profile_image_url, profile_image=profile_image_url,
media_list=timeline media_list=timeline,
fetch_mode='batch' if cached_data.get('is_batch', False) else 'all',
fetch_timestamp=cached_data.get('fetch_timestamp')
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1103,7 +1142,9 @@ class TwitterMediaDownloaderGUI(QWidget):
following=following, following=following,
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
media_list=timeline media_list=timeline,
fetch_mode='batch' if cached_data.get('is_batch', False) else 'all',
fetch_timestamp=cached_data.get('fetch_timestamp')
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1188,7 +1229,9 @@ class TwitterMediaDownloaderGUI(QWidget):
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
profile_image=profile_image_url, profile_image=profile_image_url,
media_list=timeline media_list=timeline,
fetch_mode='batch' if self.batch_mode else 'all',
fetch_timestamp=datetime.now().isoformat()
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1198,7 +1241,9 @@ class TwitterMediaDownloaderGUI(QWidget):
updated_data = { updated_data = {
'account_info': account_info, 'account_info': account_info,
'timeline': existing_account.media_list, 'timeline': existing_account.media_list,
'metadata': metadata 'metadata': metadata,
'is_batch': self.batch_mode,
'fetch_timestamp': existing_account.fetch_timestamp
} }
self.save_cached_data(username, media_type, updated_data, is_batch=self.batch_mode) self.save_cached_data(username, media_type, updated_data, is_batch=self.batch_mode)
@@ -1236,7 +1281,12 @@ class TwitterMediaDownloaderGUI(QWidget):
self.log_output.append(f'All batches complete! Total: {total_items:,} media items for {username}') self.log_output.append(f'All batches complete! Total: {total_items:,} media items for {username}')
self.twitter_url.clear() self.twitter_url.clear()
self.tab_widget.setCurrentIndex(0)
if hasattr(self, 'accounts_to_update') and hasattr(self, 'current_update_index'):
self.current_update_index += 1
self.update_next_account()
else:
self.tab_widget.setCurrentIndex(0)
except Exception as e: except Exception as e:
self.log_output.append(f'Error: {str(e)}') self.log_output.append(f'Error: {str(e)}')
self.update_account_list() self.update_account_list()
@@ -1253,6 +1303,10 @@ class TwitterMediaDownloaderGUI(QWidget):
self.enable_batch_buttons() self.enable_batch_buttons()
if hasattr(self, 'accounts_to_update') and hasattr(self, 'current_update_index'):
self.current_update_index += 1
self.update_next_account()
self.update_account_list() self.update_account_list()
def update_account_list(self): def update_account_list(self):
@@ -1263,21 +1317,22 @@ class TwitterMediaDownloaderGUI(QWidget):
line1 = f"{i}. {account.username} ({account.nick})" line1 = f"{i}. {account.username} ({account.nick})"
line2 = f"Followers: {account.followers:,} • Following: {account.following:,} • Posts: {account.posts:,} • {media_type_display}: {media_count:,}" line2 = f"Followers: {account.followers:,} • Following: {account.following:,} • Posts: {account.posts:,} • {media_type_display}: {media_count:,}"
display_text = f"{line1}\n{line2}" line3 = self.format_fetch_info(account.fetch_timestamp)
display_text = f"{line1}\n{line2}\n{line3}"
item = QListWidgetItem() item = QListWidgetItem()
item.setText(display_text) item.setText(display_text)
item.setSizeHint(QSize(0, 52)) item.setSizeHint(QSize(0, 70))
if account.profile_image: if account.profile_image:
if account.profile_image in self.profile_image_cache: if account.profile_image in self.profile_image_cache:
item.setIcon(QIcon(self.profile_image_cache[account.profile_image])) item.setIcon(QIcon(self.profile_image_cache[account.profile_image]))
else: else:
self.download_profile_image(account.profile_image) self.download_profile_image(account.profile_image)
placeholder = self.create_placeholder_icon(52) placeholder = self.create_placeholder_icon(48)
if placeholder: if placeholder:
item.setIcon(QIcon(placeholder)) item.setIcon(QIcon(placeholder))
else: else:
placeholder = self.create_placeholder_icon(52) placeholder = self.create_placeholder_icon(48)
if placeholder: if placeholder:
item.setIcon(QIcon(placeholder)) item.setIcon(QIcon(placeholder))
@@ -1285,7 +1340,7 @@ class TwitterMediaDownloaderGUI(QWidget):
self.update_button_states() self.update_button_states()
def create_placeholder_icon(self, size=36): def create_placeholder_icon(self, size=48):
pixmap = QPixmap(size, size) pixmap = QPixmap(size, size)
pixmap.fill(Qt.GlobalColor.transparent) pixmap.fill(Qt.GlobalColor.transparent)
@@ -1304,7 +1359,7 @@ class TwitterMediaDownloaderGUI(QWidget):
painter.end() painter.end()
return pixmap return pixmap
def create_square_pixmap(self, original_pixmap, size=36): def create_square_pixmap(self, original_pixmap, size=48):
if original_pixmap.isNull(): if original_pixmap.isNull():
return self.create_placeholder_icon(size) return self.create_placeholder_icon(size)
@@ -1352,7 +1407,7 @@ class TwitterMediaDownloaderGUI(QWidget):
data = reply.readAll() data = reply.readAll()
pixmap = QPixmap() pixmap = QPixmap()
if pixmap.loadFromData(data): if pixmap.loadFromData(data):
square_pixmap = self.create_square_pixmap(pixmap, 52) square_pixmap = self.create_square_pixmap(pixmap, 48)
self.profile_image_cache[image_url] = square_pixmap self.profile_image_cache[image_url] = square_pixmap
self.update_account_list() self.update_account_list()
@@ -1368,14 +1423,16 @@ class TwitterMediaDownloaderGUI(QWidget):
def update_button_states(self): def update_button_states(self):
has_accounts = len(self.accounts) > 0 has_accounts = len(self.accounts) > 0
self.download_selected_btn.setEnabled(has_accounts) has_selected = len(self.account_list.selectedItems()) > 0
self.download_all_btn.setEnabled(has_accounts)
self.remove_btn.setEnabled(has_accounts) self.download_selected_btn.setEnabled(has_accounts and has_selected)
self.update_selected_btn.setEnabled(has_accounts and has_selected)
self.remove_btn.setEnabled(has_accounts and has_selected)
self.clear_btn.setEnabled(has_accounts) self.clear_btn.setEnabled(has_accounts)
if has_accounts: if has_accounts:
self.download_selected_btn.show() self.download_selected_btn.show()
self.download_all_btn.show() self.update_selected_btn.show()
self.remove_btn.show() self.remove_btn.show()
self.clear_btn.show() self.clear_btn.show()
else: else:
@@ -1384,7 +1441,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def hide_account_buttons(self): def hide_account_buttons(self):
buttons = [ buttons = [
self.download_selected_btn, self.download_selected_btn,
self.download_all_btn, self.update_selected_btn,
self.remove_btn, self.remove_btn,
self.clear_btn self.clear_btn
] ]
@@ -1401,6 +1458,113 @@ class TwitterMediaDownloaderGUI(QWidget):
def download_all(self): def download_all(self):
self.download_accounts(range(len(self.accounts))) self.download_accounts(range(len(self.accounts)))
def update_selected(self):
selected_items = self.account_list.selectedItems()
if not selected_items:
self.log_output.append('Warning: Please select accounts to update.')
return
selected_accounts = []
for item in selected_items:
index = self.account_list.row(item)
if index < len(self.accounts):
selected_accounts.append(self.accounts[index])
if not selected_accounts:
return
self.tab_widget.setCurrentIndex(1)
self.log_output.clear()
self.log_output.append(f'Starting update for {len(selected_accounts)} account(s)...')
self.accounts_to_update = selected_accounts.copy()
self.current_update_index = 0
self.update_next_account()
def update_next_account(self):
if not hasattr(self, 'accounts_to_update') or self.current_update_index >= len(self.accounts_to_update):
self.log_output.append('All selected accounts have been updated!')
if hasattr(self, 'accounts_to_update'):
delattr(self, 'accounts_to_update')
if hasattr(self, 'current_update_index'):
delattr(self, 'current_update_index')
return
account = self.accounts_to_update[self.current_update_index]
self.log_output.append(f'Updating account {self.current_update_index + 1}/{len(self.accounts_to_update)}: {account.username} ({account.media_type})')
self.update_account(account)
def update_account(self, account):
original_batch_mode = self.batch_mode
original_batch_size = self.batch_size
original_media_type = self.media_type_combo.currentData()
self.batch_mode = (account.fetch_mode == 'batch')
if self.batch_mode:
self.batch_size = self.settings.value('batch_size', 100, type=int)
for i in range(self.media_type_combo.count()):
if self.media_type_combo.itemData(i) == account.media_type:
self.media_type_combo.setCurrentIndex(i)
break
self.twitter_url.setText(account.username)
self.tab_widget.setCurrentIndex(1)
self.log_output.append(f'Updating {account.username} ({account.media_type}) using {account.fetch_mode} mode...')
username = account.username
media_type = account.media_type
for is_batch in [True, False]:
cache_file = self.get_cache_file_path(username, media_type, is_batch=is_batch)
try:
if os.path.exists(cache_file):
os.remove(cache_file)
self.log_output.append(f'Removed existing cache: {os.path.basename(cache_file)}')
except Exception as e:
self.log_output.append(f'Warning: Could not remove cache {os.path.basename(cache_file)}: {str(e)}')
for i, existing_account in enumerate(self.accounts):
if existing_account.username == account.username and existing_account.media_type == account.media_type:
self.accounts.pop(i)
break
self.update_account_list()
self.start_fetch_process(username, media_type)
self.batch_mode = original_batch_mode
self.batch_size = original_batch_size
for i in range(self.media_type_combo.count()):
if self.media_type_combo.itemData(i) == original_media_type:
self.media_type_combo.setCurrentIndex(i)
break
def start_fetch_process(self, username, media_type):
if not self.auth_token_input.text().strip():
self.log_output.append("Error: Please enter your auth token")
return
self.current_page = 0
self.disable_batch_buttons()
self.worker = MetadataFetchWorker(
username,
media_type,
batch_mode=self.batch_mode,
batch_size=self.batch_size if self.batch_mode else 0,
page=0
)
self.worker.auth_token = self.auth_token_input.text().strip()
self.worker.finished.connect(lambda data: self.on_metadata_fetched(data, username, media_type))
self.worker.error.connect(self.on_metadata_error)
self.worker.start()
def download_accounts(self, indices): def download_accounts(self, indices):
self.log_output.clear() self.log_output.clear()
outpath = self.output_dir.text() outpath = self.output_dir.text()
@@ -1439,7 +1603,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def update_ui_for_download_start(self, account_count): def update_ui_for_download_start(self, account_count):
self.download_selected_btn.setEnabled(False) self.download_selected_btn.setEnabled(False)
self.download_all_btn.setEnabled(False) self.update_selected_btn.setEnabled(False)
self.stop_btn.show() self.stop_btn.show()
self.pause_resume_btn.show() self.pause_resume_btn.show()
@@ -1523,7 +1687,7 @@ class TwitterMediaDownloaderGUI(QWidget):
self.stop_timer() self.stop_timer()
self.download_selected_btn.setEnabled(True) self.download_selected_btn.setEnabled(True)
self.download_all_btn.setEnabled(True) self.update_selected_btn.setEnabled(True)
if (self.batch_mode and self.current_fetch_metadata and if (self.batch_mode and self.current_fetch_metadata and
self.current_fetch_metadata.get('has_more', False) and not self.is_auto_fetching): self.current_fetch_metadata.get('has_more', False) and not self.is_auto_fetching):
@@ -1670,7 +1834,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def show_account_buttons(self): def show_account_buttons(self):
self.download_selected_btn.show() self.download_selected_btn.show()
self.download_all_btn.show() self.update_selected_btn.show()
self.remove_btn.show() self.remove_btn.show()
self.clear_btn.show() self.clear_btn.show()
+197 -33
View File
@@ -32,6 +32,8 @@ class Account:
media_type: str media_type: str
profile_image: str = None profile_image: str = None
media_list: list = None media_list: list = None
fetch_mode: str = 'all'
fetch_timestamp: str = None
class MetadataFetchWorker(QThread): class MetadataFetchWorker(QThread):
finished = pyqtSignal(dict) finished = pyqtSignal(dict)
@@ -343,7 +345,7 @@ class UpdateDialog(QDialog):
class TwitterMediaDownloaderGUI(QWidget): class TwitterMediaDownloaderGUI(QWidget):
def __init__(self): def __init__(self):
super().__init__() super().__init__()
self.current_version = "3.3" self.current_version = "3.4"
self.accounts = [] self.accounts = []
self.temp_dir = os.path.join(tempfile.gettempdir(), "twitterxmediabatchdownloader") self.temp_dir = os.path.join(tempfile.gettempdir(), "twitterxmediabatchdownloader")
os.makedirs(self.temp_dir, exist_ok=True) os.makedirs(self.temp_dir, exist_ok=True)
@@ -386,6 +388,42 @@ class TwitterMediaDownloaderGUI(QWidget):
if self.check_for_updates: if self.check_for_updates:
QTimer.singleShot(0, self.check_updates) QTimer.singleShot(0, self.check_updates)
def get_time_ago(self, timestamp_str):
if not timestamp_str:
return "Unknown"
try:
fetch_time = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
now = datetime.now(fetch_time.tzinfo) if fetch_time.tzinfo else datetime.now()
diff = now - fetch_time
days = diff.days
hours = diff.seconds // 3600
minutes = (diff.seconds % 3600) // 60
if days > 0:
return f"{days} day{'s' if days != 1 else ''} ago"
elif hours > 0:
return f"{hours} hour{'s' if hours != 1 else ''} ago"
elif minutes > 0:
return f"{minutes} minute{'s' if minutes != 1 else ''} ago"
else:
return "Just now"
except:
return "Unknown"
def format_fetch_info(self, timestamp_str):
if not timestamp_str:
return "Fetched: Unknown"
try:
fetch_time = datetime.fromisoformat(timestamp_str.replace('Z', '+00:00'))
formatted_datetime = fetch_time.strftime("%Y/%m/%d • %H:%M")
age = self.get_time_ago(timestamp_str)
return f"Fetched: {formatted_datetime} ({age})"
except:
return "Fetched: Unknown"
def check_updates(self): def check_updates(self):
try: try:
response = requests.get("https://raw.githubusercontent.com/afkarxyz/Twitter-X-Media-Batch-Downloader/refs/heads/main/version.json") response = requests.get("https://raw.githubusercontent.com/afkarxyz/Twitter-X-Media-Batch-Downloader/refs/heads/main/version.json")
@@ -474,15 +512,15 @@ class TwitterMediaDownloaderGUI(QWidget):
self.account_list = QListWidget() self.account_list = QListWidget()
self.account_list.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection) self.account_list.setSelectionMode(QAbstractItemView.SelectionMode.ExtendedSelection)
self.account_list.itemSelectionChanged.connect(self.update_button_states) self.account_list.itemSelectionChanged.connect(self.update_button_states)
self.account_list.setIconSize(QSize(36, 36)) self.account_list.setIconSize(QSize(48, 48))
self.account_list.setStyleSheet(""" self.account_list.setStyleSheet("""
QListWidget { QListWidget {
padding: 0px; padding: 4px;
outline: none; outline: none;
} }
QListWidget::item { QListWidget::item {
padding: 8px 12px; padding: 3px 6px;
margin: 2px 0px; margin: 0px 0px;
border: none; border: none;
outline: none; outline: none;
} }
@@ -508,21 +546,21 @@ class TwitterMediaDownloaderGUI(QWidget):
def setup_account_buttons(self): def setup_account_buttons(self):
self.btn_layout = QHBoxLayout() self.btn_layout = QHBoxLayout()
self.download_selected_btn = QPushButton('Download Selected') self.download_selected_btn = QPushButton('Download Selected')
self.download_all_btn = QPushButton('Download All') self.update_selected_btn = QPushButton('Update Selected')
self.remove_btn = QPushButton('Remove Selected') self.remove_btn = QPushButton('Remove Selected')
self.clear_btn = QPushButton('Clear') self.clear_btn = QPushButton('Clear')
for btn in [self.download_selected_btn, self.download_all_btn, self.remove_btn, self.clear_btn]: for btn in [self.download_selected_btn, self.update_selected_btn, self.remove_btn, self.clear_btn]:
btn.setMinimumWidth(120) btn.setMinimumWidth(120)
btn.setCursor(Qt.CursorShape.PointingHandCursor) btn.setCursor(Qt.CursorShape.PointingHandCursor)
self.download_selected_btn.clicked.connect(self.download_selected) self.download_selected_btn.clicked.connect(self.download_selected)
self.download_all_btn.clicked.connect(self.download_all) self.update_selected_btn.clicked.connect(self.update_selected)
self.remove_btn.clicked.connect(self.remove_selected_accounts) self.remove_btn.clicked.connect(self.remove_selected_accounts)
self.clear_btn.clicked.connect(self.clear_accounts) self.clear_btn.clicked.connect(self.clear_accounts)
self.btn_layout.addStretch() self.btn_layout.addStretch()
for btn in [self.download_selected_btn, self.download_all_btn, self.remove_btn, self.clear_btn]: for btn in [self.download_selected_btn, self.update_selected_btn, self.remove_btn, self.clear_btn]:
self.btn_layout.addWidget(btn, 1) self.btn_layout.addWidget(btn, 1)
self.btn_layout.addStretch() self.btn_layout.addStretch()
@@ -968,20 +1006,19 @@ class TwitterMediaDownloaderGUI(QWidget):
section_layout.setContentsMargins(0, 0, 0, 0) section_layout.setContentsMargins(0, 0, 0, 0)
label = QLabel(title) label = QLabel(title)
label.setStyleSheet("color: palette(text); font-weight: bold;") label.setStyleSheet("font-weight: bold;")
label.setAlignment(Qt.AlignmentFlag.AlignCenter) label.setAlignment(Qt.AlignmentFlag.AlignCenter)
section_layout.addWidget(label) section_layout.addWidget(label)
button = QPushButton(button_text) button = QPushButton(button_text)
button.setFixedSize(120, 25) button.setFixedSize(100, 25)
button.setCursor(Qt.CursorShape.PointingHandCursor) button.setCursor(Qt.CursorShape.PointingHandCursor)
button.clicked.connect(lambda _, url=url: QDesktopServices.openUrl(QUrl(url if url.startswith(('http://', 'https://')) else f'https://{url}'))) button.clicked.connect(lambda _, url=url: QDesktopServices.openUrl(QUrl(url if url.startswith(('http://', 'https://')) else f'https://{url}')))
section_layout.addWidget(button, alignment=Qt.AlignmentFlag.AlignCenter) section_layout.addWidget(button, alignment=Qt.AlignmentFlag.AlignCenter)
about_layout.addWidget(section_widget) about_layout.addWidget(section_widget)
footer_label = QLabel(f"v{self.current_version} | gallery-dl v1.30.1 | July 2025") footer_label = QLabel(f"v{self.current_version} | gallery-dl v1.30.2 | August 2025")
footer_label.setStyleSheet("font-size: 12px; margin-top: 20px;")
about_layout.addWidget(footer_label, alignment=Qt.AlignmentFlag.AlignCenter) about_layout.addWidget(footer_label, alignment=Qt.AlignmentFlag.AlignCenter)
about_tab.setLayout(about_layout) about_tab.setLayout(about_layout)
@@ -1194,7 +1231,9 @@ class TwitterMediaDownloaderGUI(QWidget):
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
profile_image=profile_image_url, profile_image=profile_image_url,
media_list=timeline media_list=timeline,
fetch_mode='batch' if cached_data.get('is_batch', False) else 'all',
fetch_timestamp=cached_data.get('fetch_timestamp')
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1271,7 +1310,9 @@ class TwitterMediaDownloaderGUI(QWidget):
following=following, following=following,
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
media_list=timeline media_list=timeline,
fetch_mode='batch' if cached_data.get('is_batch', False) else 'all',
fetch_timestamp=cached_data.get('fetch_timestamp')
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1356,7 +1397,9 @@ class TwitterMediaDownloaderGUI(QWidget):
posts=posts, posts=posts,
media_type=media_type, media_type=media_type,
profile_image=profile_image_url, profile_image=profile_image_url,
media_list=timeline media_list=timeline,
fetch_mode='batch' if self.batch_mode else 'all',
fetch_timestamp=datetime.now().isoformat()
) )
self.accounts.append(account) self.accounts.append(account)
@@ -1366,7 +1409,9 @@ class TwitterMediaDownloaderGUI(QWidget):
updated_data = { updated_data = {
'account_info': account_info, 'account_info': account_info,
'timeline': existing_account.media_list, 'timeline': existing_account.media_list,
'metadata': metadata 'metadata': metadata,
'is_batch': self.batch_mode,
'fetch_timestamp': existing_account.fetch_timestamp
} }
self.save_cached_data(username, media_type, updated_data, is_batch=self.batch_mode) self.save_cached_data(username, media_type, updated_data, is_batch=self.batch_mode)
@@ -1404,7 +1449,12 @@ class TwitterMediaDownloaderGUI(QWidget):
self.log_output.append(f'All batches complete! Total: {total_items:,} media items for {username}') self.log_output.append(f'All batches complete! Total: {total_items:,} media items for {username}')
self.twitter_url.clear() self.twitter_url.clear()
self.tab_widget.setCurrentIndex(0)
if hasattr(self, 'accounts_to_update') and hasattr(self, 'current_update_index'):
self.current_update_index += 1
self.update_next_account()
else:
self.tab_widget.setCurrentIndex(0)
except Exception as e: except Exception as e:
self.log_output.append(f'Error: {str(e)}') self.log_output.append(f'Error: {str(e)}')
self.update_account_list() self.update_account_list()
@@ -1421,6 +1471,10 @@ class TwitterMediaDownloaderGUI(QWidget):
self.enable_batch_buttons() self.enable_batch_buttons()
if hasattr(self, 'accounts_to_update') and hasattr(self, 'current_update_index'):
self.current_update_index += 1
self.update_next_account()
self.update_account_list() self.update_account_list()
def update_account_list(self): def update_account_list(self):
@@ -1431,21 +1485,22 @@ class TwitterMediaDownloaderGUI(QWidget):
line1 = f"{i}. {account.username} ({account.nick})" line1 = f"{i}. {account.username} ({account.nick})"
line2 = f"Followers: {account.followers:,} • Following: {account.following:,} • Posts: {account.posts:,} • {media_type_display}: {media_count:,}" line2 = f"Followers: {account.followers:,} • Following: {account.following:,} • Posts: {account.posts:,} • {media_type_display}: {media_count:,}"
display_text = f"{line1}\n{line2}" line3 = self.format_fetch_info(account.fetch_timestamp)
display_text = f"{line1}\n{line2}\n{line3}"
item = QListWidgetItem() item = QListWidgetItem()
item.setText(display_text) item.setText(display_text)
item.setSizeHint(QSize(0, 52)) item.setSizeHint(QSize(0, 70))
if account.profile_image: if account.profile_image:
if account.profile_image in self.profile_image_cache: if account.profile_image in self.profile_image_cache:
item.setIcon(QIcon(self.profile_image_cache[account.profile_image])) item.setIcon(QIcon(self.profile_image_cache[account.profile_image]))
else: else:
self.download_profile_image(account.profile_image) self.download_profile_image(account.profile_image)
placeholder = self.create_placeholder_icon(52) placeholder = self.create_placeholder_icon(48)
if placeholder: if placeholder:
item.setIcon(QIcon(placeholder)) item.setIcon(QIcon(placeholder))
else: else:
placeholder = self.create_placeholder_icon(52) placeholder = self.create_placeholder_icon(48)
if placeholder: if placeholder:
item.setIcon(QIcon(placeholder)) item.setIcon(QIcon(placeholder))
@@ -1453,7 +1508,7 @@ class TwitterMediaDownloaderGUI(QWidget):
self.update_button_states() self.update_button_states()
def create_placeholder_icon(self, size=36): def create_placeholder_icon(self, size=48):
pixmap = QPixmap(size, size) pixmap = QPixmap(size, size)
pixmap.fill(Qt.GlobalColor.transparent) pixmap.fill(Qt.GlobalColor.transparent)
@@ -1472,7 +1527,7 @@ class TwitterMediaDownloaderGUI(QWidget):
painter.end() painter.end()
return pixmap return pixmap
def create_square_pixmap(self, original_pixmap, size=36): def create_square_pixmap(self, original_pixmap, size=48):
if original_pixmap.isNull(): if original_pixmap.isNull():
return self.create_placeholder_icon(size) return self.create_placeholder_icon(size)
@@ -1520,7 +1575,7 @@ class TwitterMediaDownloaderGUI(QWidget):
data = reply.readAll() data = reply.readAll()
pixmap = QPixmap() pixmap = QPixmap()
if pixmap.loadFromData(data): if pixmap.loadFromData(data):
square_pixmap = self.create_square_pixmap(pixmap, 52) square_pixmap = self.create_square_pixmap(pixmap, 48)
self.profile_image_cache[image_url] = square_pixmap self.profile_image_cache[image_url] = square_pixmap
self.update_account_list() self.update_account_list()
@@ -1535,15 +1590,16 @@ class TwitterMediaDownloaderGUI(QWidget):
def update_button_states(self): def update_button_states(self):
has_accounts = len(self.accounts) > 0 has_accounts = len(self.accounts) > 0
has_selected = len(self.account_list.selectedItems()) > 0
self.download_selected_btn.setEnabled(has_accounts) self.download_selected_btn.setEnabled(has_accounts and has_selected)
self.download_all_btn.setEnabled(has_accounts) self.update_selected_btn.setEnabled(has_accounts and has_selected)
self.remove_btn.setEnabled(has_accounts) self.remove_btn.setEnabled(has_accounts and has_selected)
self.clear_btn.setEnabled(has_accounts) self.clear_btn.setEnabled(has_accounts)
if has_accounts: if has_accounts:
self.download_selected_btn.show() self.download_selected_btn.show()
self.download_all_btn.show() self.update_selected_btn.show()
self.remove_btn.show() self.remove_btn.show()
self.clear_btn.show() self.clear_btn.show()
else: else:
@@ -1552,7 +1608,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def hide_account_buttons(self): def hide_account_buttons(self):
buttons = [ buttons = [
self.download_selected_btn, self.download_selected_btn,
self.download_all_btn, self.update_selected_btn,
self.remove_btn, self.remove_btn,
self.clear_btn self.clear_btn
] ]
@@ -1569,6 +1625,114 @@ class TwitterMediaDownloaderGUI(QWidget):
def download_all(self): def download_all(self):
self.download_accounts(range(len(self.accounts))) self.download_accounts(range(len(self.accounts)))
def update_selected(self):
selected_items = self.account_list.selectedItems()
if not selected_items:
self.log_output.append('Warning: Please select accounts to update.')
return
selected_accounts = []
for item in selected_items:
index = self.account_list.row(item)
if index < len(self.accounts):
selected_accounts.append(self.accounts[index])
if not selected_accounts:
return
self.tab_widget.setCurrentIndex(1)
self.log_output.clear()
self.log_output.append(f'Starting update for {len(selected_accounts)} account(s)...')
self.accounts_to_update = selected_accounts.copy()
self.current_update_index = 0
self.update_next_account()
def update_next_account(self):
if not hasattr(self, 'accounts_to_update') or self.current_update_index >= len(self.accounts_to_update):
self.log_output.append('All selected accounts have been updated!')
if hasattr(self, 'accounts_to_update'):
delattr(self, 'accounts_to_update')
if hasattr(self, 'current_update_index'):
delattr(self, 'current_update_index')
return
account = self.accounts_to_update[self.current_update_index]
self.log_output.append(f'Updating account {self.current_update_index + 1}/{len(self.accounts_to_update)}: {account.username} ({account.media_type})')
self.update_account(account)
def update_account(self, account):
original_batch_mode = self.batch_mode
original_batch_size = self.batch_size
original_media_type = self.media_type_combo.currentData()
self.batch_mode = (account.fetch_mode == 'batch')
if self.batch_mode:
self.batch_size = self.settings.value('batch_size', 100, type=int)
for i in range(self.media_type_combo.count()):
if self.media_type_combo.itemData(i) == account.media_type:
self.media_type_combo.setCurrentIndex(i)
break
self.twitter_url.setText(account.username)
self.tab_widget.setCurrentIndex(1)
self.log_output.clear()
self.log_output.append(f'Updating {account.username} ({account.media_type}) using {account.fetch_mode} mode...')
username = account.username
media_type = account.media_type
for is_batch in [True, False]:
cache_file = self.get_cache_file_path(username, media_type, is_batch=is_batch)
try:
if os.path.exists(cache_file):
os.remove(cache_file)
self.log_output.append(f'Removed existing cache: {os.path.basename(cache_file)}')
except Exception as e:
self.log_output.append(f'Warning: Could not remove cache {os.path.basename(cache_file)}: {str(e)}')
for i, existing_account in enumerate(self.accounts):
if existing_account.username == account.username and existing_account.media_type == account.media_type:
self.accounts.pop(i)
break
self.update_account_list()
self.start_fetch_process(username, media_type)
self.batch_mode = original_batch_mode
self.batch_size = original_batch_size
for i in range(self.media_type_combo.count()):
if self.media_type_combo.itemData(i) == original_media_type:
self.media_type_combo.setCurrentIndex(i)
break
def start_fetch_process(self, username, media_type):
if not self.auth_token_input.text().strip():
self.log_output.append("Error: Please enter your auth token")
return
self.current_page = 0
self.disable_batch_buttons()
self.worker = MetadataFetchWorker(
username,
media_type,
batch_mode=self.batch_mode,
batch_size=self.batch_size if self.batch_mode else 0,
page=0
)
self.worker.auth_token = self.auth_token_input.text().strip()
self.worker.finished.connect(lambda data: self.on_metadata_fetched(data, username, media_type))
self.worker.error.connect(self.on_metadata_error)
self.worker.start()
def download_accounts(self, indices): def download_accounts(self, indices):
self.log_output.clear() self.log_output.clear()
outpath = self.output_dir.text() outpath = self.output_dir.text()
@@ -1607,7 +1771,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def update_ui_for_download_start(self, account_count): def update_ui_for_download_start(self, account_count):
self.download_selected_btn.setEnabled(False) self.download_selected_btn.setEnabled(False)
self.download_all_btn.setEnabled(False) self.update_selected_btn.setEnabled(False)
self.stop_btn.show() self.stop_btn.show()
self.pause_resume_btn.show() self.pause_resume_btn.show()
@@ -1691,7 +1855,7 @@ class TwitterMediaDownloaderGUI(QWidget):
self.stop_timer() self.stop_timer()
self.download_selected_btn.setEnabled(True) self.download_selected_btn.setEnabled(True)
self.download_all_btn.setEnabled(True) self.update_selected_btn.setEnabled(True)
if (self.batch_mode and self.current_fetch_metadata and if (self.batch_mode and self.current_fetch_metadata and
self.current_fetch_metadata.get('has_more', False) and not self.is_auto_fetching): self.current_fetch_metadata.get('has_more', False) and not self.is_auto_fetching):
@@ -1838,7 +2002,7 @@ class TwitterMediaDownloaderGUI(QWidget):
def show_account_buttons(self): def show_account_buttons(self):
self.download_selected_btn.show() self.download_selected_btn.show()
self.download_all_btn.show() self.update_selected_btn.show()
self.remove_btn.show() self.remove_btn.show()
self.clear_btn.show() self.clear_btn.show()
-3
View File
@@ -1,3 +0,0 @@
{
"version": "3.2"
}
+1 -2
View File
@@ -3,5 +3,4 @@ requests
aiohttp aiohttp
imageio-ffmpeg imageio-ffmpeg
packaging packaging
gallery-dl gallery-dl
pyqtdarktheme
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
"version": "3.1" "version": "3.3"
} }