mirror of
https://github.com/Alvin-Zilverstand/Twitter-X-Media-Batch-Downloader.git
synced 2026-12-04 12:01:25 +01:00
Update v2.0
This commit is contained in:
1 parent
967d91d370
commit
46e09532fc
2 files changed
+50
-7
No files matched your search
@@ -302,7 +302,7 @@ class UpdateDialog(QDialog):
|
||||
class TwitterMediaDownloaderGUI(QMainWindow):
|
||||
def __init__(self):
|
||||
super().__init__()
|
||||
self.current_version = "1.9"
|
||||
self.current_version = "2.0"
|
||||
self.setWindowTitle("Twitter/X Media Batch Downloader")
|
||||
|
||||
self.settings = QSettings('TwitterMediaDownloader', 'Settings')
|
||||
@@ -437,6 +437,7 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
||||
|
||||
self.batch_checkbox = QCheckBox("Batch")
|
||||
self.batch_checkbox.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||
self.batch_checkbox.setToolTip("Enable for accounts with thousands of media")
|
||||
self.batch_checkbox.stateChanged.connect(self.handle_batch_checkbox)
|
||||
first_row_layout.addWidget(self.batch_checkbox)
|
||||
|
||||
@@ -470,12 +471,12 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
||||
|
||||
first_row_layout.addSpacing(5)
|
||||
|
||||
media_type_label = QLabel("Item Type:")
|
||||
media_type_label = QLabel("Media Type:")
|
||||
self.media_type_combo = QComboBox()
|
||||
self.media_type_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
||||
self.media_type_combo.setFixedWidth(85)
|
||||
media_types = [
|
||||
('all', 'All Media'),
|
||||
('all', 'All'),
|
||||
('image', 'Image'),
|
||||
('video', 'Video'),
|
||||
('gif', 'GIF')
|
||||
@@ -960,6 +961,15 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
||||
if not info or not isinstance(info, dict):
|
||||
raise ValueError("Invalid info data received")
|
||||
|
||||
if 'error' in info:
|
||||
error_type = info['error']
|
||||
if error_type == "withheld":
|
||||
self.status_label.setText("Please enable the 'Use API' option.")
|
||||
else:
|
||||
self.status_label.setText("Please check the 'Auth Token' value. Your account may be suspended.")
|
||||
self.fetch_button.setEnabled(True)
|
||||
return
|
||||
|
||||
account_info = info.get('account_info', {})
|
||||
if not account_info:
|
||||
self.status_label.setText("Failed to fetch profile information")
|
||||
@@ -1106,10 +1116,11 @@ class TwitterMediaDownloaderGUI(QMainWindow):
|
||||
self.next_batch_button.setEnabled(True)
|
||||
|
||||
error_str = str(error)
|
||||
if "Local gallery-dl error: None" in error_str and not self.use_api_checkbox.isChecked():
|
||||
self.status_label.setText("Please check the 'Use API' option to fetch metadata using the API method.")
|
||||
|
||||
if '"error": "withheld"' in error_str or "withheld" in error_str:
|
||||
self.status_label.setText("Please enable the 'Use API' option.")
|
||||
else:
|
||||
self.status_label.setText(f"Error fetching profile info: {error}")
|
||||
self.status_label.setText("Please check the 'Auth Token'.")
|
||||
|
||||
def start_download(self):
|
||||
if not self.media_info:
|
||||
|
||||
+33
-1
@@ -32,8 +32,25 @@ def get_metadata(username, auth_token, timeline_type="timeline", batch_size=0, p
|
||||
|
||||
extractor.config = lambda key, default=None: config_dict.get(key, default)
|
||||
|
||||
try:
|
||||
extractor.initialize()
|
||||
|
||||
api = twitter.TwitterAPI(extractor)
|
||||
try:
|
||||
if username.startswith("id:"):
|
||||
user = api.user_by_rest_id(username[3:])
|
||||
else:
|
||||
user = api.user_by_screen_name(username)
|
||||
|
||||
if "legacy" in user and user["legacy"].get("withheld_scope"):
|
||||
raise ValueError("withheld")
|
||||
|
||||
except Exception as e:
|
||||
error_msg = str(e).lower()
|
||||
if "withheld" in error_msg or (hasattr(e, "response") and "withheld" in str(e.response.text).lower()):
|
||||
raise ValueError("withheld")
|
||||
raise
|
||||
|
||||
structured_output = {
|
||||
'account_info': {},
|
||||
'total_urls': 0,
|
||||
@@ -129,6 +146,17 @@ def get_metadata(username, auth_token, timeline_type="timeline", batch_size=0, p
|
||||
|
||||
return structured_output
|
||||
|
||||
except Exception as e:
|
||||
error_msg = str(e).lower()
|
||||
if "withheld" in error_msg or e.__class__.__name__ == "ValueError" and str(e) == "withheld":
|
||||
return {"error": "withheld"}
|
||||
else:
|
||||
error_str = str(e)
|
||||
if error_str == "None":
|
||||
return {"error": "null"}
|
||||
else:
|
||||
return {"error": error_str}
|
||||
|
||||
def main():
|
||||
username = ""
|
||||
auth_token = ""
|
||||
@@ -148,7 +176,11 @@ def main():
|
||||
)
|
||||
print(json.dumps(data, ensure_ascii=False, indent=2))
|
||||
except Exception as e:
|
||||
print(json.dumps({"error": str(e)}, ensure_ascii=False))
|
||||
error_str = str(e)
|
||||
if error_str == "None":
|
||||
print(json.dumps({"error": "null"}, ensure_ascii=False))
|
||||
else:
|
||||
print(json.dumps({"error": error_str}, ensure_ascii=False))
|
||||
|
||||
if __name__ == '__main__':
|
||||
main()
|
||||
Reference in new issue
Block a user