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 | |
|---|---|---|---|
|
|
f8b27ecb5a | ||
|
|
70e79af700 | ||
|
|
4fb60840a0 | ||
|
|
5613c152f8 | ||
|
|
ad5d7727eb | ||
|
|
ed1f0fce06 |
No files matched your search
@@ -8,7 +8,7 @@
|
|||||||
|
|
||||||
## 📥 Download
|
## 📥 Download
|
||||||
|
|
||||||
- Download the latest version of [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v2.4.5/TwitterXMediaBatchDownloader.exe)
|
- Download the latest version of [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v2.6/TwitterXMediaBatchDownloader.exe)
|
||||||
- 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)
|
||||||
|
|
||||||
## ✨ Features
|
## ✨ Features
|
||||||
@@ -19,11 +19,13 @@
|
|||||||
|
|
||||||
## 🖼️ Screenshots
|
## 🖼️ Screenshots
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
> [!Important]
|
> [!Important]
|
||||||
> Use **Batch** if the items to be downloaded are in the thousands.
|
> Use **Batch** if the items to be downloaded are in the thousands.
|
||||||
|
|||||||
@@ -4,6 +4,7 @@ import asyncio
|
|||||||
import aiohttp
|
import aiohttp
|
||||||
import requests
|
import requests
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import imageio_ffmpeg
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
from packaging import version
|
from packaging import version
|
||||||
@@ -94,7 +95,7 @@ class MediaDownloader(QThread):
|
|||||||
error = pyqtSignal(str)
|
error = pyqtSignal(str)
|
||||||
status_update = pyqtSignal(str)
|
status_update = pyqtSignal(str)
|
||||||
|
|
||||||
def __init__(self, media_list, output_dir, filename_format, username, media_type='all', batch_size=10):
|
def __init__(self, media_list, output_dir, filename_format, username, media_type='all', batch_size=10, convert_gif=False):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.media_list = media_list
|
self.media_list = media_list
|
||||||
self.output_dir = output_dir
|
self.output_dir = output_dir
|
||||||
@@ -102,8 +103,10 @@ class MediaDownloader(QThread):
|
|||||||
self.filename_format = filename_format
|
self.filename_format = filename_format
|
||||||
self.media_type = media_type
|
self.media_type = media_type
|
||||||
self.batch_size = batch_size
|
self.batch_size = batch_size
|
||||||
|
self.convert_gif = convert_gif
|
||||||
self._is_cancelled = False
|
self._is_cancelled = False
|
||||||
self._download_lock = asyncio.Lock()
|
self._download_lock = asyncio.Lock()
|
||||||
|
self.filepath_map = []
|
||||||
|
|
||||||
def cancel(self):
|
def cancel(self):
|
||||||
self._is_cancelled = True
|
self._is_cancelled = True
|
||||||
@@ -112,7 +115,6 @@ class MediaDownloader(QThread):
|
|||||||
try:
|
try:
|
||||||
if os.path.exists(filepath):
|
if os.path.exists(filepath):
|
||||||
return True, True
|
return True, True
|
||||||
|
|
||||||
if self._is_cancelled:
|
if self._is_cancelled:
|
||||||
return False, False
|
return False, False
|
||||||
|
|
||||||
@@ -154,7 +156,28 @@ class MediaDownloader(QThread):
|
|||||||
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', ''))
|
tweet_id = str(item.get('tweet_id', ''))
|
||||||
|
|
||||||
extension = 'mp4' if 'video.twimg.com' in url else 'jpg'
|
item_type = item.get('type', '')
|
||||||
|
if item_type == 'animated_gif':
|
||||||
|
media_type_folder = 'gif'
|
||||||
|
extension = 'mp4'
|
||||||
|
elif item_type == 'video' or 'video.twimg.com' in url:
|
||||||
|
media_type_folder = 'video'
|
||||||
|
extension = 'mp4'
|
||||||
|
else:
|
||||||
|
media_type_folder = 'image'
|
||||||
|
extension = 'jpg'
|
||||||
|
|
||||||
|
if self.media_type == "all":
|
||||||
|
media_output_dir = os.path.join(self.output_dir, media_type_folder)
|
||||||
|
else:
|
||||||
|
if self.media_type == "image":
|
||||||
|
media_output_dir = os.path.join(self.output_dir, "image")
|
||||||
|
elif self.media_type == "video":
|
||||||
|
media_output_dir = os.path.join(self.output_dir, "video")
|
||||||
|
elif self.media_type == "gif":
|
||||||
|
media_output_dir = os.path.join(self.output_dir, "gif")
|
||||||
|
else:
|
||||||
|
media_output_dir = self.output_dir
|
||||||
|
|
||||||
if self.filename_format == "username_date":
|
if self.filename_format == "username_date":
|
||||||
base_filename = f"{self.username}_{formatted_date}_{tweet_id}"
|
base_filename = f"{self.username}_{formatted_date}_{tweet_id}"
|
||||||
@@ -168,8 +191,8 @@ class MediaDownloader(QThread):
|
|||||||
counter += 1
|
counter += 1
|
||||||
|
|
||||||
used_filenames.add(filename)
|
used_filenames.add(filename)
|
||||||
filepath = os.path.join(self.output_dir, filename)
|
filepath = os.path.join(media_output_dir, filename)
|
||||||
|
self.filepath_map.append((item, filepath))
|
||||||
task = asyncio.create_task(self.download_file(session, url, filepath))
|
task = asyncio.create_task(self.download_file(session, url, filepath))
|
||||||
tasks.append(task)
|
tasks.append(task)
|
||||||
|
|
||||||
@@ -215,6 +238,30 @@ class MediaDownloader(QThread):
|
|||||||
try:
|
try:
|
||||||
completed, skipped, failed = asyncio.run(self.download_all())
|
completed, skipped, failed = asyncio.run(self.download_all())
|
||||||
|
|
||||||
|
if getattr(self, 'convert_gif', False):
|
||||||
|
try:
|
||||||
|
ffmpeg_exe = imageio_ffmpeg.get_ffmpeg_exe()
|
||||||
|
gif_items = [(item, fp) for item, fp in self.filepath_map if item.get('type') == 'animated_gif']
|
||||||
|
total_gifs = len(gif_items)
|
||||||
|
if total_gifs > 0:
|
||||||
|
creationflags = subprocess.CREATE_NO_WINDOW if sys.platform == 'win32' else 0
|
||||||
|
self.progress.emit(0)
|
||||||
|
self.status_update.emit("Starting GIF conversion...")
|
||||||
|
for idx, (item, fp) in enumerate(gif_items, start=1):
|
||||||
|
gif_fp = fp.rsplit('.', 1)[0] + '.gif'
|
||||||
|
result = subprocess.run([ffmpeg_exe, '-i', fp, gif_fp], capture_output=True, creationflags=creationflags)
|
||||||
|
if result.returncode == 0 and os.path.exists(gif_fp):
|
||||||
|
try:
|
||||||
|
os.remove(fp)
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
conv_progress = int((idx / total_gifs) * 100)
|
||||||
|
self.progress.emit(conv_progress)
|
||||||
|
self.status_update.emit(f"Converting GIF {idx}/{total_gifs}...")
|
||||||
|
self.status_update.emit("GIF conversion completed")
|
||||||
|
except Exception as conv_e:
|
||||||
|
self.status_update.emit(f"GIF conversion error: {conv_e}")
|
||||||
|
|
||||||
if self._is_cancelled:
|
if self._is_cancelled:
|
||||||
self.status_update.emit("Download cancelled")
|
self.status_update.emit("Download cancelled")
|
||||||
return
|
return
|
||||||
@@ -273,7 +320,7 @@ class UpdateDialog(QDialog):
|
|||||||
class TwitterMediaDownloaderGUI(QMainWindow):
|
class TwitterMediaDownloaderGUI(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
self.current_version = "2.4.5"
|
self.current_version = "2.7"
|
||||||
self.setWindowTitle("Twitter/X Media Batch Downloader")
|
self.setWindowTitle("Twitter/X Media Batch Downloader")
|
||||||
|
|
||||||
self.settings = QSettings('TwitterMediaDownloader', 'Settings')
|
self.settings = QSettings('TwitterMediaDownloader', 'Settings')
|
||||||
@@ -295,6 +342,10 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
|
|
||||||
self.media_info = None
|
self.media_info = None
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
|
if not self.settings.contains('download_batch_size'):
|
||||||
|
index = self.download_batch_combo.findText("25")
|
||||||
|
if index >= 0:
|
||||||
|
self.download_batch_combo.setCurrentIndex(index)
|
||||||
self.load_settings()
|
self.load_settings()
|
||||||
self.setup_auto_save()
|
self.setup_auto_save()
|
||||||
self.clean_username = None
|
self.clean_username = None
|
||||||
@@ -342,7 +393,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.tab_widget.addTab(self.settings_tab, "Settings")
|
self.tab_widget.addTab(self.settings_tab, "Settings")
|
||||||
|
|
||||||
self.main_layout.addWidget(self.tab_widget)
|
self.main_layout.addWidget(self.tab_widget)
|
||||||
|
|
||||||
self.input_widget = QWidget()
|
self.input_widget = QWidget()
|
||||||
input_layout = QVBoxLayout(self.input_widget)
|
input_layout = QVBoxLayout(self.input_widget)
|
||||||
input_layout.setSpacing(10)
|
input_layout.setSpacing(10)
|
||||||
@@ -407,8 +457,8 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.batch_checkbox.stateChanged.connect(self.handle_batch_checkbox)
|
self.batch_checkbox.stateChanged.connect(self.handle_batch_checkbox)
|
||||||
first_row_layout.addWidget(self.batch_checkbox)
|
first_row_layout.addWidget(self.batch_checkbox)
|
||||||
|
|
||||||
size_label = QLabel("Size:")
|
self.size_label = QLabel("Size:")
|
||||||
first_row_layout.addWidget(size_label)
|
first_row_layout.addWidget(self.size_label)
|
||||||
|
|
||||||
self.batch_size_combo = QComboBox()
|
self.batch_size_combo = QComboBox()
|
||||||
self.batch_size_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
self.batch_size_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||||
@@ -418,6 +468,13 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.batch_size_combo.setCurrentIndex(1)
|
self.batch_size_combo.setCurrentIndex(1)
|
||||||
first_row_layout.addWidget(self.batch_size_combo)
|
first_row_layout.addWidget(self.batch_size_combo)
|
||||||
|
|
||||||
|
self.convert_gif_checkbox = QCheckBox("Convert GIF")
|
||||||
|
self.convert_gif_checkbox.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||||
|
first_row_layout.addWidget(self.convert_gif_checkbox)
|
||||||
|
|
||||||
|
self.size_label.hide()
|
||||||
|
self.batch_size_combo.hide()
|
||||||
|
|
||||||
first_row_layout.addSpacing(5)
|
first_row_layout.addSpacing(5)
|
||||||
|
|
||||||
timeline_label = QLabel("Timeline Type:")
|
timeline_label = QLabel("Timeline Type:")
|
||||||
@@ -459,24 +516,22 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.settings_tab_layout.addWidget(download_settings_label)
|
self.settings_tab_layout.addWidget(download_settings_label)
|
||||||
|
|
||||||
batch_download_item_layout = QHBoxLayout()
|
batch_download_item_layout = QHBoxLayout()
|
||||||
batch_download_label = QLabel("Batch Download Items:")
|
batch_download_label = QLabel("Batch Size:")
|
||||||
self.download_batch_combo = QComboBox()
|
self.download_batch_combo = QComboBox()
|
||||||
self.download_batch_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
self.download_batch_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||||
self.download_batch_combo.setFixedWidth(80)
|
self.download_batch_combo.setFixedWidth(80)
|
||||||
for size in range(5, 101, 5):
|
for size in range(5, 101, 5):
|
||||||
self.download_batch_combo.addItem(str(size))
|
self.download_batch_combo.addItem(str(size))
|
||||||
index = self.download_batch_combo.findText("25")
|
|
||||||
if index >= 0:
|
|
||||||
self.download_batch_combo.setCurrentIndex(index)
|
|
||||||
batch_download_item_layout.addWidget(batch_download_label)
|
batch_download_item_layout.addWidget(batch_download_label)
|
||||||
batch_download_item_layout.addWidget(self.download_batch_combo)
|
batch_download_item_layout.addWidget(self.download_batch_combo)
|
||||||
|
batch_download_item_layout.addWidget(self.convert_gif_checkbox)
|
||||||
batch_download_item_layout.addStretch()
|
batch_download_item_layout.addStretch()
|
||||||
self.settings_tab_layout.addLayout(batch_download_item_layout)
|
self.settings_tab_layout.addLayout(batch_download_item_layout)
|
||||||
|
|
||||||
filename_layout = QHBoxLayout()
|
filename_layout = QHBoxLayout()
|
||||||
filename_label = QLabel("Filename Format:")
|
filename_label = QLabel("Filename Format:")
|
||||||
self.format_username = QRadioButton("Username - Post Date")
|
self.format_username = QRadioButton("Username - Date")
|
||||||
self.format_date = QRadioButton("Post Date - Username")
|
self.format_date = QRadioButton("Date - Username")
|
||||||
self.format_username.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
self.format_username.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||||
self.format_date.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
self.format_date.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||||
filename_layout.addWidget(filename_label)
|
filename_layout.addWidget(filename_label)
|
||||||
@@ -596,7 +651,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
status_layout.setContentsMargins(0, 0, 0, 0)
|
status_layout.setContentsMargins(0, 0, 0, 0)
|
||||||
status_layout.setSpacing(5)
|
status_layout.setSpacing(5)
|
||||||
|
|
||||||
self.version_label = QLabel("v2.4.5 (gallery-dl v1.29.6)")
|
self.version_label = QLabel("v2.7 (gallery-dl v1.30.0)")
|
||||||
status_layout.addWidget(self.version_label)
|
status_layout.addWidget(self.version_label)
|
||||||
|
|
||||||
self.status_label = QLabel("")
|
self.status_label = QLabel("")
|
||||||
@@ -709,7 +764,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
return
|
return
|
||||||
|
|
||||||
QTimer.singleShot(500, self.fetch_next_batch_auto)
|
QTimer.singleShot(500, self.fetch_next_batch_auto)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.set_status_text(f"Error processing auto batch: {str(e)}")
|
self.set_status_text(f"Error processing auto batch: {str(e)}")
|
||||||
self.stop_auto_batch()
|
self.stop_auto_batch()
|
||||||
@@ -719,8 +773,15 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.stop_auto_batch()
|
self.stop_auto_batch()
|
||||||
|
|
||||||
def handle_batch_checkbox(self, state):
|
def handle_batch_checkbox(self, state):
|
||||||
|
if self.batch_checkbox.isChecked():
|
||||||
|
self.size_label.show()
|
||||||
|
self.batch_size_combo.show()
|
||||||
|
else:
|
||||||
|
self.size_label.hide()
|
||||||
|
self.batch_size_combo.hide()
|
||||||
|
|
||||||
if hasattr(self, 'media_info') and self.media_info:
|
if hasattr(self, 'media_info') and self.media_info:
|
||||||
if state == Qt.CheckState.Checked and self.media_info.get('metadata', {}).get('has_more', False):
|
if self.batch_checkbox.isChecked() and self.media_info.get('metadata', {}).get('has_more', False):
|
||||||
self.next_batch_button.show()
|
self.next_batch_button.show()
|
||||||
self.auto_batch_button.show()
|
self.auto_batch_button.show()
|
||||||
else:
|
else:
|
||||||
@@ -741,6 +802,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.batch_checkbox.stateChanged.connect(self.auto_save_settings)
|
self.batch_checkbox.stateChanged.connect(self.auto_save_settings)
|
||||||
self.download_batch_combo.currentTextChanged.connect(self.auto_save_settings)
|
self.download_batch_combo.currentTextChanged.connect(self.auto_save_settings)
|
||||||
self.batch_size_combo.currentTextChanged.connect(self.auto_save_settings)
|
self.batch_size_combo.currentTextChanged.connect(self.auto_save_settings)
|
||||||
|
self.convert_gif_checkbox.stateChanged.connect(self.auto_save_settings)
|
||||||
|
|
||||||
def auto_save_settings(self):
|
def auto_save_settings(self):
|
||||||
try:
|
try:
|
||||||
@@ -757,6 +819,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
|
|
||||||
self.settings.setValue('download_batch_size', self.download_batch_combo.currentText())
|
self.settings.setValue('download_batch_size', self.download_batch_combo.currentText())
|
||||||
self.settings.setValue('fetch_batch_size', self.batch_size_combo.currentText())
|
self.settings.setValue('fetch_batch_size', self.batch_size_combo.currentText())
|
||||||
|
self.settings.setValue('convert_gif', self.convert_gif_checkbox.isChecked())
|
||||||
self.settings.sync()
|
self.settings.sync()
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
@@ -789,6 +852,13 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.batch_checkbox.setChecked(batch_mode)
|
self.batch_checkbox.setChecked(batch_mode)
|
||||||
self.batch_checkbox.blockSignals(False)
|
self.batch_checkbox.blockSignals(False)
|
||||||
|
|
||||||
|
if batch_mode:
|
||||||
|
self.size_label.show()
|
||||||
|
self.batch_size_combo.show()
|
||||||
|
else:
|
||||||
|
self.size_label.hide()
|
||||||
|
self.batch_size_combo.hide()
|
||||||
|
|
||||||
fetch_batch_size = str(self.settings.value('fetch_batch_size', '100'))
|
fetch_batch_size = str(self.settings.value('fetch_batch_size', '100'))
|
||||||
index = self.batch_size_combo.findText(fetch_batch_size)
|
index = self.batch_size_combo.findText(fetch_batch_size)
|
||||||
if index >= 0:
|
if index >= 0:
|
||||||
@@ -799,11 +869,12 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
if index >= 0:
|
if index >= 0:
|
||||||
self.download_batch_combo.setCurrentIndex(index)
|
self.download_batch_combo.setCurrentIndex(index)
|
||||||
else:
|
else:
|
||||||
index = self.download_batch_combo.findText("25")
|
self.download_batch_combo.setCurrentIndex(0)
|
||||||
if index >= 0:
|
|
||||||
self.download_batch_combo.setCurrentIndex(index)
|
convert_gif = self.settings.value('convert_gif', False, type=bool)
|
||||||
else:
|
self.convert_gif_checkbox.blockSignals(True)
|
||||||
self.download_batch_combo.setCurrentIndex(0)
|
self.convert_gif_checkbox.setChecked(convert_gif)
|
||||||
|
self.convert_gif_checkbox.blockSignals(False)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@@ -824,7 +895,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
subprocess.run(['xdg-open', output_dir])
|
subprocess.run(['xdg-open', output_dir])
|
||||||
|
|
||||||
def set_status_text(self, text):
|
def set_status_text(self, text):
|
||||||
"""Set status text and hide/show version label accordingly"""
|
|
||||||
self.status_label.setText(text)
|
self.status_label.setText(text)
|
||||||
if text:
|
if text:
|
||||||
self.version_label.hide()
|
self.version_label.hide()
|
||||||
@@ -1116,6 +1186,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
filename_format = "username_date" if self.format_username.isChecked() else "date_username"
|
filename_format = "username_date" if self.format_username.isChecked() else "date_username"
|
||||||
batch_size = int(self.download_batch_combo.currentText())
|
batch_size = int(self.download_batch_combo.currentText())
|
||||||
media_type = self.media_type_combo.currentData()
|
media_type = self.media_type_combo.currentData()
|
||||||
|
convert_gif = self.convert_gif_checkbox.isChecked()
|
||||||
|
|
||||||
self.worker = MediaDownloader(
|
self.worker = MediaDownloader(
|
||||||
self.media_info['timeline'],
|
self.media_info['timeline'],
|
||||||
@@ -1123,7 +1194,8 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
filename_format,
|
filename_format,
|
||||||
self.clean_username,
|
self.clean_username,
|
||||||
media_type,
|
media_type,
|
||||||
batch_size
|
batch_size,
|
||||||
|
convert_gif
|
||||||
)
|
)
|
||||||
self.worker.progress.connect(self.update_progress)
|
self.worker.progress.connect(self.update_progress)
|
||||||
self.worker.finished.connect(self.download_finished)
|
self.worker.finished.connect(self.download_finished)
|
||||||
|
|||||||
+1
-1
@@ -1,3 +1,3 @@
|
|||||||
{
|
{
|
||||||
"version": "2.4.5"
|
"version": "2.6"
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user