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 | |
|---|---|---|---|
|
|
91210f1c82 | ||
|
|
cb2a244e37 | ||
|
|
096425a0e1 | ||
|
|
c01a995b3d | ||
|
|
b28b4ef14c | ||
|
|
1e14fa6934 | ||
|
|
eac8a0f168 | ||
|
|
f3904c276c | ||
|
|
fe9724fa2f | ||
|
|
85e8f3135a | ||
|
|
1e2725f900 | ||
|
|
8e114a45e0 | ||
|
|
92267dbf5e | ||
|
|
37da356f4c | ||
|
|
eb268f5f9f |
No files matched your search
@@ -4,7 +4,7 @@ import os
|
|||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from gallery_dl.extractor import twitter
|
from gallery_dl.extractor import twitter
|
||||||
|
|
||||||
def get_metadata(username):
|
def get_metadata(username, auth_token):
|
||||||
url = f"https://x.com/{username}/timeline"
|
url = f"https://x.com/{username}/timeline"
|
||||||
|
|
||||||
match = re.match(twitter.TwitterTimelineExtractor.pattern, url)
|
match = re.match(twitter.TwitterTimelineExtractor.pattern, url)
|
||||||
@@ -15,7 +15,7 @@ def get_metadata(username):
|
|||||||
|
|
||||||
extractor.config = lambda key, default=None: {
|
extractor.config = lambda key, default=None: {
|
||||||
"cookies": {
|
"cookies": {
|
||||||
"auth_token": ""
|
"auth_token": auth_token
|
||||||
}
|
}
|
||||||
}.get(key, default)
|
}.get(key, default)
|
||||||
|
|
||||||
@@ -75,4 +75,5 @@ def get_metadata(username):
|
|||||||
return output
|
return output
|
||||||
|
|
||||||
username = ""
|
username = ""
|
||||||
get_metadata(username)
|
auth_token = ""
|
||||||
|
get_metadata(username, auth_token)
|
||||||
+4
-3
@@ -3,7 +3,7 @@ import re
|
|||||||
import os
|
import os
|
||||||
from gallery_dl.extractor import twitter
|
from gallery_dl.extractor import twitter
|
||||||
|
|
||||||
def get_metadata(username):
|
def get_metadata(username, auth_token):
|
||||||
url = f"https://x.com/{username}/timeline"
|
url = f"https://x.com/{username}/timeline"
|
||||||
|
|
||||||
match = re.match(twitter.TwitterTimelineExtractor.pattern, url)
|
match = re.match(twitter.TwitterTimelineExtractor.pattern, url)
|
||||||
@@ -14,7 +14,7 @@ def get_metadata(username):
|
|||||||
|
|
||||||
extractor.config = lambda key, default=None: {
|
extractor.config = lambda key, default=None: {
|
||||||
"cookies": {
|
"cookies": {
|
||||||
"auth_token": ""
|
"auth_token": auth_token
|
||||||
}
|
}
|
||||||
}.get(key, default)
|
}.get(key, default)
|
||||||
|
|
||||||
@@ -31,4 +31,5 @@ def get_metadata(username):
|
|||||||
json.dump(all_items, f, indent=2, default=str)
|
json.dump(all_items, f, indent=2, default=str)
|
||||||
|
|
||||||
username = ""
|
username = ""
|
||||||
get_metadata(username)
|
auth_token = ""
|
||||||
|
get_metadata(username, auth_token)
|
||||||
@@ -8,34 +8,31 @@
|
|||||||
|
|
||||||
## Download
|
## 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.7/TwitterXMediaBatchDownloader.exe)
|
||||||
- If you're familiar with **userscripts**, please install it [here](https://greasyfork.org/en/scripts/523157-twitter-x-media-batch-downloader)
|
- If you're familiar with **userscripts**, please install it [here](https://greasyfork.org/en/scripts/523157-twitter-x-media-batch-downloader)
|
||||||
|
|
||||||
## Features
|
## Features
|
||||||
|
|
||||||
- Uses the powerful `gallery-dl` library, similar to `yt-dlp`
|
- 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** _(maybe requires checking the **Use gallery-dl API** option)_
|
||||||
- Simple and compact GUI
|
- Option to choose the media type to download: **All Media** (Image + GIF + Video) or just **Image/GIF/Video**
|
||||||
- Download images and videos in original quality
|
- Download images and videos in original quality
|
||||||
- Option to choose the media type to download: **media** (image + GIF + video) or just **image/GIF/video**
|
|
||||||
- **Batch** download settings, ranging from 10 to 100 files per download
|
|
||||||
- Filename format customization
|
|
||||||
|
|
||||||
## Screenshots
|
## Screenshots
|
||||||
|
|
||||||

|

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

|

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

|

|
||||||
|
|
||||||
> Downloading from **Withheld Accounts**
|
> Downloading from **Withheld Accounts**
|
||||||
|
|
||||||

|

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

|

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

|

|
||||||
|
|
||||||
## How to Obtain Auth Token
|
## How to Obtain Auth Token
|
||||||
|
|
||||||
@@ -43,12 +40,19 @@
|
|||||||
> - I suggest not using the **main account** to obtain the token.
|
> - I suggest not using the **main account** to obtain the token.
|
||||||
> - You can use https://temp-mail.io to register a Twitter account.
|
> - You can use https://temp-mail.io to register a Twitter account.
|
||||||
> - Using an auth token or cookies has the potential to get the **account suspended.**
|
> - Using an auth token or cookies has the potential to get the **account suspended.**
|
||||||
|
> - If too many media files are fetched, it will trigger a **rate limit**, and the media retrieval will fail.
|
||||||
|
|
||||||
1. Go to [Twitter's website](https://www.x.com/)
|
1. Go to [Twitter's website](https://www.x.com/)
|
||||||
2. Log into your account
|
2. Log into your account
|
||||||
3. Open the Developer Tools by pressing `F12`
|
3. Open the Developer Tools by pressing `F12`
|
||||||
4. Navigate to the **Application** tab, then select **Storage** > **Cookies**
|
4. Navigate to the **Application** tab, then select **Storage** > **Cookies**
|
||||||
5. Find and copy the `auth_token` value or use the browser extension [Cookie-Editor](https://cookie-editor.com/)
|
5. Find and copy the `auth_token` value or use the browser extension [X.com Auth Token Grabber](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v1.0/X.com.Auth.Token.Grabber.zip)
|
||||||
6. Do not log out of your account, as a new `auth_token` will be generated by Twitter
|
6. Do not log out of your account, as a new `auth_token` will be generated by Twitter
|
||||||
|
|
||||||
|
> X.com Auth Token Grabber
|
||||||
|
|
||||||
|

|
||||||
|
|
||||||
|
> Developer Tools
|
||||||
|
|
||||||

|

|
||||||
+191
-110
@@ -2,16 +2,18 @@ import sys
|
|||||||
import os
|
import os
|
||||||
import asyncio
|
import asyncio
|
||||||
import aiohttp
|
import aiohttp
|
||||||
|
import requests
|
||||||
import re
|
import re
|
||||||
import subprocess
|
import subprocess
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
from packaging import version
|
||||||
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
|
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
|
||||||
QHBoxLayout, QLabel, QLineEdit, QPushButton,
|
QHBoxLayout, QLabel, QLineEdit, QPushButton,
|
||||||
QProgressBar, QFileDialog, QRadioButton, QComboBox,
|
QProgressBar, QFileDialog, QRadioButton, QComboBox,
|
||||||
QGroupBox, QCheckBox)
|
QGroupBox, QCheckBox, QDialog, QDialogButtonBox)
|
||||||
from PyQt6.QtCore import QThread, pyqtSignal, Qt, QSettings
|
from PyQt6.QtCore import QThread, pyqtSignal, Qt, QSettings, QTimer, QUrl
|
||||||
from PyQt6.QtGui import QIcon, QPixmap, QCursor, QPainter, QPainterPath
|
from PyQt6.QtGui import QIcon, QPixmap, QCursor, QPainter, QPainterPath, QDesktopServices
|
||||||
from gallery_dl.extractor import twitter
|
from gallery_dl.extractor import twitter
|
||||||
|
|
||||||
class ImageDownloader(QThread):
|
class ImageDownloader(QThread):
|
||||||
@@ -37,12 +39,12 @@ class MetadataFetcher(QThread):
|
|||||||
finished = pyqtSignal(dict)
|
finished = pyqtSignal(dict)
|
||||||
error = pyqtSignal(str)
|
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__()
|
super().__init__()
|
||||||
self.username = username
|
self.username = username
|
||||||
self.auth_token = None
|
self.auth_token = None
|
||||||
self.media_type = media_type
|
self.media_type = media_type
|
||||||
self.use_api = use_api
|
self.use_local = use_local
|
||||||
|
|
||||||
def normalize_url(self, url_or_username):
|
def normalize_url(self, url_or_username):
|
||||||
url_or_username = url_or_username.strip()
|
url_or_username = url_or_username.strip()
|
||||||
@@ -82,101 +84,115 @@ class MetadataFetcher(QThread):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
raise ValueError(f"API request failed: {str(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):
|
def run(self):
|
||||||
try:
|
try:
|
||||||
normalized = self.normalize_url(self.username)
|
normalized = self.normalize_url(self.username)
|
||||||
|
|
||||||
try:
|
if not self.use_local:
|
||||||
data = asyncio.run(self.fetch_from_api(normalized, self.auth_token))
|
|
||||||
self.finished.emit(data)
|
|
||||||
return
|
|
||||||
except Exception as api_error:
|
|
||||||
try:
|
try:
|
||||||
match = re.match(twitter.TwitterTimelineExtractor.pattern, f"https://x.com/{normalized}/timeline")
|
data = asyncio.run(self.fetch_from_api(normalized, self.auth_token))
|
||||||
if not match:
|
self.finished.emit(data)
|
||||||
raise ValueError(f"Invalid username: {normalized}")
|
return
|
||||||
|
except Exception as api_error:
|
||||||
extractor = twitter.TwitterTimelineExtractor(match)
|
print(f"API fetch failed, falling back to local: {str(api_error)}")
|
||||||
extractor.config = lambda key, default=None: {
|
pass
|
||||||
"cookies": {
|
|
||||||
"auth_token": self.auth_token
|
try:
|
||||||
}
|
data = asyncio.run(self.fetch_local(normalized))
|
||||||
}.get(key, default)
|
self.finished.emit(data)
|
||||||
|
except Exception as local_error:
|
||||||
extractor.initialize()
|
if not self.use_local:
|
||||||
|
|
||||||
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:
|
|
||||||
raise ValueError(f"Both API and local methods failed.\nAPI error: {str(api_error)}\nLocal error: {str(local_error)}")
|
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:
|
except Exception as e:
|
||||||
self.error.emit(str(e))
|
self.error.emit(str(e))
|
||||||
@@ -327,11 +343,50 @@ class MediaDownloader(QThread):
|
|||||||
except Exception as e:
|
except Exception as e:
|
||||||
self.error.emit(str(e))
|
self.error.emit(str(e))
|
||||||
|
|
||||||
|
class UpdateDialog(QDialog):
|
||||||
|
def __init__(self, current_version, new_version, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.setWindowTitle("Update Available")
|
||||||
|
self.setFixedWidth(400)
|
||||||
|
self.setModal(True)
|
||||||
|
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
|
||||||
|
message = QLabel(f"A new version of Twitter/X Media Batch Downloader is available!\n\n"
|
||||||
|
f"Current version: v{current_version}\n"
|
||||||
|
f"New version: v{new_version}")
|
||||||
|
message.setWordWrap(True)
|
||||||
|
layout.addWidget(message)
|
||||||
|
|
||||||
|
self.disable_check = QCheckBox("Turn off update checking")
|
||||||
|
self.disable_check.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||||
|
layout.addWidget(self.disable_check)
|
||||||
|
|
||||||
|
button_box = QDialogButtonBox()
|
||||||
|
self.update_button = QPushButton("Update")
|
||||||
|
self.update_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||||
|
self.cancel_button = QPushButton("Cancel")
|
||||||
|
self.cancel_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||||
|
|
||||||
|
button_box.addButton(self.update_button, QDialogButtonBox.ButtonRole.AcceptRole)
|
||||||
|
button_box.addButton(self.cancel_button, QDialogButtonBox.ButtonRole.RejectRole)
|
||||||
|
|
||||||
|
layout.addWidget(button_box)
|
||||||
|
|
||||||
|
self.setLayout(layout)
|
||||||
|
|
||||||
|
self.update_button.clicked.connect(self.accept)
|
||||||
|
self.cancel_button.clicked.connect(self.reject)
|
||||||
|
|
||||||
class TwitterMediaDownloaderGUI(QMainWindow):
|
class TwitterMediaDownloaderGUI(QMainWindow):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
super().__init__()
|
super().__init__()
|
||||||
|
self.current_version = "1.6"
|
||||||
self.setWindowTitle("Twitter/X Media Batch Downloader")
|
self.setWindowTitle("Twitter/X Media Batch Downloader")
|
||||||
|
|
||||||
|
self.settings = QSettings('TwitterMediaDownloader', 'Settings')
|
||||||
|
self.check_for_updates = self.settings.value('check_for_updates', True, type=bool)
|
||||||
|
|
||||||
icon_path = os.path.join(os.path.dirname(__file__), "icon.svg")
|
icon_path = os.path.join(os.path.dirname(__file__), "icon.svg")
|
||||||
if os.path.exists(icon_path):
|
if os.path.exists(icon_path):
|
||||||
self.setWindowIcon(QIcon(icon_path))
|
self.setWindowIcon(QIcon(icon_path))
|
||||||
@@ -343,12 +398,34 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
os.makedirs(self.default_pictures_dir, exist_ok=True)
|
os.makedirs(self.default_pictures_dir, exist_ok=True)
|
||||||
|
|
||||||
self.media_info = None
|
self.media_info = None
|
||||||
self.settings = QSettings('TwitterMediaDownloader', 'Settings')
|
|
||||||
|
|
||||||
self.init_ui()
|
self.init_ui()
|
||||||
self.load_settings()
|
self.load_settings()
|
||||||
self.setup_auto_save()
|
self.setup_auto_save()
|
||||||
self.clean_username = None
|
self.clean_username = None
|
||||||
|
|
||||||
|
if self.check_for_updates:
|
||||||
|
QTimer.singleShot(0, self.check_updates)
|
||||||
|
|
||||||
|
def check_updates(self):
|
||||||
|
try:
|
||||||
|
response = requests.get("https://raw.githubusercontent.com/afkarxyz/Twitter-X-Media-Batch-Downloader/refs/heads/main/version.json")
|
||||||
|
if response.status_code == 200:
|
||||||
|
data = response.json()
|
||||||
|
new_version = data.get("version")
|
||||||
|
|
||||||
|
if new_version and version.parse(new_version) > version.parse(self.current_version):
|
||||||
|
dialog = UpdateDialog(self.current_version, new_version, self)
|
||||||
|
result = dialog.exec()
|
||||||
|
|
||||||
|
if dialog.disable_check.isChecked():
|
||||||
|
self.settings.setValue('check_for_updates', False)
|
||||||
|
self.check_for_updates = False
|
||||||
|
|
||||||
|
if result == QDialog.DialogCode.Accepted:
|
||||||
|
QDesktopServices.openUrl(QUrl("https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases"))
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error checking for updates: {e}")
|
||||||
|
|
||||||
def init_ui(self):
|
def init_ui(self):
|
||||||
central_widget = QWidget()
|
central_widget = QWidget()
|
||||||
@@ -431,9 +508,9 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
media_layout.addWidget(self.media_type_combo)
|
media_layout.addWidget(self.media_type_combo)
|
||||||
media_layout.addSpacing(10)
|
media_layout.addSpacing(10)
|
||||||
|
|
||||||
self.use_api_checkbox = QCheckBox("Use API")
|
self.use_api_checkbox = QCheckBox("Local")
|
||||||
self.use_api_checkbox.setToolTip("Use external API instead of gallery-dl")
|
self.use_api_checkbox.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||||
self.use_api_checkbox.setChecked(True)
|
self.use_api_checkbox.setToolTip("Use local gallery-dl instead of API")
|
||||||
self.use_api_checkbox.stateChanged.connect(self.auto_save_settings)
|
self.use_api_checkbox.stateChanged.connect(self.auto_save_settings)
|
||||||
|
|
||||||
media_layout.addWidget(self.use_api_checkbox)
|
media_layout.addWidget(self.use_api_checkbox)
|
||||||
@@ -450,7 +527,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.batch_size_combo.setFixedWidth(60)
|
self.batch_size_combo.setFixedWidth(60)
|
||||||
for size in range(10, 101, 10):
|
for size in range(10, 101, 10):
|
||||||
self.batch_size_combo.addItem(str(size))
|
self.batch_size_combo.addItem(str(size))
|
||||||
self.batch_size_combo.setCurrentText("20")
|
|
||||||
|
|
||||||
batch_layout.addWidget(batch_label)
|
batch_layout.addWidget(batch_label)
|
||||||
batch_layout.addWidget(self.batch_size_combo)
|
batch_layout.addWidget(self.batch_size_combo)
|
||||||
@@ -575,8 +651,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.main_layout.addWidget(self.progress_bar)
|
self.main_layout.addWidget(self.progress_bar)
|
||||||
|
|
||||||
bottom_layout = QHBoxLayout()
|
bottom_layout = QHBoxLayout()
|
||||||
bottom_layout.setContentsMargins(0, 0, 0, 0)
|
|
||||||
bottom_layout.setSpacing(5)
|
|
||||||
|
|
||||||
self.status_label = QLabel("")
|
self.status_label = QLabel("")
|
||||||
bottom_layout.addWidget(self.status_label, stretch=1)
|
bottom_layout.addWidget(self.status_label, stretch=1)
|
||||||
@@ -602,7 +676,6 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
bottom_layout.addWidget(self.update_button)
|
bottom_layout.addWidget(self.update_button)
|
||||||
|
|
||||||
self.main_layout.addLayout(bottom_layout)
|
self.main_layout.addLayout(bottom_layout)
|
||||||
self.main_layout.setAlignment(bottom_layout, Qt.AlignmentFlag.AlignBottom)
|
|
||||||
|
|
||||||
def open_update_page(self):
|
def open_update_page(self):
|
||||||
import webbrowser
|
import webbrowser
|
||||||
@@ -624,7 +697,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.settings.setValue('filename_format',
|
self.settings.setValue('filename_format',
|
||||||
'username_date' if self.format_username.isChecked() else 'date_username')
|
'username_date' if self.format_username.isChecked() else 'date_username')
|
||||||
self.settings.setValue('media_type', self.media_type_combo.currentData())
|
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.setValue('batch_size', self.batch_size_combo.currentText())
|
||||||
self.settings.sync()
|
self.settings.sync()
|
||||||
|
|
||||||
@@ -643,8 +716,8 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.media_type_combo.setCurrentIndex(i)
|
self.media_type_combo.setCurrentIndex(i)
|
||||||
break
|
break
|
||||||
|
|
||||||
use_api = self.settings.value('use_api', True, type=bool)
|
use_local = self.settings.value('use_local', False, type=bool)
|
||||||
self.use_api_checkbox.setChecked(use_api)
|
self.use_api_checkbox.setChecked(use_local)
|
||||||
|
|
||||||
batch_size = self.settings.value('batch_size', '20')
|
batch_size = self.settings.value('batch_size', '20')
|
||||||
index = self.batch_size_combo.findText(batch_size)
|
index = self.batch_size_combo.findText(batch_size)
|
||||||
@@ -682,8 +755,8 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.status_label.setText("Fetching profile information...")
|
self.status_label.setText("Fetching profile information...")
|
||||||
|
|
||||||
media_type = self.media_type_combo.currentData()
|
media_type = self.media_type_combo.currentData()
|
||||||
use_api = self.use_api_checkbox.isChecked()
|
use_local = self.use_api_checkbox.isChecked()
|
||||||
self.fetcher = MetadataFetcher(username, media_type, use_api)
|
self.fetcher = MetadataFetcher(username, media_type, use_local)
|
||||||
self.fetcher.auth_token = auth_token
|
self.fetcher.auth_token = auth_token
|
||||||
self.fetcher.finished.connect(self.handle_profile_info)
|
self.fetcher.finished.connect(self.handle_profile_info)
|
||||||
self.fetcher.error.connect(self.handle_fetch_error)
|
self.fetcher.error.connect(self.handle_fetch_error)
|
||||||
@@ -706,7 +779,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
is_withheld = not account_info.get('nick') and not account_info.get('profile_image')
|
is_withheld = not account_info.get('nick') and not account_info.get('profile_image')
|
||||||
|
|
||||||
name = account_info.get('name', 'Unknown')
|
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', '')
|
date_str = account_info.get('date', '')
|
||||||
followers = account_info.get('followers_count', 0)
|
followers = account_info.get('followers_count', 0)
|
||||||
following = account_info.get('friends_count', 0)
|
following = account_info.get('friends_count', 0)
|
||||||
@@ -783,6 +856,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.download_button.show()
|
self.download_button.show()
|
||||||
self.cancel_button.show()
|
self.cancel_button.show()
|
||||||
self.update_button.hide()
|
self.update_button.hide()
|
||||||
|
self.setFixedHeight(180)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
output_base = self.dir_input.text().strip() or self.default_pictures_dir
|
output_base = self.dir_input.text().strip() or self.default_pictures_dir
|
||||||
@@ -822,7 +896,12 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
|
|
||||||
def handle_fetch_error(self, error):
|
def handle_fetch_error(self, error):
|
||||||
self.fetch_button.setEnabled(True)
|
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):
|
def start_download(self):
|
||||||
if not self.media_info:
|
if not self.media_info:
|
||||||
@@ -887,6 +966,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.download_button.setText("Download")
|
self.download_button.setText("Download")
|
||||||
self.download_button.clicked.disconnect()
|
self.download_button.clicked.disconnect()
|
||||||
self.download_button.clicked.connect(self.start_download)
|
self.download_button.clicked.connect(self.start_download)
|
||||||
|
self.setFixedHeight(210)
|
||||||
|
|
||||||
def download_error(self, error_message):
|
def download_error(self, error_message):
|
||||||
self.progress_bar.hide()
|
self.progress_bar.hide()
|
||||||
@@ -907,6 +987,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
|||||||
self.media_info = None
|
self.media_info = None
|
||||||
self.update_button.show()
|
self.update_button.show()
|
||||||
self.fetch_button.setEnabled(True)
|
self.fetch_button.setEnabled(True)
|
||||||
|
self.setFixedHeight(210)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
if getattr(sys, 'frozen', False):
|
if getattr(sys, 'frozen', False):
|
||||||
|
|||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "1.7"
|
||||||
|
}
|
||||||
Reference in new issue
Block a user