Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1ace435160 | ||
|
|
df0de054c8 | ||
|
|
f2a3810c8c | ||
|
|
549d8fde60 | ||
|
|
64bd8b4b2d | ||
|
|
0f2427ad2b | ||
|
|
05e8230063 | ||
|
|
83672f42b6 | ||
|
|
affd36c968 | ||
|
|
281ea82656 | ||
|
|
aa003fab4c | ||
|
|
805fade0fb | ||
|
|
dacf6f5a01 | ||
|
|
fe095afb38 | ||
|
|
e769ea8d20 | ||
|
|
befe838e79 | ||
|
|
b534bc278e | ||
|
|
2e882635eb | ||
|
|
5d5b778c8e | ||
|
|
7cf134f681 | ||
|
|
7d90eb7cb2 | ||
|
|
3d1fd7d1fb | ||
|
|
c0885b1812 | ||
|
|
1ca5c613ae | ||
|
|
596ba9bb3c | ||
|
|
a1cbb04402 | ||
|
|
ddf6439893 | ||
|
|
fed2bf7b0c | ||
|
|
241884de89 | ||
|
|
77b443ace0 | ||
|
|
cd48b6f9bc | ||
|
|
6f45b48047 | ||
|
|
7083c56c8b | ||
|
|
60cb3cbabd | ||
|
|
b38bff238a | ||
|
|
d4d216ed6b | ||
|
|
129c007f6f | ||
|
|
d78ad32c09 | ||
|
|
3975e5dd0e | ||
|
|
37f1d910cb | ||
|
|
74ed38cc31 | ||
|
|
2e326c39a0 | ||
|
|
39c37d4776 | ||
|
|
5709d76ceb | ||
|
|
75b3549653 | ||
|
|
ebe739e612 | ||
|
|
d423f20bad | ||
|
|
fba8a8ac45 | ||
|
|
a36c7613d2 | ||
|
|
c7615ed2f6 | ||
|
|
0c17f1b419 | ||
|
|
dd38880366 | ||
|
|
306d2c3c95 | ||
|
|
1caa59bbcf | ||
|
|
4d0021092c | ||
|
|
981bc8d9ec | ||
|
|
c894bfd4d2 | ||
|
|
61e50b8121 | ||
|
|
ba69dd7cf4 | ||
|
|
bcc332d0d7 | ||
|
|
82184aef33 | ||
|
|
357ad0f020 | ||
|
|
43f4d84593 | ||
|
|
4cecb6b14e | ||
|
|
eb712d5d8d | ||
|
|
46c178fec0 | ||
|
|
8ce5f1f833 | ||
|
|
0a80a3d331 | ||
|
|
f8b27ecb5a | ||
|
|
70e79af700 | ||
|
|
4fb60840a0 | ||
|
|
5613c152f8 | ||
|
|
ad5d7727eb | ||
|
|
ed1f0fce06 | ||
|
|
ee92174773 | ||
|
|
f08ce57feb | ||
|
|
4f21321e42 | ||
|
|
c8b7a5365a | ||
|
|
1049b544c5 | ||
|
|
e7db97a936 | ||
|
|
af1280b798 | ||
|
|
4f6004a501 | ||
|
|
e7141cd8d1 | ||
|
|
4d6f4d904a | ||
|
|
4081e6aacf | ||
|
|
2b405a16a7 | ||
|
|
5e658c05d4 | ||
|
|
b26dd0b2af | ||
|
|
28422dcf1d | ||
|
|
46e09532fc | ||
|
|
967d91d370 | ||
|
|
2ff0242e32 | ||
|
|
1e1d612807 | ||
|
|
9821dd8c65 | ||
|
|
46bb7d38f7 | ||
|
|
112f5992c4 | ||
|
|
178b3c490f | ||
|
|
bb1c0dccae | ||
|
|
0cf5316745 | ||
|
|
c3493944e8 | ||
|
|
c656459171 | ||
|
|
0e14f92244 | ||
|
|
fad4434753 | ||
|
|
77a9c83f4d | ||
|
|
7fa277931c | ||
|
|
be080481bf | ||
|
|
8a720e3e2b | ||
|
|
48a672e0bd | ||
|
|
91210f1c82 | ||
|
|
cb2a244e37 | ||
|
|
096425a0e1 | ||
|
|
c01a995b3d | ||
|
|
b28b4ef14c | ||
|
|
1e14fa6934 | ||
|
|
eac8a0f168 | ||
|
|
f3904c276c | ||
|
|
fe9724fa2f | ||
|
|
85e8f3135a | ||
|
|
1e2725f900 | ||
|
|
8e114a45e0 | ||
|
|
92267dbf5e | ||
|
|
37da356f4c | ||
|
|
eb268f5f9f | ||
|
|
e8ac4b8734 | ||
|
|
99afe59a11 | ||
|
|
8e8c0667df | ||
|
|
03479326b3 | ||
|
|
b39f40e9f9 | ||
|
|
5ed127f226 | ||
|
|
3487edf691 | ||
|
|
5b336df1d4 |
No files matched your search
@@ -1,78 +0,0 @@
|
|||||||
import json
|
|
||||||
import re
|
|
||||||
import os
|
|
||||||
from datetime import datetime
|
|
||||||
from gallery_dl.extractor import twitter
|
|
||||||
|
|
||||||
def get_metadata(username):
|
|
||||||
url = f"https://x.com/{username}/timeline"
|
|
||||||
|
|
||||||
match = re.match(twitter.TwitterTimelineExtractor.pattern, url)
|
|
||||||
if not match:
|
|
||||||
raise ValueError(f"Invalid URL: {url}")
|
|
||||||
|
|
||||||
extractor = twitter.TwitterTimelineExtractor(match)
|
|
||||||
|
|
||||||
extractor.config = lambda key, default=None: {
|
|
||||||
"cookies": {
|
|
||||||
"auth_token": ""
|
|
||||||
}
|
|
||||||
}.get(key, default)
|
|
||||||
|
|
||||||
extractor.initialize()
|
|
||||||
|
|
||||||
output = {
|
|
||||||
'account_info': {},
|
|
||||||
'total_urls': 0,
|
|
||||||
'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)
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'pbs.twimg.com' in media_url or 'video.twimg.com' in media_url:
|
|
||||||
tweet_date = tweet_data.get('date', datetime.now())
|
|
||||||
if isinstance(tweet_date, datetime):
|
|
||||||
tweet_date = tweet_date.strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
timeline_entry = {
|
|
||||||
'url': media_url,
|
|
||||||
'date': tweet_date,
|
|
||||||
'tweet_id': tweet_data.get('tweet_id', 0),
|
|
||||||
}
|
|
||||||
|
|
||||||
if 'type' in tweet_data:
|
|
||||||
timeline_entry['type'] = tweet_data['type']
|
|
||||||
|
|
||||||
output['timeline'].append(timeline_entry)
|
|
||||||
output['total_urls'] += 1
|
|
||||||
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
output_file = os.path.join(current_dir, f"{username}.json")
|
|
||||||
|
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
|
||||||
json.dump(output, f, ensure_ascii=False, indent=2)
|
|
||||||
|
|
||||||
return output
|
|
||||||
|
|
||||||
username = ""
|
|
||||||
get_metadata(username)
|
|
||||||
@@ -1,34 +0,0 @@
|
|||||||
import json
|
|
||||||
import re
|
|
||||||
import os
|
|
||||||
from gallery_dl.extractor import twitter
|
|
||||||
|
|
||||||
def get_metadata(username):
|
|
||||||
url = f"https://x.com/{username}/timeline"
|
|
||||||
|
|
||||||
match = re.match(twitter.TwitterTimelineExtractor.pattern, url)
|
|
||||||
if not match:
|
|
||||||
raise ValueError(f"Invalid URL: {url}")
|
|
||||||
|
|
||||||
extractor = twitter.TwitterTimelineExtractor(match)
|
|
||||||
|
|
||||||
extractor.config = lambda key, default=None: {
|
|
||||||
"cookies": {
|
|
||||||
"auth_token": ""
|
|
||||||
}
|
|
||||||
}.get(key, default)
|
|
||||||
|
|
||||||
extractor.initialize()
|
|
||||||
|
|
||||||
all_items = []
|
|
||||||
for item in extractor:
|
|
||||||
all_items.append(item)
|
|
||||||
|
|
||||||
current_dir = os.path.dirname(os.path.abspath(__file__))
|
|
||||||
output_file = os.path.join(current_dir, f"{username}.json")
|
|
||||||
|
|
||||||
with open(output_file, 'w', encoding='utf-8') as f:
|
|
||||||
json.dump(all_items, f, indent=2, default=str)
|
|
||||||
|
|
||||||
username = ""
|
|
||||||
get_metadata(username)
|
|
||||||
@@ -6,35 +6,66 @@
|
|||||||
<b>Twitter/X Media Batch Downloader</b> is a GUI tool that allows users to download all media, including images and videos, in their original quality from Twitter/X accounts using <code>gallery-dl</code>
|
<b>Twitter/X Media Batch Downloader</b> is a GUI tool that allows users to download all media, including images and videos, in their original quality from Twitter/X accounts using <code>gallery-dl</code>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
## Download
|
## 📥 Download
|
||||||
|
|
||||||
- Download the latest version of [TwitterXMediaBatchDownloader](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v1.2/TwitterXMediaBatchDownloader.exe)
|
- [**Windows**](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest/download/TwitterXMediaBatchDownloader_Windows.exe)
|
||||||
- If you're familiar with **userscripts**, please install it [here](https://greasyfork.org/en/scripts/523157-twitter-x-media-batch-downloader)
|
- [**Linux**](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest/download/TwitterXMediaBatchDownloader_Linux)
|
||||||
|
- [**Mac**](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest/download/TwitterXMediaBatchDownloader_Mac.zip)
|
||||||
|
- If you're familiar with **userscripts**, please install it [**here**](https://greasyfork.org/en/scripts/523157)
|
||||||
|
- The **Chrome extension** version is now available, please install it [**here**](https://www.patreon.com/posts/chrome-extension-139296789)
|
||||||
|
|
||||||
## Features
|
## ✨ Features
|
||||||
|
|
||||||
- Uses the powerful `gallery-dl` library, similar to `yt-dlp`
|
- Powered by `gallery-dl`, similar to `yt-dlp`
|
||||||
- Simple and compact GUI
|
- **Bulk fetch**: Fetch multiple accounts at once
|
||||||
- Download images and videos in original quality
|
- **Bulk download**: Download multiple accounts at once
|
||||||
- Option to choose the media type to download: **media** (image + video) or just **image/video**
|
- Media-type selection: All (Images + GIFs + Videos) or specific (Images / GIFs / Videos)
|
||||||
- **Batch** download settings, ranging from 10 to 100 files per download
|
- **MP4 → GIF conversion:** Convert downloaded MP4 videos into GIF format
|
||||||
- Filename format customization
|
- Downloads at original quality
|
||||||
|
|
||||||
## Screenshots
|
## 🖼️ Screenshots
|
||||||
|
|
||||||

|

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

|

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

|
### The downloaded application won't run❓
|
||||||
|
|
||||||
## How to Obtain Auth Token
|
🐧 **Solution (Ubuntu/Linux)**: Open your terminal and run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
chmod +x TwitterXMediaBatchDownloader_Linux
|
||||||
|
```
|
||||||
|

|
||||||
|
|
||||||
|
🍎 **Solution (macOS)**: Open your terminal and run:
|
||||||
|
|
||||||
|
```bash
|
||||||
|
xattr -rd com.apple.quarantine ~/Downloads/TwitterXMediaBatchDownloader_Mac.app
|
||||||
|
```
|
||||||
|

|
||||||
|
|
||||||
|
## 🔑 How to Obtain Auth Token
|
||||||
|
|
||||||
|
> [!Warning]
|
||||||
|
> - I suggest not using the **main account** to obtain the token.
|
||||||
|
> - 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.**
|
||||||
|
> - If too many media files are fetched, it may trigger a **rate limit**, and the media retrieval will fail, try enabling Batch mode.
|
||||||
|
|
||||||
|
### [Video Tutorial](https://www.patreon.com/posts/how-to-obtain-127206894)
|
||||||
|
|
||||||
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
|
||||||
|
|
||||||
|

|
||||||
@@ -1,737 +0,0 @@
|
|||||||
import sys
|
|
||||||
import os
|
|
||||||
import asyncio
|
|
||||||
import aiohttp
|
|
||||||
import re
|
|
||||||
import subprocess
|
|
||||||
from datetime import datetime
|
|
||||||
from pathlib import Path
|
|
||||||
from PyQt6.QtWidgets import (QApplication, QMainWindow, QWidget, QVBoxLayout,
|
|
||||||
QHBoxLayout, QLabel, QLineEdit, QPushButton,
|
|
||||||
QProgressBar, QFileDialog, QRadioButton, QComboBox)
|
|
||||||
from PyQt6.QtCore import QThread, pyqtSignal, Qt, QSettings
|
|
||||||
from PyQt6.QtGui import QIcon, QPixmap, QCursor, QPainter, QPainterPath
|
|
||||||
from gallery_dl.extractor import twitter
|
|
||||||
|
|
||||||
class ImageDownloader(QThread):
|
|
||||||
finished = pyqtSignal(bytes)
|
|
||||||
|
|
||||||
def __init__(self, url):
|
|
||||||
super().__init__()
|
|
||||||
self.url = url
|
|
||||||
|
|
||||||
async def download_image(self):
|
|
||||||
async with aiohttp.ClientSession() as session:
|
|
||||||
async with session.get(self.url) as response:
|
|
||||||
if response.status == 200:
|
|
||||||
return await response.read()
|
|
||||||
return None
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
image_data = asyncio.run(self.download_image())
|
|
||||||
if image_data:
|
|
||||||
self.finished.emit(image_data)
|
|
||||||
|
|
||||||
class MetadataFetcher(QThread):
|
|
||||||
finished = pyqtSignal(dict)
|
|
||||||
error = pyqtSignal(str)
|
|
||||||
|
|
||||||
def __init__(self, username, media_type='media'):
|
|
||||||
super().__init__()
|
|
||||||
self.username = username
|
|
||||||
self.auth_token = None
|
|
||||||
self.media_type = media_type
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
try:
|
|
||||||
username = self.username.strip()
|
|
||||||
if "x.com/" in username or "twitter.com/" in username:
|
|
||||||
username = username.split("/")[-1]
|
|
||||||
if username.endswith("/timeline"):
|
|
||||||
username = username[:-9]
|
|
||||||
|
|
||||||
url = f"https://x.com/{username}/timeline"
|
|
||||||
|
|
||||||
match = re.match(twitter.TwitterTimelineExtractor.pattern, url)
|
|
||||||
if not match:
|
|
||||||
raise ValueError(f"Invalid URL: {url}")
|
|
||||||
|
|
||||||
extractor = twitter.TwitterTimelineExtractor(match)
|
|
||||||
extractor.config = lambda key, default=None: {
|
|
||||||
"cookies": {
|
|
||||||
"auth_token": self.auth_token
|
|
||||||
}
|
|
||||||
}.get(key, default)
|
|
||||||
|
|
||||||
extractor.initialize()
|
|
||||||
|
|
||||||
output = {
|
|
||||||
'account_info': {},
|
|
||||||
'timeline': []
|
|
||||||
}
|
|
||||||
|
|
||||||
for item in extractor:
|
|
||||||
if isinstance(item, tuple) and len(item) >= 3:
|
|
||||||
media_url = item[1]
|
|
||||||
tweet_data = item[2]
|
|
||||||
|
|
||||||
if not output['account_info']:
|
|
||||||
if 'user' in tweet_data:
|
|
||||||
user = tweet_data['user']
|
|
||||||
user_date = user.get('date', '')
|
|
||||||
if isinstance(user_date, datetime):
|
|
||||||
user_date = user_date.strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
output['account_info'] = {
|
|
||||||
'name': user.get('name', ''),
|
|
||||||
'nick': user.get('nick', ''),
|
|
||||||
'date': user_date,
|
|
||||||
'followers_count': user.get('followers_count', 0),
|
|
||||||
'friends_count': user.get('friends_count', 0),
|
|
||||||
'profile_image': user.get('profile_image', ''),
|
|
||||||
'statuses_count': user.get('statuses_count', 0)
|
|
||||||
}
|
|
||||||
|
|
||||||
should_include = False
|
|
||||||
media_type = tweet_data.get('type', '')
|
|
||||||
|
|
||||||
if self.media_type == 'media':
|
|
||||||
should_include = ('pbs.twimg.com' in media_url or
|
|
||||||
'video.twimg.com' in media_url)
|
|
||||||
elif self.media_type == 'image':
|
|
||||||
should_include = ('pbs.twimg.com' in media_url and
|
|
||||||
media_type == 'photo')
|
|
||||||
elif self.media_type == 'gif':
|
|
||||||
should_include = media_type == 'animated_gif'
|
|
||||||
elif self.media_type == 'video':
|
|
||||||
should_include = (media_type == 'video' and
|
|
||||||
'video.twimg.com' in media_url)
|
|
||||||
|
|
||||||
if should_include:
|
|
||||||
tweet_date = tweet_data.get('date', datetime.now())
|
|
||||||
if isinstance(tweet_date, datetime):
|
|
||||||
tweet_date = tweet_date.strftime("%Y-%m-%d %H:%M:%S")
|
|
||||||
|
|
||||||
output['timeline'].append({
|
|
||||||
'url': media_url,
|
|
||||||
'date': tweet_date,
|
|
||||||
'type': media_type,
|
|
||||||
'tweet_id': tweet_data.get('tweet_id', '')
|
|
||||||
})
|
|
||||||
|
|
||||||
if not output['account_info']:
|
|
||||||
raise ValueError("Failed to fetch account information. Please check the username and auth token.")
|
|
||||||
|
|
||||||
if not output['timeline']:
|
|
||||||
if self.media_type == 'media':
|
|
||||||
message = "No media found in timeline"
|
|
||||||
elif self.media_type == 'image':
|
|
||||||
message = "No images found in timeline"
|
|
||||||
elif self.media_type == 'gif':
|
|
||||||
message = "No GIFs found in timeline"
|
|
||||||
else:
|
|
||||||
message = "No videos found in timeline"
|
|
||||||
raise ValueError(message)
|
|
||||||
|
|
||||||
self.finished.emit(output)
|
|
||||||
|
|
||||||
except Exception as e:
|
|
||||||
self.error.emit(str(e))
|
|
||||||
|
|
||||||
class MediaDownloader(QThread):
|
|
||||||
progress = pyqtSignal(int)
|
|
||||||
finished = pyqtSignal(str)
|
|
||||||
error = pyqtSignal(str)
|
|
||||||
status_update = pyqtSignal(str)
|
|
||||||
|
|
||||||
def __init__(self, media_list, output_dir, filename_format, username, media_type='media', batch_size=10):
|
|
||||||
super().__init__()
|
|
||||||
self.media_list = media_list
|
|
||||||
self.output_dir = output_dir
|
|
||||||
self.filename_format = filename_format
|
|
||||||
self.username = username
|
|
||||||
self.media_type = media_type
|
|
||||||
self.batch_size = batch_size
|
|
||||||
|
|
||||||
async def download_file(self, session, url, filepath):
|
|
||||||
try:
|
|
||||||
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
|
||||||
|
|
||||||
async with session.get(url) as response:
|
|
||||||
if response.status == 200:
|
|
||||||
with open(filepath, 'wb') as f:
|
|
||||||
f.write(await response.read())
|
|
||||||
return True
|
|
||||||
return False
|
|
||||||
except Exception:
|
|
||||||
return False
|
|
||||||
|
|
||||||
async def download_all(self):
|
|
||||||
os.makedirs(self.output_dir, exist_ok=True)
|
|
||||||
|
|
||||||
async with aiohttp.ClientSession() as session:
|
|
||||||
total = len(self.media_list)
|
|
||||||
completed = 0
|
|
||||||
|
|
||||||
used_filenames = set()
|
|
||||||
|
|
||||||
tasks = []
|
|
||||||
for item in self.media_list:
|
|
||||||
url = item['url']
|
|
||||||
date = datetime.strptime(item['date'], "%Y-%m-%d %H:%M:%S")
|
|
||||||
formatted_date = date.strftime("%Y%m%d_%H%M%S")
|
|
||||||
tweet_id = str(item.get('tweet_id', ''))
|
|
||||||
|
|
||||||
extension = 'mp4' if 'video.twimg.com' in url else 'jpg'
|
|
||||||
|
|
||||||
if self.filename_format == "username_date":
|
|
||||||
base_filename = f"{self.username}_{formatted_date}_{tweet_id}"
|
|
||||||
else:
|
|
||||||
base_filename = f"{formatted_date}_{self.username}_{tweet_id}"
|
|
||||||
|
|
||||||
filename = f"{base_filename}.{extension}"
|
|
||||||
counter = 1
|
|
||||||
while filename in used_filenames:
|
|
||||||
filename = f"{base_filename}_{counter:02d}.{extension}"
|
|
||||||
counter += 1
|
|
||||||
|
|
||||||
used_filenames.add(filename)
|
|
||||||
filepath = os.path.join(self.output_dir, filename)
|
|
||||||
|
|
||||||
task = asyncio.create_task(self.download_file(session, url, filepath))
|
|
||||||
tasks.append(task)
|
|
||||||
|
|
||||||
if len(tasks) >= self.batch_size:
|
|
||||||
results = await asyncio.gather(*tasks)
|
|
||||||
completed += sum(1 for r in results if r)
|
|
||||||
progress = int((completed / total) * 100)
|
|
||||||
self.progress.emit(progress)
|
|
||||||
completed_str = f"{completed:,}" if completed >= 1000 else str(completed)
|
|
||||||
total_str = f"{total:,}" if total >= 1000 else str(total)
|
|
||||||
|
|
||||||
media_type_str = "files"
|
|
||||||
if self.media_type == "image":
|
|
||||||
media_type_str = "images"
|
|
||||||
elif self.media_type == "video":
|
|
||||||
media_type_str = "videos"
|
|
||||||
|
|
||||||
self.status_update.emit(f"Downloaded {completed_str} of {total_str} {media_type_str}...")
|
|
||||||
tasks = []
|
|
||||||
|
|
||||||
if tasks:
|
|
||||||
results = await asyncio.gather(*tasks)
|
|
||||||
completed += sum(1 for r in results if r)
|
|
||||||
progress = int((completed / total) * 100)
|
|
||||||
self.progress.emit(progress)
|
|
||||||
|
|
||||||
return completed
|
|
||||||
|
|
||||||
def run(self):
|
|
||||||
try:
|
|
||||||
completed = asyncio.run(self.download_all())
|
|
||||||
completed_str = f"{completed:,}" if completed >= 1000 else str(completed)
|
|
||||||
|
|
||||||
media_type_str = "files"
|
|
||||||
if self.media_type == "image":
|
|
||||||
media_type_str = "images"
|
|
||||||
elif self.media_type == "video":
|
|
||||||
media_type_str = "videos"
|
|
||||||
|
|
||||||
self.finished.emit(f"Downloaded {completed_str} {media_type_str} successfully!")
|
|
||||||
except Exception as e:
|
|
||||||
self.error.emit(str(e))
|
|
||||||
|
|
||||||
class TwitterMediaDownloaderGUI(QMainWindow):
|
|
||||||
def __init__(self):
|
|
||||||
super().__init__()
|
|
||||||
self.setWindowTitle("Twitter/X Media Batch Downloader")
|
|
||||||
|
|
||||||
icon_path = os.path.join(os.path.dirname(__file__), "icon.svg")
|
|
||||||
if os.path.exists(icon_path):
|
|
||||||
self.setWindowIcon(QIcon(icon_path))
|
|
||||||
|
|
||||||
self.setFixedWidth(600)
|
|
||||||
self.setFixedHeight(180)
|
|
||||||
|
|
||||||
self.default_pictures_dir = str(Path.home() / "Pictures")
|
|
||||||
os.makedirs(self.default_pictures_dir, exist_ok=True)
|
|
||||||
|
|
||||||
self.media_info = None
|
|
||||||
self.settings = QSettings('TwitterMediaDownloader', 'Settings')
|
|
||||||
|
|
||||||
self.init_ui()
|
|
||||||
self.load_settings()
|
|
||||||
self.setup_auto_save()
|
|
||||||
|
|
||||||
def init_ui(self):
|
|
||||||
central_widget = QWidget()
|
|
||||||
self.setCentralWidget(central_widget)
|
|
||||||
self.main_layout = QVBoxLayout(central_widget)
|
|
||||||
self.main_layout.setContentsMargins(10, 10, 10, 10)
|
|
||||||
|
|
||||||
self.input_widget = QWidget()
|
|
||||||
input_layout = QVBoxLayout(self.input_widget)
|
|
||||||
input_layout.setSpacing(10)
|
|
||||||
|
|
||||||
url_layout = QHBoxLayout()
|
|
||||||
url_label = QLabel("Username/URL:")
|
|
||||||
url_label.setFixedWidth(100)
|
|
||||||
|
|
||||||
self.url_input = QLineEdit()
|
|
||||||
self.url_input.setPlaceholderText("e.g. Takomayuyi or https://x.com/Takomayuyi")
|
|
||||||
self.url_input.setClearButtonEnabled(True)
|
|
||||||
|
|
||||||
self.fetch_button = QPushButton("Fetch")
|
|
||||||
self.fetch_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
self.fetch_button.setFixedWidth(100)
|
|
||||||
self.fetch_button.clicked.connect(self.fetch_metadata)
|
|
||||||
|
|
||||||
url_layout.addWidget(url_label)
|
|
||||||
url_layout.addWidget(self.url_input)
|
|
||||||
url_layout.addWidget(self.fetch_button)
|
|
||||||
input_layout.addLayout(url_layout)
|
|
||||||
|
|
||||||
dir_layout = QHBoxLayout()
|
|
||||||
dir_label = QLabel("Output Directory:")
|
|
||||||
dir_label.setFixedWidth(100)
|
|
||||||
|
|
||||||
self.dir_input = QLineEdit(self.default_pictures_dir)
|
|
||||||
|
|
||||||
self.dir_button = QPushButton("Browse")
|
|
||||||
self.dir_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
self.dir_button.setFixedWidth(100)
|
|
||||||
self.dir_button.clicked.connect(self.select_directory)
|
|
||||||
|
|
||||||
dir_layout.addWidget(dir_label)
|
|
||||||
dir_layout.addWidget(self.dir_input)
|
|
||||||
dir_layout.addWidget(self.dir_button)
|
|
||||||
input_layout.addLayout(dir_layout)
|
|
||||||
|
|
||||||
auth_layout = QHBoxLayout()
|
|
||||||
auth_label = QLabel("Auth Token:")
|
|
||||||
auth_label.setFixedWidth(100)
|
|
||||||
|
|
||||||
self.auth_input = QLineEdit()
|
|
||||||
self.auth_input.setPlaceholderText("Enter your Twitter/X auth_token")
|
|
||||||
self.auth_input.setClearButtonEnabled(True)
|
|
||||||
|
|
||||||
auth_layout.addWidget(auth_label)
|
|
||||||
auth_layout.addWidget(self.auth_input)
|
|
||||||
input_layout.addLayout(auth_layout)
|
|
||||||
|
|
||||||
options_layout = QHBoxLayout()
|
|
||||||
|
|
||||||
media_label = QLabel("Media Type:")
|
|
||||||
media_label.setFixedWidth(100)
|
|
||||||
|
|
||||||
self.media_type_combo = QComboBox()
|
|
||||||
self.media_type_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
media_types = [('media', 'Media'), ('image', 'Image'), ('gif', 'GIF'), ('video', 'Video')]
|
|
||||||
for value, display in media_types:
|
|
||||||
self.media_type_combo.addItem(display, value)
|
|
||||||
self.media_type_combo.setFixedWidth(100)
|
|
||||||
|
|
||||||
batch_label = QLabel("Batch:")
|
|
||||||
batch_label.setFixedWidth(40)
|
|
||||||
|
|
||||||
self.batch_size_combo = QComboBox()
|
|
||||||
self.batch_size_combo.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
self.batch_size_combo.setFixedWidth(50)
|
|
||||||
for size in range(10, 101, 10):
|
|
||||||
self.batch_size_combo.addItem(str(size))
|
|
||||||
|
|
||||||
format_label = QLabel("Filename:")
|
|
||||||
format_label.setFixedWidth(60)
|
|
||||||
|
|
||||||
self.format_username = QRadioButton("Username")
|
|
||||||
self.format_date = QRadioButton("Date")
|
|
||||||
self.format_username.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
self.format_date.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
|
|
||||||
options_layout.addWidget(media_label)
|
|
||||||
options_layout.addWidget(self.media_type_combo)
|
|
||||||
options_layout.addSpacing(10)
|
|
||||||
options_layout.addWidget(batch_label)
|
|
||||||
options_layout.addWidget(self.batch_size_combo)
|
|
||||||
options_layout.addSpacing(10)
|
|
||||||
options_layout.addWidget(format_label)
|
|
||||||
options_layout.addWidget(self.format_username)
|
|
||||||
options_layout.addWidget(self.format_date)
|
|
||||||
options_layout.addStretch()
|
|
||||||
|
|
||||||
input_layout.addLayout(options_layout)
|
|
||||||
|
|
||||||
self.main_layout.addWidget(self.input_widget)
|
|
||||||
|
|
||||||
self.profile_widget = QWidget()
|
|
||||||
self.profile_widget.hide()
|
|
||||||
profile_layout = QHBoxLayout(self.profile_widget)
|
|
||||||
profile_layout.setContentsMargins(0, 0, 0, 0)
|
|
||||||
profile_layout.setSpacing(10)
|
|
||||||
|
|
||||||
profile_container = QWidget()
|
|
||||||
profile_image_layout = QVBoxLayout(profile_container)
|
|
||||||
profile_image_layout.setContentsMargins(0, 0, 0, 0)
|
|
||||||
profile_image_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
|
||||||
|
|
||||||
self.profile_image_label = QLabel()
|
|
||||||
self.profile_image_label.setFixedSize(100, 100)
|
|
||||||
self.profile_image_label.setAlignment(Qt.AlignmentFlag.AlignCenter)
|
|
||||||
profile_image_layout.addWidget(self.profile_image_label)
|
|
||||||
profile_layout.addWidget(profile_container)
|
|
||||||
|
|
||||||
profile_details_container = QWidget()
|
|
||||||
profile_details_layout = QVBoxLayout(profile_details_container)
|
|
||||||
profile_details_layout.setContentsMargins(0, 0, 0, 0)
|
|
||||||
profile_details_layout.setSpacing(2)
|
|
||||||
profile_details_layout.setAlignment(Qt.AlignmentFlag.AlignTop)
|
|
||||||
|
|
||||||
self.name_label = QLabel()
|
|
||||||
self.name_label.setStyleSheet("font-size: 14px;")
|
|
||||||
self.name_label.setWordWrap(True)
|
|
||||||
self.name_label.setMinimumWidth(400)
|
|
||||||
|
|
||||||
self.join_date_label = QLabel()
|
|
||||||
self.join_date_label.setStyleSheet("font-size: 12px;")
|
|
||||||
self.join_date_label.setWordWrap(True)
|
|
||||||
self.join_date_label.setMinimumWidth(400)
|
|
||||||
|
|
||||||
self.followers_label = QLabel()
|
|
||||||
self.followers_label.setStyleSheet("font-size: 12px;")
|
|
||||||
self.followers_label.setWordWrap(True)
|
|
||||||
self.followers_label.setMinimumWidth(400)
|
|
||||||
|
|
||||||
self.following_label = QLabel()
|
|
||||||
self.following_label.setStyleSheet("font-size: 12px;")
|
|
||||||
self.following_label.setWordWrap(True)
|
|
||||||
self.following_label.setMinimumWidth(400)
|
|
||||||
|
|
||||||
self.posts_label = QLabel()
|
|
||||||
self.posts_label.setStyleSheet("font-size: 12px;")
|
|
||||||
self.posts_label.setWordWrap(True)
|
|
||||||
self.posts_label.setMinimumWidth(400)
|
|
||||||
|
|
||||||
profile_details_layout.addWidget(self.name_label)
|
|
||||||
profile_details_layout.addWidget(self.join_date_label)
|
|
||||||
profile_details_layout.addWidget(self.followers_label)
|
|
||||||
profile_details_layout.addWidget(self.following_label)
|
|
||||||
profile_details_layout.addWidget(self.posts_label)
|
|
||||||
profile_details_layout.addWidget(self.posts_label)
|
|
||||||
profile_layout.addWidget(profile_details_container, stretch=1)
|
|
||||||
profile_layout.addStretch()
|
|
||||||
|
|
||||||
self.main_layout.addWidget(self.profile_widget)
|
|
||||||
|
|
||||||
self.download_button = QPushButton("Download")
|
|
||||||
self.download_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
self.download_button.setFixedWidth(100)
|
|
||||||
self.download_button.clicked.connect(self.start_download)
|
|
||||||
self.download_button.hide()
|
|
||||||
|
|
||||||
self.cancel_button = QPushButton("Cancel")
|
|
||||||
self.cancel_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
self.cancel_button.setFixedWidth(100)
|
|
||||||
self.cancel_button.clicked.connect(self.cancel_clicked)
|
|
||||||
self.cancel_button.hide()
|
|
||||||
|
|
||||||
self.open_button = QPushButton("Open")
|
|
||||||
self.open_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
self.open_button.setFixedWidth(100)
|
|
||||||
self.open_button.clicked.connect(self.open_output_directory)
|
|
||||||
self.open_button.hide()
|
|
||||||
|
|
||||||
button_layout = QHBoxLayout()
|
|
||||||
button_layout.addStretch()
|
|
||||||
button_layout.addWidget(self.open_button)
|
|
||||||
button_layout.addWidget(self.download_button)
|
|
||||||
button_layout.addWidget(self.cancel_button)
|
|
||||||
button_layout.addStretch()
|
|
||||||
self.main_layout.addLayout(button_layout)
|
|
||||||
|
|
||||||
self.progress_bar = QProgressBar()
|
|
||||||
self.progress_bar.hide()
|
|
||||||
self.main_layout.addWidget(self.progress_bar)
|
|
||||||
|
|
||||||
bottom_layout = QHBoxLayout()
|
|
||||||
|
|
||||||
self.status_label = QLabel("")
|
|
||||||
bottom_layout.addWidget(self.status_label, stretch=1)
|
|
||||||
|
|
||||||
self.update_button = QPushButton()
|
|
||||||
icon_path = os.path.join(os.path.dirname(__file__), "update.svg")
|
|
||||||
if os.path.exists(icon_path):
|
|
||||||
self.update_button.setIcon(QIcon(icon_path))
|
|
||||||
self.update_button.setFixedSize(16, 16)
|
|
||||||
self.update_button.setStyleSheet("""
|
|
||||||
QPushButton {
|
|
||||||
border: none;
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
QPushButton:hover {
|
|
||||||
background: transparent;
|
|
||||||
}
|
|
||||||
""")
|
|
||||||
self.update_button.setCursor(QCursor(Qt.CursorShape.PointingHandCursor))
|
|
||||||
self.update_button.setToolTip("Check for Updates")
|
|
||||||
self.update_button.clicked.connect(self.open_update_page)
|
|
||||||
|
|
||||||
bottom_layout.addWidget(self.update_button)
|
|
||||||
|
|
||||||
self.main_layout.addLayout(bottom_layout)
|
|
||||||
|
|
||||||
def open_update_page(self):
|
|
||||||
import webbrowser
|
|
||||||
webbrowser.open('https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases')
|
|
||||||
|
|
||||||
def setup_auto_save(self):
|
|
||||||
self.url_input.textChanged.connect(self.auto_save_settings)
|
|
||||||
self.auth_input.textChanged.connect(self.auto_save_settings)
|
|
||||||
self.dir_input.textChanged.connect(self.auto_save_settings)
|
|
||||||
self.format_username.toggled.connect(self.auto_save_settings)
|
|
||||||
self.media_type_combo.currentTextChanged.connect(self.auto_save_settings)
|
|
||||||
self.batch_size_combo.currentTextChanged.connect(self.auto_save_settings)
|
|
||||||
|
|
||||||
def auto_save_settings(self):
|
|
||||||
self.settings.setValue('url_input', self.url_input.text())
|
|
||||||
self.settings.setValue('auth_token', self.auth_input.text())
|
|
||||||
self.settings.setValue('output_dir', self.dir_input.text())
|
|
||||||
self.settings.setValue('filename_format',
|
|
||||||
'username_date' if self.format_username.isChecked() else 'date_username')
|
|
||||||
self.settings.setValue('media_type', self.media_type_combo.currentData())
|
|
||||||
self.settings.setValue('batch_size', self.batch_size_combo.currentText())
|
|
||||||
self.settings.sync()
|
|
||||||
|
|
||||||
def load_settings(self):
|
|
||||||
self.url_input.setText(self.settings.value('url_input', '', str))
|
|
||||||
self.auth_input.setText(self.settings.value('auth_token', '', str))
|
|
||||||
self.dir_input.setText(self.settings.value('output_dir', self.default_pictures_dir, str))
|
|
||||||
|
|
||||||
format_setting = self.settings.value('filename_format', 'username_date')
|
|
||||||
self.format_username.setChecked(format_setting == 'username_date')
|
|
||||||
self.format_date.setChecked(format_setting == 'date_username')
|
|
||||||
|
|
||||||
media_type = self.settings.value('media_type', 'media')
|
|
||||||
for i in range(self.media_type_combo.count()):
|
|
||||||
if self.media_type_combo.itemData(i) == media_type:
|
|
||||||
self.media_type_combo.setCurrentIndex(i)
|
|
||||||
break
|
|
||||||
|
|
||||||
batch_size = self.settings.value('batch_size', '10')
|
|
||||||
index = self.batch_size_combo.findText(batch_size)
|
|
||||||
if index >= 0:
|
|
||||||
self.batch_size_combo.setCurrentIndex(index)
|
|
||||||
|
|
||||||
def select_directory(self):
|
|
||||||
directory = QFileDialog.getExistingDirectory(self, "Select Output Directory")
|
|
||||||
if directory:
|
|
||||||
os.makedirs(directory, exist_ok=True)
|
|
||||||
self.dir_input.setText(directory)
|
|
||||||
|
|
||||||
def open_output_directory(self):
|
|
||||||
output_dir = self.dir_input.text().strip() or self.default_pictures_dir
|
|
||||||
if os.path.exists(output_dir):
|
|
||||||
if sys.platform == 'win32':
|
|
||||||
os.startfile(output_dir)
|
|
||||||
elif sys.platform == 'darwin':
|
|
||||||
subprocess.run(['open', output_dir])
|
|
||||||
else:
|
|
||||||
subprocess.run(['xdg-open', output_dir])
|
|
||||||
|
|
||||||
def fetch_metadata(self):
|
|
||||||
username = self.url_input.text().strip()
|
|
||||||
if not username:
|
|
||||||
self.status_label.setText("Please enter a username or URL")
|
|
||||||
return
|
|
||||||
|
|
||||||
auth_token = self.auth_input.text().strip()
|
|
||||||
if not auth_token:
|
|
||||||
self.status_label.setText("Please enter your auth token")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.fetch_button.setEnabled(False)
|
|
||||||
self.status_label.setText("Fetching profile information...")
|
|
||||||
|
|
||||||
media_type = self.media_type_combo.currentData()
|
|
||||||
self.fetcher = MetadataFetcher(username, media_type)
|
|
||||||
self.fetcher.auth_token = auth_token
|
|
||||||
self.fetcher.finished.connect(self.handle_profile_info)
|
|
||||||
self.fetcher.error.connect(self.handle_fetch_error)
|
|
||||||
self.fetcher.start()
|
|
||||||
|
|
||||||
def handle_profile_info(self, info):
|
|
||||||
if not info.get('account_info'):
|
|
||||||
self.status_label.setText("Failed to fetch profile information")
|
|
||||||
self.fetch_button.setEnabled(True)
|
|
||||||
return
|
|
||||||
|
|
||||||
self.media_info = info
|
|
||||||
self.fetch_button.setEnabled(True)
|
|
||||||
|
|
||||||
account_info = info['account_info']
|
|
||||||
name = account_info['name']
|
|
||||||
nick = account_info['nick']
|
|
||||||
join_date = datetime.strptime(account_info['date'], "%Y-%m-%d %H:%M:%S")
|
|
||||||
followers = account_info['followers_count']
|
|
||||||
following = account_info['friends_count']
|
|
||||||
posts = account_info['statuses_count']
|
|
||||||
|
|
||||||
join_date_str = join_date.strftime("%A, %d %B %Y - %H:%M")
|
|
||||||
|
|
||||||
self.name_label.setText(f"<b>{name}</b> ({nick})")
|
|
||||||
self.join_date_label.setText(f"<b>Join Date:</b> {join_date_str}")
|
|
||||||
self.followers_label.setText(f"<b>Followers:</b> {followers:,}")
|
|
||||||
self.following_label.setText(f"<b>Following:</b> {following:,}")
|
|
||||||
self.posts_label.setText(f"<b>Posts:</b> {posts:,}")
|
|
||||||
|
|
||||||
media_count = len(info['timeline'])
|
|
||||||
self.status_label.setText(f"Successfully fetched {media_count:,} media items")
|
|
||||||
|
|
||||||
profile_image_url = account_info['profile_image']
|
|
||||||
self.image_downloader = ImageDownloader(profile_image_url)
|
|
||||||
self.image_downloader.finished.connect(self.update_profile_image)
|
|
||||||
self.image_downloader.start()
|
|
||||||
|
|
||||||
self.input_widget.hide()
|
|
||||||
self.profile_widget.show()
|
|
||||||
self.download_button.show()
|
|
||||||
self.cancel_button.show()
|
|
||||||
self.update_button.hide()
|
|
||||||
|
|
||||||
username = self.url_input.text().strip()
|
|
||||||
if "x.com/" in username or "twitter.com/" in username:
|
|
||||||
username = username.split("/")[-1]
|
|
||||||
if username.endswith("/timeline"):
|
|
||||||
username = username[:-9]
|
|
||||||
|
|
||||||
output_base = self.dir_input.text().strip() or self.default_pictures_dir
|
|
||||||
self.user_output_dir = os.path.join(output_base, username)
|
|
||||||
os.makedirs(self.user_output_dir, exist_ok=True)
|
|
||||||
|
|
||||||
def update_profile_image(self, image_data):
|
|
||||||
original_pixmap = QPixmap()
|
|
||||||
original_pixmap.loadFromData(image_data)
|
|
||||||
|
|
||||||
scaled_pixmap = original_pixmap.scaled(100, 100,
|
|
||||||
Qt.AspectRatioMode.KeepAspectRatio,
|
|
||||||
Qt.TransformationMode.SmoothTransformation)
|
|
||||||
|
|
||||||
rounded_pixmap = QPixmap(scaled_pixmap.size())
|
|
||||||
rounded_pixmap.fill(Qt.GlobalColor.transparent)
|
|
||||||
|
|
||||||
painter = QPainter(rounded_pixmap)
|
|
||||||
painter.setRenderHint(QPainter.RenderHint.Antialiasing)
|
|
||||||
|
|
||||||
path = QPainterPath()
|
|
||||||
path.addRoundedRect(0, 0, scaled_pixmap.width(), scaled_pixmap.height(), 10, 10)
|
|
||||||
|
|
||||||
painter.setClipPath(path)
|
|
||||||
painter.drawPixmap(0, 0, scaled_pixmap)
|
|
||||||
painter.end()
|
|
||||||
|
|
||||||
self.profile_image_label.setPixmap(rounded_pixmap)
|
|
||||||
|
|
||||||
def handle_fetch_error(self, error):
|
|
||||||
self.fetch_button.setEnabled(True)
|
|
||||||
self.status_label.setText(f"Error fetching profile info: {error}")
|
|
||||||
|
|
||||||
def start_download(self):
|
|
||||||
if not self.media_info:
|
|
||||||
self.status_label.setText("Please fetch profile information first")
|
|
||||||
return
|
|
||||||
|
|
||||||
auth_token = self.auth_input.text().strip()
|
|
||||||
if not auth_token:
|
|
||||||
self.status_label.setText("Please enter your auth token")
|
|
||||||
return
|
|
||||||
|
|
||||||
self.download_button.hide()
|
|
||||||
self.cancel_button.hide()
|
|
||||||
self.progress_bar.show()
|
|
||||||
self.progress_bar.setValue(0)
|
|
||||||
self.status_label.setText("Starting download...")
|
|
||||||
|
|
||||||
filename_format = "username_date" if self.format_username.isChecked() else "date_username"
|
|
||||||
batch_size = int(self.batch_size_combo.currentText())
|
|
||||||
media_type = self.media_type_combo.currentData()
|
|
||||||
|
|
||||||
username = self.url_input.text().strip()
|
|
||||||
if "x.com/" in username or "twitter.com/" in username:
|
|
||||||
username = username.split("/")[-1]
|
|
||||||
if username.endswith("/timeline"):
|
|
||||||
username = username[:-9]
|
|
||||||
|
|
||||||
self.worker = MediaDownloader(
|
|
||||||
self.media_info['timeline'],
|
|
||||||
self.user_output_dir,
|
|
||||||
filename_format,
|
|
||||||
username,
|
|
||||||
media_type,
|
|
||||||
batch_size
|
|
||||||
)
|
|
||||||
self.worker.progress.connect(self.update_progress)
|
|
||||||
self.worker.finished.connect(self.download_finished)
|
|
||||||
self.worker.error.connect(self.download_error)
|
|
||||||
self.worker.status_update.connect(self.status_label.setText)
|
|
||||||
self.worker.start()
|
|
||||||
|
|
||||||
def update_progress(self, value):
|
|
||||||
self.progress_bar.setValue(value)
|
|
||||||
|
|
||||||
def download_finished(self, message):
|
|
||||||
self.progress_bar.hide()
|
|
||||||
self.status_label.setText(message)
|
|
||||||
self.open_button.show()
|
|
||||||
self.download_button.setText("Clear")
|
|
||||||
self.download_button.clicked.disconnect()
|
|
||||||
self.download_button.clicked.connect(self.clear_form)
|
|
||||||
self.download_button.show()
|
|
||||||
self.cancel_button.hide()
|
|
||||||
|
|
||||||
def clear_form(self):
|
|
||||||
self.url_input.clear()
|
|
||||||
self.profile_widget.hide()
|
|
||||||
self.input_widget.show()
|
|
||||||
self.download_button.hide()
|
|
||||||
self.cancel_button.hide()
|
|
||||||
self.open_button.hide()
|
|
||||||
self.progress_bar.hide()
|
|
||||||
self.progress_bar.setValue(0)
|
|
||||||
self.status_label.clear()
|
|
||||||
self.media_info = None
|
|
||||||
self.update_button.show()
|
|
||||||
self.fetch_button.setEnabled(True)
|
|
||||||
self.download_button.setText("Download")
|
|
||||||
self.download_button.clicked.disconnect()
|
|
||||||
self.download_button.clicked.connect(self.start_download)
|
|
||||||
|
|
||||||
def download_error(self, error_message):
|
|
||||||
self.progress_bar.hide()
|
|
||||||
self.status_label.setText(f"Download error: {error_message}")
|
|
||||||
self.download_button.setText("Retry")
|
|
||||||
self.download_button.show()
|
|
||||||
self.cancel_button.show()
|
|
||||||
|
|
||||||
def cancel_clicked(self):
|
|
||||||
self.profile_widget.hide()
|
|
||||||
self.input_widget.show()
|
|
||||||
self.download_button.hide()
|
|
||||||
self.cancel_button.hide()
|
|
||||||
self.open_button.hide()
|
|
||||||
self.progress_bar.hide()
|
|
||||||
self.progress_bar.setValue(0)
|
|
||||||
self.status_label.clear()
|
|
||||||
self.media_info = None
|
|
||||||
self.update_button.show()
|
|
||||||
self.fetch_button.setEnabled(True)
|
|
||||||
|
|
||||||
def main():
|
|
||||||
if getattr(sys, 'frozen', False):
|
|
||||||
os.chdir(os.path.dirname(sys.executable))
|
|
||||||
|
|
||||||
app = QApplication(sys.argv)
|
|
||||||
window = TwitterMediaDownloaderGUI()
|
|
||||||
window.show()
|
|
||||||
sys.exit(app.exec())
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
|
||||||
main()
|
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
from ui.mainWindow_Unix import TwitterXMediaBatchDownloaderGUI_Unix
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
os.chdir(os.path.dirname(sys.executable))
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
app.setStyle('Fusion')
|
||||||
|
|
||||||
|
window = TwitterXMediaBatchDownloaderGUI_Unix()
|
||||||
|
window.show()
|
||||||
|
sys.exit(app.exec())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,18 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
from ui.mainWindow_Unix import TwitterXMediaBatchDownloaderGUI_Unix
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
os.chdir(os.path.dirname(sys.executable))
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
app.setStyle('Fusion')
|
||||||
|
|
||||||
|
window = TwitterXMediaBatchDownloaderGUI_Unix()
|
||||||
|
window.show()
|
||||||
|
sys.exit(app.exec())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,29 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import qdarktheme
|
||||||
|
from PyQt6.QtWidgets import QApplication
|
||||||
|
from PyQt6.QtCore import QSettings
|
||||||
|
from ui.mainWindow import TwitterXMediaBatchDownloaderGUI
|
||||||
|
|
||||||
|
def main():
|
||||||
|
if getattr(sys, 'frozen', False):
|
||||||
|
os.chdir(os.path.dirname(sys.executable))
|
||||||
|
|
||||||
|
app = QApplication(sys.argv)
|
||||||
|
|
||||||
|
settings = QSettings('TwitterXMediaBatchDownloader', 'Settings')
|
||||||
|
theme_color = settings.value('theme_color', '#2196F3')
|
||||||
|
|
||||||
|
qdarktheme.setup_theme(
|
||||||
|
custom_colors={
|
||||||
|
"[dark]": {
|
||||||
|
"primary": theme_color,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
)
|
||||||
|
window = TwitterXMediaBatchDownloaderGUI()
|
||||||
|
window.show()
|
||||||
|
sys.exit(app.exec())
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
main()
|
||||||
@@ -0,0 +1,14 @@
|
|||||||
|
from core.databaseManager import DatabaseManager
|
||||||
|
from core.metadataFetcher import get_metadata, get_metadata_by_date
|
||||||
|
from core.downloadWorker import DownloadWorker
|
||||||
|
from core.metadataWorker import MetadataFetchWorker
|
||||||
|
from core.accountModel import Account
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'DatabaseManager',
|
||||||
|
'get_metadata',
|
||||||
|
'get_metadata_by_date',
|
||||||
|
'DownloadWorker',
|
||||||
|
'MetadataFetchWorker',
|
||||||
|
'Account'
|
||||||
|
]
|
||||||
@@ -0,0 +1,15 @@
|
|||||||
|
from dataclasses import dataclass
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class Account:
|
||||||
|
username: str
|
||||||
|
nick: str
|
||||||
|
followers: int
|
||||||
|
following: int
|
||||||
|
posts: int
|
||||||
|
media_type: str
|
||||||
|
profile_image: str = None
|
||||||
|
media_list: list = None
|
||||||
|
fetch_mode: str = 'all'
|
||||||
|
fetch_timestamp: str = None
|
||||||
|
group_id: int = None
|
||||||
@@ -0,0 +1,420 @@
|
|||||||
|
import sqlite3
|
||||||
|
import os
|
||||||
|
import json
|
||||||
|
import threading
|
||||||
|
from datetime import datetime
|
||||||
|
from pathlib import Path
|
||||||
|
from typing import List, Dict, Optional, Tuple
|
||||||
|
|
||||||
|
class DatabaseManager:
|
||||||
|
def __init__(self, db_path: str):
|
||||||
|
self.db_path = db_path
|
||||||
|
self.conn = None
|
||||||
|
self._lock = threading.Lock()
|
||||||
|
self.init_database()
|
||||||
|
|
||||||
|
def init_database(self):
|
||||||
|
self.conn = sqlite3.connect(self.db_path, check_same_thread=False)
|
||||||
|
self.conn.row_factory = sqlite3.Row
|
||||||
|
|
||||||
|
self.conn.execute('PRAGMA foreign_keys = ON')
|
||||||
|
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS groups (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
name TEXT UNIQUE NOT NULL,
|
||||||
|
created_at TEXT
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS accounts (
|
||||||
|
username TEXT PRIMARY KEY COLLATE NOCASE,
|
||||||
|
nick TEXT,
|
||||||
|
followers INTEGER,
|
||||||
|
following INTEGER,
|
||||||
|
posts INTEGER,
|
||||||
|
profile_image TEXT,
|
||||||
|
fetch_timestamp TEXT,
|
||||||
|
media_type TEXT,
|
||||||
|
fetch_mode TEXT,
|
||||||
|
timeline_type TEXT DEFAULT 'media',
|
||||||
|
group_id INTEGER,
|
||||||
|
FOREIGN KEY (group_id) REFERENCES groups(id) ON DELETE SET NULL
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
try:
|
||||||
|
cursor.execute("SELECT group_id FROM accounts LIMIT 1")
|
||||||
|
except sqlite3.OperationalError:
|
||||||
|
cursor.execute("ALTER TABLE accounts ADD COLUMN group_id INTEGER")
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS media (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
username TEXT COLLATE NOCASE,
|
||||||
|
tweet_id TEXT,
|
||||||
|
url TEXT,
|
||||||
|
date TEXT,
|
||||||
|
type TEXT,
|
||||||
|
FOREIGN KEY (username) REFERENCES accounts(username) ON DELETE CASCADE,
|
||||||
|
UNIQUE(username, url)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
CREATE TABLE IF NOT EXISTS downloads (
|
||||||
|
id INTEGER PRIMARY KEY AUTOINCREMENT,
|
||||||
|
url TEXT,
|
||||||
|
filepath TEXT,
|
||||||
|
filepath_normalized TEXT COLLATE NOCASE,
|
||||||
|
username TEXT COLLATE NOCASE,
|
||||||
|
tweet_id TEXT,
|
||||||
|
download_date TEXT,
|
||||||
|
file_size INTEGER,
|
||||||
|
status TEXT,
|
||||||
|
UNIQUE(url, filepath_normalized)
|
||||||
|
)
|
||||||
|
''')
|
||||||
|
|
||||||
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_filepath_normalized ON downloads(filepath_normalized)')
|
||||||
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_url ON downloads(url)')
|
||||||
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_username ON downloads(username)')
|
||||||
|
cursor.execute('CREATE INDEX IF NOT EXISTS idx_media_username ON media(username)')
|
||||||
|
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def save_account(self, username: str, nick: str, followers: int, following: int,
|
||||||
|
posts: int, media_type: str, profile_image: str = None,
|
||||||
|
fetch_mode: str = 'all', timeline_type: str = 'media',
|
||||||
|
fetch_timestamp: str = None, group_id: int = None):
|
||||||
|
with self._lock:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
if fetch_timestamp is None:
|
||||||
|
fetch_timestamp = datetime.now().isoformat()
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
INSERT OR REPLACE INTO accounts
|
||||||
|
(username, nick, followers, following, posts, profile_image,
|
||||||
|
fetch_timestamp, media_type, fetch_mode, timeline_type, group_id)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
''', (username, nick, followers, following, posts, profile_image,
|
||||||
|
fetch_timestamp, media_type, fetch_mode, timeline_type, group_id))
|
||||||
|
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def save_media_list(self, username: str, media_list: List[Dict]):
|
||||||
|
with self._lock:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute('DELETE FROM media WHERE username = ?', (username,))
|
||||||
|
|
||||||
|
for item in media_list:
|
||||||
|
cursor.execute('''
|
||||||
|
INSERT OR IGNORE INTO media (username, tweet_id, url, date, type)
|
||||||
|
VALUES (?, ?, ?, ?, ?)
|
||||||
|
''', (username, item.get('tweet_id', ''), item['url'],
|
||||||
|
item['date'], item.get('type', 'image')))
|
||||||
|
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def get_account(self, username: str, media_type: str = 'all') -> Optional[Dict]:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('''
|
||||||
|
SELECT * FROM accounts
|
||||||
|
WHERE username = ? AND media_type = ?
|
||||||
|
''', (username, media_type))
|
||||||
|
|
||||||
|
row = cursor.fetchone()
|
||||||
|
if row:
|
||||||
|
return dict(row)
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_media_list(self, username: str) -> List[Dict]:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('''
|
||||||
|
SELECT tweet_id, url, date, type
|
||||||
|
FROM media
|
||||||
|
WHERE username = ?
|
||||||
|
ORDER BY date DESC
|
||||||
|
''', (username,))
|
||||||
|
|
||||||
|
return [dict(row) for row in cursor.fetchall()]
|
||||||
|
|
||||||
|
def get_all_accounts(self) -> List[Dict]:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('SELECT * FROM accounts ORDER BY fetch_timestamp DESC')
|
||||||
|
return [dict(row) for row in cursor.fetchall()]
|
||||||
|
|
||||||
|
def delete_account(self, username: str, media_type: str = None):
|
||||||
|
with self._lock:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
if media_type:
|
||||||
|
cursor.execute('DELETE FROM accounts WHERE username = ? AND media_type = ?',
|
||||||
|
(username, media_type))
|
||||||
|
else:
|
||||||
|
cursor.execute('DELETE FROM accounts WHERE username = ?', (username,))
|
||||||
|
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def is_file_downloaded(self, filepath: str) -> bool:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
filepath_normalized = filepath.lower()
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
SELECT 1 FROM downloads
|
||||||
|
WHERE filepath_normalized = ? AND status = 'downloaded'
|
||||||
|
LIMIT 1
|
||||||
|
''', (filepath_normalized,))
|
||||||
|
|
||||||
|
return cursor.fetchone() is not None
|
||||||
|
|
||||||
|
def is_url_downloaded(self, url: str) -> bool:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
SELECT 1 FROM downloads
|
||||||
|
WHERE url = ? AND status = 'downloaded'
|
||||||
|
LIMIT 1
|
||||||
|
''', (url,))
|
||||||
|
|
||||||
|
return cursor.fetchone() is not None
|
||||||
|
|
||||||
|
def record_download(self, url: str, filepath: str, username: str,
|
||||||
|
tweet_id: str, status: str = 'downloaded', file_size: int = 0):
|
||||||
|
with self._lock:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
filepath_normalized = filepath.lower()
|
||||||
|
download_date = datetime.now().isoformat()
|
||||||
|
|
||||||
|
cursor.execute('''
|
||||||
|
INSERT OR REPLACE INTO downloads
|
||||||
|
(url, filepath, filepath_normalized, username, tweet_id,
|
||||||
|
download_date, file_size, status)
|
||||||
|
VALUES (?, ?, ?, ?, ?, ?, ?, ?)
|
||||||
|
''', (url, filepath, filepath_normalized, username, tweet_id,
|
||||||
|
download_date, file_size, status))
|
||||||
|
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def get_download_stats(self, username: str = None) -> Dict:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
|
||||||
|
if username:
|
||||||
|
cursor.execute('''
|
||||||
|
SELECT
|
||||||
|
COUNT(*) as total,
|
||||||
|
SUM(CASE WHEN status = 'downloaded' THEN 1 ELSE 0 END) as downloaded,
|
||||||
|
SUM(CASE WHEN status = 'skipped' THEN 1 ELSE 0 END) as skipped,
|
||||||
|
SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) as failed,
|
||||||
|
SUM(file_size) as total_size
|
||||||
|
FROM downloads
|
||||||
|
WHERE username = ?
|
||||||
|
''', (username,))
|
||||||
|
else:
|
||||||
|
cursor.execute('''
|
||||||
|
SELECT
|
||||||
|
COUNT(*) as total,
|
||||||
|
SUM(CASE WHEN status = 'downloaded' THEN 1 ELSE 0 END) as downloaded,
|
||||||
|
SUM(CASE WHEN status = 'skipped' THEN 1 ELSE 0 END) as skipped,
|
||||||
|
SUM(CASE WHEN status = 'failed' THEN 1 ELSE 0 END) as failed,
|
||||||
|
SUM(file_size) as total_size
|
||||||
|
FROM downloads
|
||||||
|
''')
|
||||||
|
|
||||||
|
row = cursor.fetchone()
|
||||||
|
return dict(row) if row else {}
|
||||||
|
|
||||||
|
def migrate_from_json(self, json_dir: str) -> Tuple[int, int]:
|
||||||
|
if not os.path.exists(json_dir):
|
||||||
|
return 0, 0
|
||||||
|
|
||||||
|
json_files = [f for f in os.listdir(json_dir) if f.endswith('.json')]
|
||||||
|
accounts_migrated = 0
|
||||||
|
media_migrated = 0
|
||||||
|
|
||||||
|
for json_file in json_files:
|
||||||
|
try:
|
||||||
|
json_path = os.path.join(json_dir, json_file)
|
||||||
|
|
||||||
|
with open(json_path, 'r', encoding='utf-8') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
media_type = data.get('media_type', 'all')
|
||||||
|
|
||||||
|
if media_type not in ['all', 'image', 'video', 'gif']:
|
||||||
|
filename_parts = json_file.replace('.json', '').split('_')
|
||||||
|
if len(filename_parts) >= 1:
|
||||||
|
last_part = filename_parts[-1]
|
||||||
|
if last_part in ['all', 'image', 'video', 'gif']:
|
||||||
|
media_type = last_part
|
||||||
|
else:
|
||||||
|
media_type = 'all'
|
||||||
|
else:
|
||||||
|
media_type = 'all'
|
||||||
|
|
||||||
|
filename_parts = json_file.replace('.json', '').split('_')
|
||||||
|
if len(filename_parts) >= 2:
|
||||||
|
second_last = filename_parts[-2]
|
||||||
|
if second_last in ['media', 'timeline', 'tweets', 'with']:
|
||||||
|
timeline_type = second_last
|
||||||
|
else:
|
||||||
|
timeline_type = 'media'
|
||||||
|
else:
|
||||||
|
timeline_type = 'media'
|
||||||
|
|
||||||
|
account_info = data.get('account_info', {})
|
||||||
|
timeline = data.get('timeline', [])
|
||||||
|
|
||||||
|
username = data.get('username') or account_info.get('name', filename_parts[0] if filename_parts else 'unknown')
|
||||||
|
|
||||||
|
nick = data.get('nick') or account_info.get('nick') or account_info.get('name', username)
|
||||||
|
followers = data.get('followers') or account_info.get('followers_count', 0)
|
||||||
|
following = data.get('following') or account_info.get('friends_count', 0)
|
||||||
|
posts = data.get('posts') or account_info.get('statuses_count', 0)
|
||||||
|
profile_image = data.get('profile_image') or account_info.get('profile_image')
|
||||||
|
|
||||||
|
self.save_account(
|
||||||
|
username=username,
|
||||||
|
nick=nick,
|
||||||
|
followers=followers,
|
||||||
|
following=following,
|
||||||
|
posts=posts,
|
||||||
|
media_type=media_type,
|
||||||
|
profile_image=profile_image,
|
||||||
|
fetch_mode=data.get('fetch_mode', 'all'),
|
||||||
|
timeline_type=timeline_type
|
||||||
|
)
|
||||||
|
accounts_migrated += 1
|
||||||
|
|
||||||
|
media_list = timeline if timeline else data.get('media_list', [])
|
||||||
|
if media_list:
|
||||||
|
self.save_media_list(username, media_list)
|
||||||
|
media_migrated += len(media_list)
|
||||||
|
|
||||||
|
backup_path = json_path + '.backup'
|
||||||
|
if not os.path.exists(backup_path):
|
||||||
|
os.rename(json_path, backup_path)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error migrating {json_file}: {e}")
|
||||||
|
continue
|
||||||
|
|
||||||
|
return accounts_migrated, media_migrated
|
||||||
|
|
||||||
|
def export_to_json(self, username: str, media_type: str, output_path: str):
|
||||||
|
account = self.get_account(username, media_type)
|
||||||
|
if not account:
|
||||||
|
return False
|
||||||
|
|
||||||
|
media_list = self.get_media_list(username)
|
||||||
|
|
||||||
|
export_data = {
|
||||||
|
'username': account['username'],
|
||||||
|
'nick': account['nick'],
|
||||||
|
'followers': account['followers'],
|
||||||
|
'following': account['following'],
|
||||||
|
'posts': account['posts'],
|
||||||
|
'profile_image': account['profile_image'],
|
||||||
|
'fetch_timestamp': account['fetch_timestamp'],
|
||||||
|
'media_type': account['media_type'],
|
||||||
|
'fetch_mode': account['fetch_mode'],
|
||||||
|
'media_list': media_list
|
||||||
|
}
|
||||||
|
|
||||||
|
with open(output_path, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(export_data, f, ensure_ascii=False, indent=2)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
def import_from_json(self, json_path: str) -> bool:
|
||||||
|
try:
|
||||||
|
with open(json_path, 'r', encoding='utf-8') as f:
|
||||||
|
data = json.load(f)
|
||||||
|
|
||||||
|
username = data.get('username')
|
||||||
|
if not username:
|
||||||
|
return False
|
||||||
|
|
||||||
|
self.save_account(
|
||||||
|
username=username,
|
||||||
|
nick=data.get('nick', ''),
|
||||||
|
followers=data.get('followers', 0),
|
||||||
|
following=data.get('following', 0),
|
||||||
|
posts=data.get('posts', 0),
|
||||||
|
media_type=data.get('media_type', 'all'),
|
||||||
|
profile_image=data.get('profile_image'),
|
||||||
|
fetch_mode=data.get('fetch_mode', 'all')
|
||||||
|
)
|
||||||
|
|
||||||
|
media_list = data.get('media_list', [])
|
||||||
|
if media_list:
|
||||||
|
self.save_media_list(username, media_list)
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error importing JSON: {e}")
|
||||||
|
return False
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
if self.conn:
|
||||||
|
self.conn.close()
|
||||||
|
|
||||||
|
def create_group(self, name: str) -> Optional[int]:
|
||||||
|
with self._lock:
|
||||||
|
try:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
created_at = datetime.now().isoformat()
|
||||||
|
cursor.execute('INSERT INTO groups (name, created_at) VALUES (?, ?)', (name, created_at))
|
||||||
|
self.conn.commit()
|
||||||
|
return cursor.lastrowid
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
return None
|
||||||
|
|
||||||
|
def get_all_groups(self) -> List[Dict]:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('SELECT * FROM groups ORDER BY name')
|
||||||
|
return [dict(row) for row in cursor.fetchall()]
|
||||||
|
|
||||||
|
def get_group(self, group_id: int) -> Optional[Dict]:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('SELECT * FROM groups WHERE id = ?', (group_id,))
|
||||||
|
row = cursor.fetchone()
|
||||||
|
return dict(row) if row else None
|
||||||
|
|
||||||
|
def update_group(self, group_id: int, name: str) -> bool:
|
||||||
|
with self._lock:
|
||||||
|
try:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('UPDATE groups SET name = ? WHERE id = ?', (name, group_id))
|
||||||
|
self.conn.commit()
|
||||||
|
return True
|
||||||
|
except sqlite3.IntegrityError:
|
||||||
|
return False
|
||||||
|
|
||||||
|
def delete_group(self, group_id: int):
|
||||||
|
with self._lock:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('UPDATE accounts SET group_id = NULL WHERE group_id = ?', (group_id,))
|
||||||
|
cursor.execute('DELETE FROM groups WHERE id = ?', (group_id,))
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def assign_account_to_group(self, username: str, group_id: Optional[int]):
|
||||||
|
with self._lock:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
cursor.execute('UPDATE accounts SET group_id = ? WHERE username = ?', (group_id, username))
|
||||||
|
self.conn.commit()
|
||||||
|
|
||||||
|
def get_accounts_by_group(self, group_id: Optional[int]) -> List[Dict]:
|
||||||
|
cursor = self.conn.cursor()
|
||||||
|
if group_id is None:
|
||||||
|
cursor.execute('SELECT * FROM accounts WHERE group_id IS NULL ORDER BY fetch_timestamp DESC')
|
||||||
|
else:
|
||||||
|
cursor.execute('SELECT * FROM accounts WHERE group_id = ? ORDER BY fetch_timestamp DESC', (group_id,))
|
||||||
|
return [dict(row) for row in cursor.fetchall()]
|
||||||
@@ -0,0 +1,307 @@
|
|||||||
|
import sys
|
||||||
|
import os
|
||||||
|
import asyncio
|
||||||
|
import aiohttp
|
||||||
|
import subprocess
|
||||||
|
import imageio_ffmpeg
|
||||||
|
from datetime import datetime
|
||||||
|
from PyQt6.QtCore import QThread, pyqtSignal
|
||||||
|
|
||||||
|
DEFAULT_BATCH_SIZE = 25
|
||||||
|
TIMEOUT_SECONDS_MAC = 60
|
||||||
|
TIMEOUT_SECONDS_DEFAULT = 30
|
||||||
|
BATCH_SLEEP_INTERVAL = 0.1
|
||||||
|
PAUSE_CHECK_INTERVAL = 0.1
|
||||||
|
|
||||||
|
class DownloadWorker(QThread):
|
||||||
|
finished = pyqtSignal(bool, str)
|
||||||
|
progress = pyqtSignal(str, int)
|
||||||
|
conversion_progress = pyqtSignal(str, int)
|
||||||
|
download_progress = pyqtSignal(str, int)
|
||||||
|
|
||||||
|
def __init__(self, accounts, outpath, auth_token, filename_format='username_date',
|
||||||
|
download_batch_size=DEFAULT_BATCH_SIZE, convert_gif=False, gif_resolution='original', gif_conversion_mode='better', db_manager=None):
|
||||||
|
super().__init__()
|
||||||
|
self.accounts = accounts
|
||||||
|
self.outpath = outpath
|
||||||
|
self.auth_token = auth_token
|
||||||
|
self.filename_format = filename_format
|
||||||
|
self.download_batch_size = download_batch_size
|
||||||
|
self.convert_gif = convert_gif
|
||||||
|
self.gif_resolution = gif_resolution
|
||||||
|
self.gif_conversion_mode = gif_conversion_mode
|
||||||
|
self.is_paused = False
|
||||||
|
self.is_stopped = False
|
||||||
|
self.filepath_map = []
|
||||||
|
self.db_manager = db_manager
|
||||||
|
|
||||||
|
async def download_file(self, session, url, filepath, username, tweet_id):
|
||||||
|
try:
|
||||||
|
if self.db_manager and self.db_manager.is_url_downloaded(url):
|
||||||
|
return True, True
|
||||||
|
|
||||||
|
if os.path.exists(filepath):
|
||||||
|
if self.db_manager:
|
||||||
|
file_size = os.path.getsize(filepath)
|
||||||
|
self.db_manager.record_download(url, filepath, username, tweet_id, 'downloaded', file_size)
|
||||||
|
return True, True
|
||||||
|
|
||||||
|
if self.is_stopped:
|
||||||
|
return False, False
|
||||||
|
|
||||||
|
try:
|
||||||
|
os.makedirs(os.path.dirname(filepath), exist_ok=True)
|
||||||
|
except OSError as e:
|
||||||
|
return False, False
|
||||||
|
|
||||||
|
async with session.get(url) as response:
|
||||||
|
if response.status == 200:
|
||||||
|
content = await response.read()
|
||||||
|
|
||||||
|
try:
|
||||||
|
with open(filepath, 'wb') as f:
|
||||||
|
f.write(content)
|
||||||
|
except (IOError, OSError) as e:
|
||||||
|
if self.db_manager:
|
||||||
|
self.db_manager.record_download(url, filepath, username, tweet_id, 'failed', 0)
|
||||||
|
return False, False
|
||||||
|
|
||||||
|
if self.db_manager:
|
||||||
|
self.db_manager.record_download(url, filepath, username, tweet_id, 'downloaded', len(content))
|
||||||
|
|
||||||
|
return True, False
|
||||||
|
return False, False
|
||||||
|
except asyncio.TimeoutError:
|
||||||
|
if self.db_manager:
|
||||||
|
self.db_manager.record_download(url, filepath, username, tweet_id, 'failed', 0)
|
||||||
|
return False, False
|
||||||
|
except aiohttp.ClientError as e:
|
||||||
|
if self.db_manager:
|
||||||
|
self.db_manager.record_download(url, filepath, username, tweet_id, 'failed', 0)
|
||||||
|
return False, False
|
||||||
|
except Exception as e:
|
||||||
|
if self.db_manager:
|
||||||
|
self.db_manager.record_download(url, filepath, username, tweet_id, 'failed', 0)
|
||||||
|
return False, False
|
||||||
|
|
||||||
|
async def download_account_media(self, account):
|
||||||
|
if not account.media_list:
|
||||||
|
return 0, 0, 0
|
||||||
|
|
||||||
|
safe_username = os.path.basename(account.username.replace('/', '_').replace('\\', '_'))
|
||||||
|
account_output_dir = os.path.join(self.outpath, safe_username)
|
||||||
|
os.makedirs(account_output_dir, exist_ok=True)
|
||||||
|
|
||||||
|
timeout_seconds = TIMEOUT_SECONDS_MAC if sys.platform == 'darwin' else TIMEOUT_SECONDS_DEFAULT
|
||||||
|
timeout = aiohttp.ClientTimeout(total=timeout_seconds)
|
||||||
|
connector = aiohttp.TCPConnector(limit=self.download_batch_size)
|
||||||
|
|
||||||
|
async with aiohttp.ClientSession(timeout=timeout, connector=connector) as session:
|
||||||
|
total = len(account.media_list)
|
||||||
|
completed = 0
|
||||||
|
skipped = 0
|
||||||
|
failed = 0
|
||||||
|
|
||||||
|
used_filenames = set()
|
||||||
|
|
||||||
|
for i in range(0, total, self.download_batch_size):
|
||||||
|
if self.is_stopped:
|
||||||
|
break
|
||||||
|
|
||||||
|
while self.is_paused:
|
||||||
|
if self.is_stopped:
|
||||||
|
return completed, skipped, failed
|
||||||
|
await asyncio.sleep(PAUSE_CHECK_INTERVAL)
|
||||||
|
|
||||||
|
batch = account.media_list[i:i + self.download_batch_size]
|
||||||
|
tasks = []
|
||||||
|
|
||||||
|
for item in batch:
|
||||||
|
url = item['url']
|
||||||
|
date = datetime.strptime(item['date'], "%Y-%m-%d %H:%M:%S")
|
||||||
|
formatted_date = date.strftime("%Y%m%d_%H%M%S")
|
||||||
|
tweet_id = str(item.get('tweet_id', ''))
|
||||||
|
|
||||||
|
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'
|
||||||
|
media_output_dir = os.path.join(account_output_dir, media_type_folder)
|
||||||
|
|
||||||
|
if self.filename_format == "username_date":
|
||||||
|
base_filename = f"{safe_username}_{formatted_date}_{tweet_id}"
|
||||||
|
else:
|
||||||
|
base_filename = f"{formatted_date}_{safe_username}_{tweet_id}"
|
||||||
|
|
||||||
|
filename = f"{base_filename}.{extension}"
|
||||||
|
counter = 1
|
||||||
|
while filename in used_filenames:
|
||||||
|
filename = f"{base_filename}_{counter:02d}.{extension}"
|
||||||
|
counter += 1
|
||||||
|
|
||||||
|
used_filenames.add(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, account.username, tweet_id))
|
||||||
|
tasks.append(task)
|
||||||
|
results = await asyncio.gather(*tasks, return_exceptions=True)
|
||||||
|
for result in results:
|
||||||
|
if isinstance(result, tuple):
|
||||||
|
success, was_skipped = result
|
||||||
|
if success:
|
||||||
|
if was_skipped:
|
||||||
|
skipped += 1
|
||||||
|
else:
|
||||||
|
completed += 1
|
||||||
|
else:
|
||||||
|
failed += 1
|
||||||
|
else:
|
||||||
|
failed += 1
|
||||||
|
|
||||||
|
progress_percent = int((completed + skipped + failed) / total * 100)
|
||||||
|
media_type_display = account.media_type if account.media_type != 'all' else 'media'
|
||||||
|
self.download_progress.emit(f"Downloading {account.username}'s {media_type_display}: {completed + skipped + failed:,}/{total:,}", progress_percent)
|
||||||
|
|
||||||
|
await asyncio.sleep(BATCH_SLEEP_INTERVAL)
|
||||||
|
|
||||||
|
return completed, skipped, failed
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
if sys.platform == 'darwin':
|
||||||
|
asyncio.set_event_loop_policy(asyncio.DefaultEventLoopPolicy())
|
||||||
|
|
||||||
|
total_accounts = len(self.accounts)
|
||||||
|
overall_completed = 0
|
||||||
|
overall_skipped = 0
|
||||||
|
overall_failed = 0
|
||||||
|
|
||||||
|
for i, account in enumerate(self.accounts):
|
||||||
|
if self.is_stopped:
|
||||||
|
break
|
||||||
|
|
||||||
|
while self.is_paused:
|
||||||
|
if self.is_stopped:
|
||||||
|
return
|
||||||
|
self.msleep(100)
|
||||||
|
media_type_display = account.media_type if account.media_type != 'all' else 'media'
|
||||||
|
self.progress.emit(f"Downloading from account: {account.username} ({media_type_display}) - ({i+1}/{total_accounts})",
|
||||||
|
int((i) / total_accounts * 100))
|
||||||
|
|
||||||
|
completed, skipped, failed = asyncio.run(self.download_account_media(account))
|
||||||
|
overall_completed += completed
|
||||||
|
overall_skipped += skipped
|
||||||
|
overall_failed += failed
|
||||||
|
self.progress.emit(f"Account {account.username} ({media_type_display}): {completed:,} downloaded, {skipped:,} skipped, {failed:,} failed",
|
||||||
|
int((i + 1) / total_accounts * 100))
|
||||||
|
|
||||||
|
if not self.is_stopped:
|
||||||
|
if self.convert_gif:
|
||||||
|
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:
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
creationflags = subprocess.CREATE_NO_WINDOW
|
||||||
|
else:
|
||||||
|
creationflags = 0
|
||||||
|
|
||||||
|
converted_count = 0
|
||||||
|
skipped_count = 0
|
||||||
|
self.progress.emit("Starting GIF conversion...", 0)
|
||||||
|
|
||||||
|
for idx, (item, fp) in enumerate(gif_items, start=1):
|
||||||
|
if self.is_stopped:
|
||||||
|
break
|
||||||
|
|
||||||
|
while self.is_paused:
|
||||||
|
if self.is_stopped:
|
||||||
|
break
|
||||||
|
self.msleep(100)
|
||||||
|
|
||||||
|
if self.is_stopped:
|
||||||
|
break
|
||||||
|
|
||||||
|
gif_fp = fp.rsplit('.', 1)[0] + '.gif'
|
||||||
|
|
||||||
|
if os.path.exists(gif_fp):
|
||||||
|
try:
|
||||||
|
os.remove(fp)
|
||||||
|
skipped_count += 1
|
||||||
|
conv_progress = int((idx / total_gifs) * 100)
|
||||||
|
quality_display = f"({self.gif_conversion_mode}) - ({self.gif_resolution})"
|
||||||
|
self.conversion_progress.emit(f"Converting GIF {idx:,}/{total_gifs:,} {quality_display} - Skipped (exists)", conv_progress)
|
||||||
|
continue
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
if self.gif_conversion_mode == 'fast':
|
||||||
|
ffmpeg_args = [ffmpeg_exe, '-i', fp, '-y', gif_fp]
|
||||||
|
else:
|
||||||
|
if self.gif_resolution == 'high':
|
||||||
|
ffmpeg_args = [ffmpeg_exe, '-i', fp, '-lavfi', 'scale=800:-1:flags=lanczos,palettegen=stats_mode=full[palette];[0:v]scale=800:-1:flags=lanczos[scaled];[scaled][palette]paletteuse=dither=sierra2_4a', '-r', '15', '-y', gif_fp]
|
||||||
|
elif self.gif_resolution == 'medium':
|
||||||
|
ffmpeg_args = [ffmpeg_exe, '-i', fp, '-lavfi', 'scale=600:-1:flags=lanczos,palettegen=stats_mode=full[palette];[0:v]scale=600:-1:flags=lanczos[scaled];[scaled][palette]paletteuse=dither=sierra2_4a', '-r', '10', '-y', gif_fp]
|
||||||
|
elif self.gif_resolution == 'low':
|
||||||
|
ffmpeg_args = [ffmpeg_exe, '-i', fp, '-lavfi', 'scale=400:-1:flags=lanczos,palettegen=stats_mode=full[palette];[0:v]scale=400:-1:flags=lanczos[scaled];[scaled][palette]paletteuse=dither=sierra2_4a', '-r', '8', '-y', gif_fp]
|
||||||
|
else:
|
||||||
|
ffmpeg_args = [ffmpeg_exe, '-i', fp, '-lavfi', 'palettegen=stats_mode=full[palette];[0:v][palette]paletteuse=dither=sierra2_4a', '-y', gif_fp]
|
||||||
|
|
||||||
|
try:
|
||||||
|
if sys.platform == 'win32':
|
||||||
|
result = subprocess.run(ffmpeg_args, capture_output=True, creationflags=creationflags)
|
||||||
|
else:
|
||||||
|
result = subprocess.run(ffmpeg_args, capture_output=True, stderr=subprocess.PIPE, stdout=subprocess.PIPE)
|
||||||
|
|
||||||
|
if result.returncode == 0 and os.path.exists(gif_fp):
|
||||||
|
try:
|
||||||
|
os.remove(fp)
|
||||||
|
converted_count += 1
|
||||||
|
except Exception:
|
||||||
|
pass
|
||||||
|
elif result.returncode != 0:
|
||||||
|
error_msg = result.stderr.decode('utf-8', errors='ignore') if result.stderr else 'Unknown error'
|
||||||
|
self.progress.emit(f"GIF conversion warning for file {idx}: {error_msg[:100]}", 0)
|
||||||
|
except Exception as e:
|
||||||
|
self.progress.emit(f"GIF conversion error for file {idx}: {str(e)[:100]}", 0)
|
||||||
|
|
||||||
|
conv_progress = int((idx / total_gifs) * 100)
|
||||||
|
quality_display = f"({self.gif_conversion_mode}) - ({self.gif_resolution})"
|
||||||
|
self.conversion_progress.emit(f"Converting GIF {idx:,}/{total_gifs:,} {quality_display}", conv_progress)
|
||||||
|
if converted_count > 0 or skipped_count > 0:
|
||||||
|
completion_msg = f"GIF conversion completed: {converted_count:,} converted"
|
||||||
|
if skipped_count > 0:
|
||||||
|
completion_msg += f", {skipped_count:,} skipped (already exists)"
|
||||||
|
self.progress.emit(completion_msg, 100)
|
||||||
|
else:
|
||||||
|
self.progress.emit("GIF conversion completed", 100)
|
||||||
|
except Exception as conv_e:
|
||||||
|
self.progress.emit(f"GIF conversion error: {conv_e}", 0)
|
||||||
|
|
||||||
|
success_message = f"Download completed! {overall_completed:,} files downloaded"
|
||||||
|
if overall_skipped > 0:
|
||||||
|
success_message += f", {overall_skipped:,} skipped"
|
||||||
|
if overall_failed > 0:
|
||||||
|
success_message += f", {overall_failed:,} failed"
|
||||||
|
self.finished.emit(True, success_message)
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
self.finished.emit(False, str(e))
|
||||||
|
|
||||||
|
def pause(self):
|
||||||
|
self.is_paused = True
|
||||||
|
|
||||||
|
def resume(self):
|
||||||
|
self.is_paused = False
|
||||||
|
|
||||||
|
def stop(self):
|
||||||
|
self.is_stopped = True
|
||||||
|
self.is_paused = False
|
||||||
@@ -0,0 +1,329 @@
|
|||||||
|
import re
|
||||||
|
import json
|
||||||
|
from datetime import datetime
|
||||||
|
from gallery_dl.extractor import twitter
|
||||||
|
|
||||||
|
def get_metadata_by_date(username, auth_token, date_start, date_end, media_filter="filter:media", output_file=None):
|
||||||
|
query = f"from:{username} since:{date_start} until:{date_end}"
|
||||||
|
if media_filter:
|
||||||
|
query += f" {media_filter}"
|
||||||
|
|
||||||
|
url = f"https://x.com/search?q={query}"
|
||||||
|
|
||||||
|
extractor_class = twitter.TwitterSearchExtractor
|
||||||
|
match = re.match(extractor_class.pattern, url)
|
||||||
|
|
||||||
|
if not match:
|
||||||
|
raise ValueError(f"Invalid search URL: {url}")
|
||||||
|
|
||||||
|
extractor = extractor_class(match)
|
||||||
|
|
||||||
|
config_dict = {
|
||||||
|
"cookies": {
|
||||||
|
"auth_token": auth_token
|
||||||
|
},
|
||||||
|
"retweets": False
|
||||||
|
}
|
||||||
|
|
||||||
|
extractor.config = lambda key, default=None: config_dict.get(key, default)
|
||||||
|
|
||||||
|
try:
|
||||||
|
extractor.initialize()
|
||||||
|
|
||||||
|
api = twitter.TwitterAPI(extractor)
|
||||||
|
|
||||||
|
try:
|
||||||
|
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
|
||||||
|
|
||||||
|
user_data = extractor._transform_user(user)
|
||||||
|
|
||||||
|
structured_output = {
|
||||||
|
'account_info': {
|
||||||
|
'name': user_data.get('name', ''),
|
||||||
|
'nick': user_data.get('nick', ''),
|
||||||
|
'date': user_data.get('date', ''),
|
||||||
|
'followers_count': user_data.get('followers_count', 0),
|
||||||
|
'friends_count': user_data.get('friends_count', 0),
|
||||||
|
'profile_image': user_data.get('profile_image', ''),
|
||||||
|
'statuses_count': user_data.get('statuses_count', 0)
|
||||||
|
},
|
||||||
|
'total_urls': 0,
|
||||||
|
'timeline': [],
|
||||||
|
'search_query': query,
|
||||||
|
'date_filter': {
|
||||||
|
'start': date_start,
|
||||||
|
'end': date_end,
|
||||||
|
'method': 'search_api'
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if isinstance(structured_output['account_info']['date'], datetime):
|
||||||
|
structured_output['account_info']['date'] = structured_output['account_info']['date'].strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
new_timeline_entries = []
|
||||||
|
|
||||||
|
try:
|
||||||
|
iterator = iter(extractor)
|
||||||
|
|
||||||
|
while True:
|
||||||
|
try:
|
||||||
|
item = next(iterator)
|
||||||
|
|
||||||
|
if isinstance(item, tuple) and len(item) >= 3:
|
||||||
|
media_url = item[1]
|
||||||
|
tweet_data = item[2]
|
||||||
|
|
||||||
|
if 'pbs.twimg.com' in media_url or 'video.twimg.com' in media_url:
|
||||||
|
tweet_date = tweet_data.get('date', datetime.now())
|
||||||
|
if isinstance(tweet_date, datetime):
|
||||||
|
tweet_date = tweet_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
timeline_entry = {
|
||||||
|
'url': media_url,
|
||||||
|
'date': tweet_date,
|
||||||
|
'tweet_id': tweet_data.get('tweet_id', 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
if 'type' in tweet_data:
|
||||||
|
timeline_entry['type'] = tweet_data['type']
|
||||||
|
|
||||||
|
if 'retweet_id' in tweet_data and tweet_data['retweet_id']:
|
||||||
|
timeline_entry['retweet_id'] = tweet_data['retweet_id']
|
||||||
|
timeline_entry['is_retweet'] = True
|
||||||
|
else:
|
||||||
|
timeline_entry['is_retweet'] = False
|
||||||
|
|
||||||
|
new_timeline_entries.append(timeline_entry)
|
||||||
|
structured_output['total_urls'] += 1
|
||||||
|
|
||||||
|
except StopIteration:
|
||||||
|
break
|
||||||
|
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
structured_output['timeline'] = new_timeline_entries
|
||||||
|
|
||||||
|
structured_output['metadata'] = {
|
||||||
|
"new_entries": len(new_timeline_entries),
|
||||||
|
"method": "search_api",
|
||||||
|
"date_range": f"{date_start} to {date_end}"
|
||||||
|
}
|
||||||
|
|
||||||
|
if output_file:
|
||||||
|
try:
|
||||||
|
with open(output_file, 'w', encoding='utf-8') as f:
|
||||||
|
json.dump(structured_output, f, ensure_ascii=False, indent=2)
|
||||||
|
except Exception as e:
|
||||||
|
pass
|
||||||
|
|
||||||
|
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": "To download withheld accounts, use this userscript version: https://www.patreon.com/exyezed"}
|
||||||
|
else:
|
||||||
|
error_str = str(e)
|
||||||
|
if error_str == "None":
|
||||||
|
return {"error": "Failed to authenticate. Please verify your auth token is valid and not expired."}
|
||||||
|
else:
|
||||||
|
return {"error": error_str}
|
||||||
|
|
||||||
|
def get_metadata(username, auth_token, timeline_type="timeline", batch_size=0, page=0, media_type="all", retweets=False):
|
||||||
|
url = f"https://x.com/{username}/{timeline_type}"
|
||||||
|
|
||||||
|
if timeline_type == "media":
|
||||||
|
extractor_class = twitter.TwitterMediaExtractor
|
||||||
|
elif timeline_type == "tweets":
|
||||||
|
extractor_class = twitter.TwitterTweetsExtractor
|
||||||
|
elif timeline_type == "with_replies":
|
||||||
|
extractor_class = twitter.TwitterRepliesExtractor
|
||||||
|
else:
|
||||||
|
extractor_class = twitter.TwitterTimelineExtractor
|
||||||
|
|
||||||
|
match = re.match(extractor_class.pattern, url)
|
||||||
|
if not match:
|
||||||
|
raise ValueError(f"Invalid URL for {timeline_type}: {url}")
|
||||||
|
|
||||||
|
extractor = extractor_class(match)
|
||||||
|
|
||||||
|
config_dict = {
|
||||||
|
"cookies": {
|
||||||
|
"auth_token": auth_token
|
||||||
|
},
|
||||||
|
"retweets": retweets
|
||||||
|
}
|
||||||
|
|
||||||
|
if batch_size > 0:
|
||||||
|
config_dict["count"] = batch_size
|
||||||
|
|
||||||
|
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,
|
||||||
|
'timeline': []
|
||||||
|
}
|
||||||
|
|
||||||
|
iterator = iter(extractor)
|
||||||
|
|
||||||
|
if batch_size > 0 and page > 0:
|
||||||
|
items_to_skip = page * batch_size
|
||||||
|
|
||||||
|
if hasattr(extractor, '_cursor') and extractor._cursor:
|
||||||
|
pass
|
||||||
|
else:
|
||||||
|
skipped = 0
|
||||||
|
try:
|
||||||
|
for _ in range(items_to_skip):
|
||||||
|
next(iterator)
|
||||||
|
skipped += 1
|
||||||
|
except StopIteration:
|
||||||
|
pass
|
||||||
|
|
||||||
|
new_timeline_entries = []
|
||||||
|
|
||||||
|
items_to_fetch = batch_size if batch_size > 0 else float('inf')
|
||||||
|
items_fetched = 0
|
||||||
|
|
||||||
|
try:
|
||||||
|
while items_fetched < items_to_fetch:
|
||||||
|
item = next(iterator)
|
||||||
|
items_fetched += 1
|
||||||
|
|
||||||
|
if isinstance(item, tuple) and len(item) >= 3:
|
||||||
|
media_url = item[1]
|
||||||
|
tweet_data = item[2]
|
||||||
|
|
||||||
|
if not structured_output['account_info'] and '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")
|
||||||
|
|
||||||
|
structured_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)
|
||||||
|
}
|
||||||
|
|
||||||
|
if 'pbs.twimg.com' in media_url or 'video.twimg.com' in media_url:
|
||||||
|
tweet_date = tweet_data.get('date', datetime.now())
|
||||||
|
if isinstance(tweet_date, datetime):
|
||||||
|
tweet_date = tweet_date.strftime("%Y-%m-%d %H:%M:%S")
|
||||||
|
|
||||||
|
timeline_entry = {
|
||||||
|
'url': media_url,
|
||||||
|
'date': tweet_date,
|
||||||
|
'tweet_id': tweet_data.get('tweet_id', 0),
|
||||||
|
}
|
||||||
|
|
||||||
|
if 'type' in tweet_data:
|
||||||
|
timeline_entry['type'] = tweet_data['type']
|
||||||
|
|
||||||
|
if 'retweet_id' in tweet_data and tweet_data['retweet_id']:
|
||||||
|
timeline_entry['retweet_id'] = tweet_data['retweet_id']
|
||||||
|
timeline_entry['is_retweet'] = True
|
||||||
|
else:
|
||||||
|
timeline_entry['is_retweet'] = False
|
||||||
|
|
||||||
|
if media_type == 'all' or (
|
||||||
|
(media_type == 'image' and 'pbs.twimg.com' in media_url and tweet_data.get('type') == 'photo') or
|
||||||
|
(media_type == 'video' and 'video.twimg.com' in media_url and tweet_data.get('type') == 'video') or
|
||||||
|
(media_type == 'gif' and 'video.twimg.com' in media_url and tweet_data.get('type') == 'animated_gif')
|
||||||
|
):
|
||||||
|
new_timeline_entries.append(timeline_entry)
|
||||||
|
structured_output['total_urls'] += 1
|
||||||
|
except StopIteration:
|
||||||
|
pass
|
||||||
|
|
||||||
|
structured_output['timeline'].extend(new_timeline_entries)
|
||||||
|
|
||||||
|
cursor_info = None
|
||||||
|
if hasattr(extractor, '_cursor') and extractor._cursor:
|
||||||
|
cursor_info = extractor._cursor
|
||||||
|
|
||||||
|
structured_output['metadata'] = {
|
||||||
|
"new_entries": len(new_timeline_entries),
|
||||||
|
"page": page,
|
||||||
|
"batch_size": batch_size,
|
||||||
|
"has_more": batch_size > 0 and items_fetched == batch_size,
|
||||||
|
"cursor": cursor_info
|
||||||
|
}
|
||||||
|
|
||||||
|
if not structured_output['account_info']:
|
||||||
|
raise ValueError("Failed to fetch account information. Please check the username and auth token.")
|
||||||
|
|
||||||
|
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": "To download withheld accounts, use this userscript version: https://www.patreon.com/exyezed"}
|
||||||
|
else:
|
||||||
|
error_str = str(e)
|
||||||
|
if error_str == "None":
|
||||||
|
return {"error": "Failed to authenticate. Please verify your auth token is valid and not expired."}
|
||||||
|
else:
|
||||||
|
return {"error": error_str}
|
||||||
|
|
||||||
|
def main():
|
||||||
|
username = ""
|
||||||
|
auth_token = ""
|
||||||
|
timeline_type = "media"
|
||||||
|
batch_size = 100
|
||||||
|
page = 0
|
||||||
|
media_type = "all"
|
||||||
|
|
||||||
|
try:
|
||||||
|
data = get_metadata(
|
||||||
|
username=username,
|
||||||
|
auth_token=auth_token,
|
||||||
|
timeline_type=timeline_type,
|
||||||
|
batch_size=batch_size,
|
||||||
|
page=page,
|
||||||
|
media_type=media_type
|
||||||
|
)
|
||||||
|
print(json.dumps(data, ensure_ascii=False, indent=2))
|
||||||
|
except Exception as e:
|
||||||
|
error_str = str(e)
|
||||||
|
if error_str == "None":
|
||||||
|
print(json.dumps({"error": "Failed to authenticate. Please verify your auth token is valid and not expired."}, ensure_ascii=False))
|
||||||
|
else:
|
||||||
|
print(json.dumps({"error": error_str}, ensure_ascii=False))
|
||||||
|
|
||||||
|
if __name__ == '__main__':
|
||||||
|
main()
|
||||||
@@ -0,0 +1,60 @@
|
|||||||
|
from PyQt6.QtCore import QThread, pyqtSignal
|
||||||
|
from core.metadataFetcher import get_metadata, get_metadata_by_date
|
||||||
|
|
||||||
|
class MetadataFetchWorker(QThread):
|
||||||
|
finished = pyqtSignal(dict)
|
||||||
|
error = pyqtSignal(str)
|
||||||
|
|
||||||
|
def __init__(self, username, media_type='all', batch_mode=False, batch_size=0, page=0, timeline_type='media', include_retweets=False, use_date_range=False, date_start=None, date_end=None):
|
||||||
|
super().__init__()
|
||||||
|
self.username = username
|
||||||
|
self.media_type = media_type
|
||||||
|
self.batch_mode = batch_mode
|
||||||
|
self.batch_size = batch_size
|
||||||
|
self.page = page
|
||||||
|
self.timeline_type = timeline_type
|
||||||
|
self.include_retweets = include_retweets
|
||||||
|
self.use_date_range = use_date_range
|
||||||
|
self.date_start = date_start
|
||||||
|
self.date_end = date_end
|
||||||
|
self.auth_token = None
|
||||||
|
|
||||||
|
def normalize_url(self, url_or_username):
|
||||||
|
url_or_username = url_or_username.strip()
|
||||||
|
username = url_or_username
|
||||||
|
|
||||||
|
if "x.com/" in url_or_username or "twitter.com/" in url_or_username:
|
||||||
|
parts = url_or_username.split('/')
|
||||||
|
for i, part in enumerate(parts):
|
||||||
|
if part in ['x.com', 'twitter.com'] and i + 1 < len(parts):
|
||||||
|
username = parts[i + 1]
|
||||||
|
username = username.split('/')[0]
|
||||||
|
break
|
||||||
|
|
||||||
|
username = username.strip()
|
||||||
|
return username
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
try:
|
||||||
|
normalized = self.normalize_url(self.username)
|
||||||
|
if self.use_date_range and self.date_start and self.date_end:
|
||||||
|
data = get_metadata_by_date(
|
||||||
|
username=normalized,
|
||||||
|
auth_token=self.auth_token,
|
||||||
|
date_start=self.date_start,
|
||||||
|
date_end=self.date_end,
|
||||||
|
media_filter="filter:media" if self.media_type == 'all' else f"filter:{self.media_type}"
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
data = get_metadata(
|
||||||
|
username=normalized,
|
||||||
|
auth_token=self.auth_token,
|
||||||
|
timeline_type=self.timeline_type,
|
||||||
|
batch_size=self.batch_size if self.batch_mode else 0,
|
||||||
|
page=self.page,
|
||||||
|
media_type=self.media_type,
|
||||||
|
retweets=self.include_retweets
|
||||||
|
)
|
||||||
|
self.finished.emit(data)
|
||||||
|
except Exception as e:
|
||||||
|
self.error.emit(str(e))
|
||||||
@@ -0,0 +1,8 @@
|
|||||||
|
PyQt6==6.9.1
|
||||||
|
requests
|
||||||
|
aiohttp
|
||||||
|
imageio-ffmpeg
|
||||||
|
packaging
|
||||||
|
gallery-dl
|
||||||
|
pyqtdarktheme
|
||||||
|
pyinstaller
|
||||||
@@ -0,0 +1,7 @@
|
|||||||
|
from ui.mainWindow import TwitterXMediaBatchDownloaderGUI
|
||||||
|
from ui.dialogs import UpdateDialog
|
||||||
|
|
||||||
|
__all__ = [
|
||||||
|
'TwitterXMediaBatchDownloaderGUI',
|
||||||
|
'UpdateDialog'
|
||||||
|
]
|
||||||
@@ -0,0 +1,33 @@
|
|||||||
|
from PyQt6.QtWidgets import (
|
||||||
|
QDialog, QVBoxLayout, QLabel, QPushButton, QDialogButtonBox
|
||||||
|
)
|
||||||
|
from PyQt6.QtCore import Qt
|
||||||
|
|
||||||
|
class UpdateDialog(QDialog):
|
||||||
|
def __init__(self, current_version, new_version, parent=None):
|
||||||
|
super().__init__(parent)
|
||||||
|
self.setWindowTitle("Update Now")
|
||||||
|
self.setFixedWidth(400)
|
||||||
|
self.setModal(True)
|
||||||
|
|
||||||
|
layout = QVBoxLayout()
|
||||||
|
|
||||||
|
message = QLabel(f"Twitter/X Media Batch Downloader v{new_version} Available!")
|
||||||
|
message.setWordWrap(True)
|
||||||
|
layout.addWidget(message)
|
||||||
|
|
||||||
|
button_box = QDialogButtonBox()
|
||||||
|
self.update_button = QPushButton("Check")
|
||||||
|
self.update_button.setCursor(Qt.CursorShape.PointingHandCursor)
|
||||||
|
self.cancel_button = QPushButton("Later")
|
||||||
|
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)
|
||||||
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-cancel"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M3 12a9 9 0 1 0 18 0a9 9 0 1 0 -18 0" /><path d="M18.364 5.636l-12.728 12.728" /></svg>
|
||||||
|
After Width: | Height: | Size: 396 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-database-export"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 6c0 1.657 3.582 3 8 3s8 -1.343 8 -3s-3.582 -3 -8 -3s-8 1.343 -8 3" /><path d="M4 6v6c0 1.657 3.582 3 8 3c1.118 0 2.183 -.086 3.15 -.241" /><path d="M20 12v-6" /><path d="M4 12v6c0 1.657 3.582 3 8 3c.157 0 .312 -.002 .466 -.005" /><path d="M16 19h6" /><path d="M19 16l3 3l-3 3" /></svg>
|
||||||
|
After Width: | Height: | Size: 616 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-database-import"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 6c0 1.657 3.582 3 8 3s8 -1.343 8 -3s-3.582 -3 -8 -3s-8 1.343 -8 3" /><path d="M4 6v6c0 1.657 3.582 3 8 3c.856 0 1.68 -.05 2.454 -.144m5.546 -2.856v-6" /><path d="M4 12v6c0 1.657 3.582 3 8 3c.171 0 .341 -.002 .51 -.006" /><path d="M19 22v-6" /><path d="M22 19l-3 -3l-3 3" /></svg>
|
||||||
|
After Width: | Height: | Size: 610 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-device-floppy"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 4h10l4 4v10a2 2 0 0 1 -2 2h-12a2 2 0 0 1 -2 -2v-12a2 2 0 0 1 2 -2" /><path d="M12 14m-2 0a2 2 0 1 0 4 0a2 2 0 1 0 -4 0" /><path d="M14 4l0 4l-6 0l0 -4" /></svg>
|
||||||
|
After Width: | Height: | Size: 479 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-download"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 17v2a2 2 0 0 0 2 2h12a2 2 0 0 0 2 -2v-2" /><path d="M7 11l5 5l5 -5" /><path d="M12 4l0 12" /></svg>
|
||||||
|
After Width: | Height: | Size: 423 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-edit"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 7h-1a2 2 0 0 0 -2 2v9a2 2 0 0 0 2 2h9a2 2 0 0 0 2 -2v-1" /><path d="M20.385 6.585a2.1 2.1 0 0 0 -2.97 -2.97l-8.415 8.385v3h3l8.385 -8.415z" /><path d="M16 5l3 3" /></svg>
|
||||||
|
After Width: | Height: | Size: 480 B |
|
After Width: | Height: | Size: 173 KiB |
@@ -1,11 +1,11 @@
|
|||||||
<?xml version="1.0" ?>
|
<?xml version="1.0" ?>
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
|
<svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" version="1.1"
|
||||||
id="Layer_1" width="512px" height="512px" viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;"
|
id="Layer_1" width="512px" height="512px" viewBox="0 0 24 24" style="enable-background:new 0 0 24 24;"
|
||||||
xml:space="preserve">
|
xml:space="preserve">
|
||||||
<g fill="#1da0f1">
|
<g fill="#1da0f1">
|
||||||
<polygon
|
<polygon
|
||||||
points="12.153992,10.729553 8.088684,5.041199 5.92041,5.041199 10.956299,12.087097 11.59021,12.97345 15.900635,19.009583 18.068909,19.009583 12.785217,11.615906 " />
|
points="12.153992,10.729553 8.088684,5.041199 5.92041,5.041199 10.956299,12.087097 11.59021,12.97345 15.900635,19.009583 18.068909,19.009583 12.785217,11.615906 " />
|
||||||
<path
|
<path
|
||||||
d="M21.15979,1H2.84021C1.823853,1,1,1.823853,1,2.84021v18.31958C1,22.176147,1.823853,23,2.84021,23h18.31958 C22.176147,23,23,22.176147,23,21.15979V2.84021C23,1.823853,22.176147,1,21.15979,1z M15.235352,20l-4.362549-6.213013 L5.411438,20H4l6.246887-7.104675L4,4h4.764648l4.130127,5.881958L18.06958,4h1.411377l-5.95697,6.775635L20,20H15.235352z" />
|
d="M21.15979,1H2.84021C1.823853,1,1,1.823853,1,2.84021v18.31958C1,22.176147,1.823853,23,2.84021,23h18.31958 C22.176147,23,23,22.176147,23,21.15979V2.84021C23,1.823853,22.176147,1,21.15979,1z M15.235352,20l-4.362549-6.213013 L5.411438,20H4l6.246887-7.104675L4,4h4.764648l4.130127,5.881958L18.06958,4h1.411377l-5.95697,6.775635L20,20H15.235352z" />
|
||||||
</g>
|
</g>
|
||||||
</svg>
|
</svg>
|
||||||
|
Before Width: | Height: | Size: 876 B After Width: | Height: | Size: 865 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-player-pause"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M6 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z" /><path d="M14 5m0 1a1 1 0 0 1 1 -1h2a1 1 0 0 1 1 1v12a1 1 0 0 1 -1 1h-2a1 1 0 0 1 -1 -1z" /></svg>
|
||||||
|
After Width: | Height: | Size: 493 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-player-play"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M7 4v16l13 -8z" /></svg>
|
||||||
|
After Width: | Height: | Size: 338 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-reload"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M19.933 13.041a8 8 0 1 1 -9.925 -8.788c3.899 -1 7.935 1.007 9.425 4.747" /><path d="M20 4v5h-5" /></svg>
|
||||||
|
After Width: | Height: | Size: 423 B |
@@ -0,0 +1 @@
|
|||||||
|
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="1.25" stroke-linecap="round" stroke-linejoin="round" class="icon icon-tabler icons-tabler-outline icon-tabler-trash"><path stroke="none" d="M0 0h24v24H0z" fill="none"/><path d="M4 7l16 0" /><path d="M10 11l0 6" /><path d="M14 11l0 6" /><path d="M5 7l1 12a2 2 0 0 0 2 2h8a2 2 0 0 0 2 -2l1 -12" /><path d="M9 7v-3a1 1 0 0 1 1 -1h4a1 1 0 0 1 1 1v3" /></svg>
|
||||||
|
After Width: | Height: | Size: 495 B |
@@ -0,0 +1,267 @@
|
|||||||
|
import os
|
||||||
|
from PyQt6.QtWidgets import QApplication, QLabel
|
||||||
|
from PyQt6.QtCore import Qt, QSize, QEvent
|
||||||
|
from PyQt6.QtGui import QIcon, QPalette, QColor
|
||||||
|
from ui.mainWindow import TwitterXMediaBatchDownloaderGUI
|
||||||
|
|
||||||
|
class TwitterXMediaBatchDownloaderGUI_Unix(TwitterXMediaBatchDownloaderGUI):
|
||||||
|
def __init__(self):
|
||||||
|
super().__init__()
|
||||||
|
self.setup_unix_specific()
|
||||||
|
|
||||||
|
QApplication.instance().installEventFilter(self)
|
||||||
|
|
||||||
|
def eventFilter(self, obj, event):
|
||||||
|
if event.type() == QEvent.Type.ApplicationPaletteChange:
|
||||||
|
self.update_button_icons_unix()
|
||||||
|
self.update_ui_colors()
|
||||||
|
return super().eventFilter(obj, event)
|
||||||
|
|
||||||
|
def update_ui_colors(self):
|
||||||
|
from PyQt6.QtWidgets import QLineEdit, QTextEdit, QComboBox, QCheckBox, QPushButton, QProgressBar, QDateEdit, QListWidget, QTabWidget
|
||||||
|
|
||||||
|
new_palette = QApplication.palette()
|
||||||
|
|
||||||
|
self.account_list.setStyleSheet("""
|
||||||
|
QListWidget {
|
||||||
|
background-color: palette(base);
|
||||||
|
padding: 4px;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
QListWidget::item {
|
||||||
|
padding: 3px 6px;
|
||||||
|
margin: 0px 0px;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
QListWidget::item:selected {
|
||||||
|
background-color: palette(highlight);
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
QListWidget::item:focus {
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
QListWidget::item:hover {
|
||||||
|
background-color: palette(highlight);
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
|
||||||
|
widget_types = [QLabel, QLineEdit, QTextEdit, QComboBox, QCheckBox, QPushButton, QProgressBar, QDateEdit, QListWidget, QTabWidget]
|
||||||
|
|
||||||
|
for widget_type in widget_types:
|
||||||
|
for widget in self.findChildren(widget_type):
|
||||||
|
widget.setPalette(new_palette)
|
||||||
|
widget.update()
|
||||||
|
|
||||||
|
for i in range(self.account_list.count()):
|
||||||
|
item = self.account_list.item(i)
|
||||||
|
if item:
|
||||||
|
self.account_list.update(self.account_list.indexFromItem(item))
|
||||||
|
|
||||||
|
self.setPalette(new_palette)
|
||||||
|
self.update()
|
||||||
|
|
||||||
|
def setup_unix_specific(self):
|
||||||
|
self.setFixedWidth(670)
|
||||||
|
|
||||||
|
if hasattr(self, 'fetch_btn'):
|
||||||
|
self.fetch_btn.setFixedWidth(100)
|
||||||
|
|
||||||
|
if hasattr(self, 'start_date_edit'):
|
||||||
|
self.start_date_edit.setMinimumWidth(130)
|
||||||
|
|
||||||
|
if hasattr(self, 'end_date_edit'):
|
||||||
|
self.end_date_edit.setMinimumWidth(130)
|
||||||
|
|
||||||
|
if hasattr(self, 'output_browse'):
|
||||||
|
self.output_browse.setFixedWidth(100)
|
||||||
|
|
||||||
|
self.account_list.setStyleSheet("""
|
||||||
|
QListWidget {
|
||||||
|
background-color: palette(base);
|
||||||
|
padding: 4px;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
QListWidget::item {
|
||||||
|
padding: 3px 6px;
|
||||||
|
margin: 0px 0px;
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
QListWidget::item:selected {
|
||||||
|
background-color: palette(highlight);
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
QListWidget::item:focus {
|
||||||
|
border: none;
|
||||||
|
outline: none;
|
||||||
|
}
|
||||||
|
QListWidget::item:hover {
|
||||||
|
background-color: palette(highlight);
|
||||||
|
}
|
||||||
|
""")
|
||||||
|
|
||||||
|
self.update_button_icons_unix()
|
||||||
|
|
||||||
|
def create_colored_icon(self, icon_path, color=None):
|
||||||
|
if not os.path.exists(icon_path):
|
||||||
|
return QIcon()
|
||||||
|
|
||||||
|
palette = QApplication.palette()
|
||||||
|
text_color = palette.color(QPalette.ColorRole.Text)
|
||||||
|
color_hex = text_color.name()
|
||||||
|
|
||||||
|
from PyQt6.QtSvg import QSvgRenderer
|
||||||
|
from PyQt6.QtGui import QPixmap, QPainter
|
||||||
|
|
||||||
|
renderer = QSvgRenderer(icon_path)
|
||||||
|
pixmap = QPixmap(24, 24)
|
||||||
|
pixmap.fill(Qt.GlobalColor.transparent)
|
||||||
|
|
||||||
|
painter = QPainter(pixmap)
|
||||||
|
renderer.render(painter)
|
||||||
|
painter.setCompositionMode(QPainter.CompositionMode.CompositionMode_SourceIn)
|
||||||
|
painter.fillRect(pixmap.rect(), QColor(color_hex))
|
||||||
|
painter.end()
|
||||||
|
|
||||||
|
return QIcon(pixmap)
|
||||||
|
|
||||||
|
def update_button_icons(self):
|
||||||
|
self.update_button_icons_unix()
|
||||||
|
|
||||||
|
def update_button_icons_unix_dashboard(self):
|
||||||
|
if not hasattr(self, 'import_btn'):
|
||||||
|
return
|
||||||
|
|
||||||
|
icon_dir = os.path.join(os.path.dirname(__file__), 'icons')
|
||||||
|
|
||||||
|
self.import_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'database-import.svg')))
|
||||||
|
self.export_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'database-export.svg')))
|
||||||
|
self.download_selected_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'download.svg')))
|
||||||
|
self.update_selected_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'reload.svg')))
|
||||||
|
self.delete_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'trash.svg')))
|
||||||
|
|
||||||
|
def update_button_icons_unix(self):
|
||||||
|
self.update_button_icons_unix_dashboard()
|
||||||
|
|
||||||
|
icon_dir = os.path.join(os.path.dirname(__file__), 'icons')
|
||||||
|
|
||||||
|
if hasattr(self, 'stop_btn'):
|
||||||
|
self.stop_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'cancel.svg')))
|
||||||
|
if hasattr(self, 'pause_resume_btn'):
|
||||||
|
if self.pause_resume_btn.text() == ' Resume':
|
||||||
|
self.pause_resume_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-play.svg')))
|
||||||
|
else:
|
||||||
|
self.pause_resume_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-pause.svg')))
|
||||||
|
if hasattr(self, 'stop_fetch_btn'):
|
||||||
|
self.stop_fetch_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'cancel.svg')))
|
||||||
|
if hasattr(self, 'pause_fetch_btn'):
|
||||||
|
if self.pause_fetch_btn.text() == ' Resume':
|
||||||
|
self.pause_fetch_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-play.svg')))
|
||||||
|
else:
|
||||||
|
self.pause_fetch_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-pause.svg')))
|
||||||
|
|
||||||
|
def setup_theme_tab(self):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def change_theme_color(self, color, clicked_btn=None):
|
||||||
|
pass
|
||||||
|
|
||||||
|
def toggle_pause_resume(self):
|
||||||
|
if hasattr(self, 'worker'):
|
||||||
|
icon_dir = os.path.join(os.path.dirname(__file__), 'icons')
|
||||||
|
|
||||||
|
if self.worker.is_paused:
|
||||||
|
self.worker.resume()
|
||||||
|
self.pause_resume_btn.setText(' Pause')
|
||||||
|
self.pause_resume_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-pause.svg')))
|
||||||
|
self.timer.start(1000)
|
||||||
|
else:
|
||||||
|
self.worker.pause()
|
||||||
|
self.pause_resume_btn.setText(' Resume')
|
||||||
|
self.pause_resume_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-play.svg')))
|
||||||
|
|
||||||
|
def pause_batch_fetch(self):
|
||||||
|
self.is_auto_fetching = False
|
||||||
|
|
||||||
|
if hasattr(self, 'metadata_worker') and self.metadata_worker.isRunning():
|
||||||
|
self.metadata_worker.terminate()
|
||||||
|
self.metadata_worker.wait()
|
||||||
|
|
||||||
|
icon_dir = os.path.join(os.path.dirname(__file__), 'icons')
|
||||||
|
self.pause_fetch_btn.setText(' Resume')
|
||||||
|
self.pause_fetch_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-play.svg')))
|
||||||
|
self.pause_fetch_btn.clicked.disconnect()
|
||||||
|
self.pause_fetch_btn.clicked.connect(self.resume_batch_fetch)
|
||||||
|
self.log_output.append('Batch fetching paused.')
|
||||||
|
|
||||||
|
def resume_batch_fetch(self):
|
||||||
|
self.is_auto_fetching = True
|
||||||
|
icon_dir = os.path.join(os.path.dirname(__file__), 'icons')
|
||||||
|
self.pause_fetch_btn.setText(' Pause')
|
||||||
|
self.pause_fetch_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-pause.svg')))
|
||||||
|
self.pause_fetch_btn.clicked.disconnect()
|
||||||
|
self.pause_fetch_btn.clicked.connect(self.pause_batch_fetch)
|
||||||
|
self.log_output.append('Resuming batch fetching...')
|
||||||
|
|
||||||
|
if hasattr(self, 'is_multiple_user_mode') and self.is_multiple_user_mode:
|
||||||
|
self.fetch_next_account_in_batch()
|
||||||
|
else:
|
||||||
|
self.fetch_next_batch_internal()
|
||||||
|
|
||||||
|
def stop_batch_fetch(self):
|
||||||
|
self.is_auto_fetching = False
|
||||||
|
self.pause_fetch_btn.hide()
|
||||||
|
self.stop_fetch_btn.hide()
|
||||||
|
|
||||||
|
if hasattr(self, 'metadata_worker') and self.metadata_worker.isRunning():
|
||||||
|
self.metadata_worker.terminate()
|
||||||
|
self.metadata_worker.wait()
|
||||||
|
|
||||||
|
if self.pause_fetch_btn.text() == ' Resume':
|
||||||
|
icon_dir = os.path.join(os.path.dirname(__file__), 'icons')
|
||||||
|
self.pause_fetch_btn.setText(' Pause')
|
||||||
|
self.pause_fetch_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-pause.svg')))
|
||||||
|
self.pause_fetch_btn.clicked.disconnect()
|
||||||
|
self.pause_fetch_btn.clicked.connect(self.pause_batch_fetch)
|
||||||
|
|
||||||
|
if hasattr(self, 'is_multiple_user_mode') and self.is_multiple_user_mode:
|
||||||
|
self.log_output.append('Batch processing stopped.')
|
||||||
|
self.is_multiple_user_mode = False
|
||||||
|
if hasattr(self, 'accounts_to_fetch'):
|
||||||
|
del self.accounts_to_fetch
|
||||||
|
else:
|
||||||
|
self.log_output.append('Auto batch mode stopped.')
|
||||||
|
|
||||||
|
self.enable_batch_buttons()
|
||||||
|
|
||||||
|
def reset_ui(self):
|
||||||
|
super().reset_ui()
|
||||||
|
icon_dir = os.path.join(os.path.dirname(__file__), 'icons')
|
||||||
|
if hasattr(self, 'pause_resume_btn'):
|
||||||
|
self.pause_resume_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-pause.svg')))
|
||||||
|
|
||||||
|
def on_download_finished(self, success, message):
|
||||||
|
self.progress_bar.hide()
|
||||||
|
self.stop_btn.hide()
|
||||||
|
self.pause_resume_btn.hide()
|
||||||
|
self.pause_resume_btn.setText(' Pause')
|
||||||
|
icon_dir = os.path.join(os.path.dirname(__file__), 'icons')
|
||||||
|
self.pause_resume_btn.setIcon(self.create_colored_icon(os.path.join(icon_dir, 'player-pause.svg')))
|
||||||
|
self.stop_timer()
|
||||||
|
|
||||||
|
self.download_selected_btn.setEnabled(True)
|
||||||
|
self.update_selected_btn.setEnabled(True)
|
||||||
|
|
||||||
|
self.pause_fetch_btn.hide()
|
||||||
|
self.stop_fetch_btn.hide()
|
||||||
|
|
||||||
|
if success:
|
||||||
|
self.log_output.append(f"\nStatus: {message}")
|
||||||
|
else:
|
||||||
|
self.log_output.append(f"Error: {message}")
|
||||||
|
|
||||||
|
self.tab_widget.setCurrentWidget(self.process_tab)
|
||||||
@@ -0,0 +1,3 @@
|
|||||||
|
{
|
||||||
|
"version": "3.7"
|
||||||
|
}
|
||||||