Compare commits

...
3 Commits
Author SHA1 Message Date
afkarxyz aa87cce538 v4.1 2025-12-11 22:17:57 +07:00
afkarxyz 2d913d987f v4.1 2025-12-11 22:14:01 +07:00
afkarxyz 3abba4cc59 v4.0 2025-12-05 06:12:04 +07:00
26 changed files with 3839 additions and 1583 deletions

No files matched your search

+6 -11
View File
@@ -14,12 +14,13 @@ A GUI tool to download original-quality images and videos from Twitter/X account
### [Download](https://github.com/afkarxyz/SpotiFLAC/releases) ### [Download](https://github.com/afkarxyz/SpotiFLAC/releases)
- If you're familiar with **userscripts**, please install it [**here**](https://greasyfork.org/en/scripts/523157) - If you're familiar with userscripts, install it [**here**](https://greasyfork.org/en/scripts/551198)
- The **Chrome extension** version is now available, please install it [**here**](https://www.patreon.com/posts/chrome-extension-139296789)
- To install the Chrome extension version, click [**here**](https://www.patreon.com/posts/chrome-extension-139296789)
## Screenshot ## Screenshot
![Image](https://github.com/user-attachments/assets/02bd8c33-74b7-4fde-8b6c-d2b006a3ae70) ![Image](https://github.com/user-attachments/assets/1638e0c3-5dc5-4202-bf94-cdebd37a5f19)
## How to Obtain Auth Token ## How to Obtain Auth Token
@@ -27,7 +28,7 @@ A GUI tool to download original-quality images and videos from Twitter/X account
> - I suggest not using the **main account** to obtain the token. > - I suggest not using the **main account** to obtain the token.
> - You can use https://temp-mail.io to register a Twitter account. > - You can use https://temp-mail.io to register a Twitter account.
> - Using an auth token or cookies has the potential to get the **account suspended.** > - Using an auth token or cookies has the potential to get the **account suspended.**
> - If too many media files are fetched, it may trigger a **rate limit**, and the media retrieval will fail, try enabling Batch mode. > - If too many media files are fetched, it may trigger a **rate limit**, and the media retrieval will fail.
### [Video Tutorial](https://www.patreon.com/posts/how-to-obtain-127206894) ### [Video Tutorial](https://www.patreon.com/posts/how-to-obtain-127206894)
@@ -35,13 +36,7 @@ A GUI tool to download original-quality images and videos from Twitter/X account
2. Log into your account 2. Log into your account
3. Open the Developer Tools by pressing <kbd>F12</kbd> 3. Open the Developer Tools by pressing <kbd>F12</kbd>
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 [X.com Auth Token Grabber](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/download/v1.0/X.com.Auth.Token.Grabber.zip) 5. Find and copy the `auth_token` value
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
![image](https://github.com/user-attachments/assets/4bf5f787-d34f-4259-837c-07a6432c4360)
> Developer Tools
![image](https://github.com/user-attachments/assets/8e81dd8f-f8be-4254-9cf6-cacfa97743e9) ![image](https://github.com/user-attachments/assets/8e81dd8f-f8be-4254-9cf6-cacfa97743e9)
+59 -20
View File
@@ -174,18 +174,21 @@ func (a *App) Quit() {
// DownloadMediaRequest represents the request for downloading media (legacy) // DownloadMediaRequest represents the request for downloading media (legacy)
type DownloadMediaRequest struct { type DownloadMediaRequest struct {
URLs []string `json:"urls"` URLs []string `json:"urls"`
OutputDir string `json:"output_dir"` OutputDir string `json:"output_dir"`
Username string `json:"username"` Username string `json:"username"`
Proxy string `json:"proxy,omitempty"` // Optional proxy URL (e.g., http://proxy:port or socks5://proxy:port)
} }
// MediaItemRequest represents a media item with metadata // MediaItemRequest represents a media item with metadata
type MediaItemRequest struct { type MediaItemRequest struct {
URL string `json:"url"` URL string `json:"url"`
Date string `json:"date"` Date string `json:"date"`
TweetID backend.TweetIDString `json:"tweet_id"` TweetID backend.TweetIDString `json:"tweet_id"`
Type string `json:"type"` Type string `json:"type"`
Content string `json:"content,omitempty"` // Tweet text content (for text-only tweets) Content string `json:"content,omitempty"` // Tweet text content (for text-only tweets)
OriginalFilename string `json:"original_filename,omitempty"` // Original filename from API
AuthorUsername string `json:"author_username,omitempty"` // Username of tweet author (for bookmarks and likes)
} }
// DownloadMediaWithMetadataRequest represents the request for downloading media with metadata // DownloadMediaWithMetadataRequest represents the request for downloading media with metadata
@@ -193,12 +196,14 @@ type DownloadMediaWithMetadataRequest struct {
Items []MediaItemRequest `json:"items"` Items []MediaItemRequest `json:"items"`
OutputDir string `json:"output_dir"` OutputDir string `json:"output_dir"`
Username string `json:"username"` Username string `json:"username"`
Proxy string `json:"proxy,omitempty"` // Optional proxy URL (e.g., http://proxy:port or socks5://proxy:port)
} }
// DownloadMediaResponse represents the response for download operation // DownloadMediaResponse represents the response for download operation
type DownloadMediaResponse struct { type DownloadMediaResponse struct {
Success bool `json:"success"` Success bool `json:"success"`
Downloaded int `json:"downloaded"` Downloaded int `json:"downloaded"`
Skipped int `json:"skipped"`
Failed int `json:"failed"` Failed int `json:"failed"`
Message string `json:"message"` Message string `json:"message"`
} }
@@ -222,11 +227,12 @@ func (a *App) DownloadMedia(req DownloadMediaRequest) (DownloadMediaResponse, er
outputDir = filepath.Join(outputDir, req.Username) outputDir = filepath.Join(outputDir, req.Username)
} }
downloaded, failed, err := backend.DownloadMediaFiles(req.URLs, outputDir) downloaded, failed, err := backend.DownloadMediaFiles(req.URLs, outputDir, req.Proxy)
if err != nil { if err != nil {
return DownloadMediaResponse{ return DownloadMediaResponse{
Success: false, Success: false,
Downloaded: downloaded, Downloaded: downloaded,
Skipped: 0,
Failed: failed, Failed: failed,
Message: err.Error(), Message: err.Error(),
}, err }, err
@@ -235,6 +241,7 @@ func (a *App) DownloadMedia(req DownloadMediaRequest) (DownloadMediaResponse, er
return DownloadMediaResponse{ return DownloadMediaResponse{
Success: true, Success: true,
Downloaded: downloaded, Downloaded: downloaded,
Skipped: 0,
Failed: failed, Failed: failed,
Message: fmt.Sprintf("Downloaded %d files, %d failed", downloaded, failed), Message: fmt.Sprintf("Downloaded %d files, %d failed", downloaded, failed),
}, nil }, nil
@@ -268,16 +275,31 @@ func (a *App) DownloadMediaWithMetadata(req DownloadMediaWithMetadataRequest) (D
outputDir = backend.GetDefaultDownloadPath() outputDir = backend.GetDefaultDownloadPath()
} }
// Convert request items to backend items // Convert request items to backend items
items := make([]backend.MediaItem, len(req.Items)) // For bookmarks and likes, use author_username from each item if available
for i, item := range req.Items { items := make([]backend.MediaItem, len(req.Items))
for i, item := range req.Items {
// Use original filename from API if available, otherwise extract from URL
originalFilename := item.OriginalFilename
if originalFilename == "" {
// Fallback: extract from URL if not provided in API response
originalFilename = backend.ExtractOriginalFilename(item.URL)
}
// For bookmarks and likes, use author_username from item, otherwise use req.Username
username := req.Username
if item.AuthorUsername != "" {
username = item.AuthorUsername
}
items[i] = backend.MediaItem{ items[i] = backend.MediaItem{
URL: item.URL, URL: item.URL,
Date: item.Date, Date: item.Date,
TweetID: int64(item.TweetID), TweetID: int64(item.TweetID),
Type: item.Type, Type: item.Type,
Username: req.Username, Username: username,
Content: item.Content, Content: item.Content,
OriginalFilename: originalFilename,
} }
} }
@@ -306,11 +328,12 @@ func (a *App) DownloadMediaWithMetadata(req DownloadMediaWithMetadataRequest) (D
}) })
} }
downloaded, failed, err := backend.DownloadMediaWithMetadataProgressAndStatus(items, outputDir, req.Username, progressCallback, itemStatusCallback, a.downloadCtx) downloaded, skipped, failed, err := backend.DownloadMediaWithMetadataProgressAndStatus(items, outputDir, req.Username, progressCallback, itemStatusCallback, a.downloadCtx, req.Proxy)
if err != nil { if err != nil {
return DownloadMediaResponse{ return DownloadMediaResponse{
Success: false, Success: false,
Downloaded: downloaded, Downloaded: downloaded,
Skipped: skipped,
Failed: failed, Failed: failed,
Message: err.Error(), Message: err.Error(),
}, err }, err
@@ -322,8 +345,9 @@ func (a *App) DownloadMediaWithMetadata(req DownloadMediaWithMetadataRequest) (D
return DownloadMediaResponse{ return DownloadMediaResponse{
Success: true, Success: true,
Downloaded: downloaded, Downloaded: downloaded,
Skipped: skipped,
Failed: failed, Failed: failed,
Message: fmt.Sprintf("Downloaded %d files, %d failed", downloaded, failed), Message: fmt.Sprintf("Downloaded %d files, %d skipped, %d failed", downloaded, skipped, failed),
}, nil }, nil
} }
@@ -378,6 +402,11 @@ func (a *App) ExportAccountJSON(id int64, outputDir string) (string, error) {
return backend.ExportAccountToFile(id, outputDir) return backend.ExportAccountToFile(id, outputDir)
} }
// ExportAccountsTXT exports selected accounts to TXT file in specified directory
func (a *App) ExportAccountsTXT(ids []int64, outputDir string) (string, error) {
return backend.ExportAccountsToTXT(ids, outputDir)
}
// UpdateAccountGroup updates the group for an account // UpdateAccountGroup updates the group for an account
func (a *App) UpdateAccountGroup(id int64, groupName, groupColor string) error { func (a *App) UpdateAccountGroup(id int64, groupName, groupColor string) error {
return backend.UpdateAccountGroup(id, groupName, groupColor) return backend.UpdateAccountGroup(id, groupName, groupColor)
@@ -400,6 +429,16 @@ func (a *App) DownloadFFmpeg() error {
return backend.DownloadFFmpeg(nil) return backend.DownloadFFmpeg(nil)
} }
// IsExifToolInstalled checks if exiftool is available
func (a *App) IsExifToolInstalled() bool {
return backend.IsExifToolInstalled()
}
// DownloadExifTool downloads exiftool binary
func (a *App) DownloadExifTool() error {
return backend.DownloadExifTool(nil)
}
// ConvertGIFsRequest represents request for converting GIFs // ConvertGIFsRequest represents request for converting GIFs
type ConvertGIFsRequest struct { type ConvertGIFsRequest struct {
FolderPath string `json:"folder_path"` FolderPath string `json:"folder_path"`
+58
View File
@@ -1,8 +1,12 @@
package backend package backend
import ( import (
"fmt"
"net/http"
"net/url"
"os" "os"
"path/filepath" "path/filepath"
"time"
) )
func GetDefaultDownloadPath() string { func GetDefaultDownloadPath() string {
@@ -16,3 +20,57 @@ func GetDefaultDownloadPath() string {
// Return path to user's Pictures folder // Return path to user's Pictures folder
return filepath.Join(homeDir, "Pictures") return filepath.Join(homeDir, "Pictures")
} }
// GetProxyURL gets proxy URL from environment variables or custom proxy setting
// Priority: customProxy > HTTP_PROXY/HTTPS_PROXY > http_proxy/https_proxy
func GetProxyURL(customProxy string) (*url.URL, error) {
// First, check custom proxy setting
if customProxy != "" {
proxyURL, err := url.Parse(customProxy)
if err != nil {
return nil, fmt.Errorf("invalid custom proxy URL: %v", err)
}
return proxyURL, nil
}
// Check environment variables (case-insensitive on Windows)
proxyEnv := os.Getenv("HTTPS_PROXY")
if proxyEnv == "" {
proxyEnv = os.Getenv("https_proxy")
}
if proxyEnv == "" {
proxyEnv = os.Getenv("HTTP_PROXY")
}
if proxyEnv == "" {
proxyEnv = os.Getenv("http_proxy")
}
if proxyEnv != "" {
proxyURL, err := url.Parse(proxyEnv)
if err != nil {
return nil, fmt.Errorf("invalid proxy URL from environment: %v", err)
}
return proxyURL, nil
}
return nil, nil // No proxy
}
// CreateHTTPClient creates an HTTP client with proxy support
func CreateHTTPClient(customProxy string, timeout time.Duration) (*http.Client, error) {
proxyURL, err := GetProxyURL(customProxy)
if err != nil {
return nil, err
}
transport := &http.Transport{
Proxy: http.ProxyURL(proxyURL),
}
client := &http.Client{
Transport: transport,
Timeout: timeout,
}
return client, nil
}
+47 -38
View File
@@ -241,36 +241,6 @@ func ClearAllAccounts() error {
return err return err
} }
// GetAccountByUsername returns a specific account by username
func GetAccountByUsername(username string) (*AccountDB, error) {
if db == nil {
if err := InitDB(); err != nil {
return nil, err
}
}
var acc AccountDB
var lastFetched time.Time
var completedInt int
err := db.QueryRow(`
SELECT id, username, name, profile_image, total_media, last_fetched, response_json,
COALESCE(cursor, '') as cursor, COALESCE(completed, 1) as completed
FROM accounts WHERE username = ?
`, username).Scan(&acc.ID, &acc.Username, &acc.Name, &acc.ProfileImage, &acc.TotalMedia, &lastFetched, &acc.ResponseJSON, &acc.Cursor, &completedInt)
if err != nil {
return nil, err
}
acc.LastFetched = lastFetched
acc.Completed = completedInt == 1
// Convert legacy format if needed
if converted, err := ConvertLegacyToNewFormat(acc.ResponseJSON); err == nil {
acc.ResponseJSON = converted
}
return &acc, nil
}
// GetAccountByID returns a specific account by ID // GetAccountByID returns a specific account by ID
func GetAccountByID(id int64) (*AccountDB, error) { func GetAccountByID(id int64) (*AccountDB, error) {
@@ -314,14 +284,6 @@ func DeleteAccount(id int64) error {
_, err := db.Exec("DELETE FROM accounts WHERE id = ?", id) _, err := db.Exec("DELETE FROM accounts WHERE id = ?", id)
return err return err
} }
// ParseResponseJSON parses the stored JSON response
func ParseResponseJSON(jsonStr string) (map[string]interface{}, error) {
var result map[string]interface{}
err := json.Unmarshal([]byte(jsonStr), &result)
return result, err
}
// LegacyMediaEntry represents media entry in old format // LegacyMediaEntry represents media entry in old format
type LegacyMediaEntry struct { type LegacyMediaEntry struct {
TweetID string `json:"tweet_id"` TweetID string `json:"tweet_id"`
@@ -442,6 +404,53 @@ func ExportAccountToFile(id int64, outputDir string) (string, error) {
return filePath, nil return filePath, nil
} }
// ExportAccountsToTXT exports selected accounts to TXT file (one username per line)
func ExportAccountsToTXT(ids []int64, outputDir string) (string, error) {
if len(ids) == 0 {
return "", fmt.Errorf("no accounts to export")
}
// Create export directory if not exists
exportDir := filepath.Join(outputDir, "twitterxmediabatchdownloader_backups")
if err := os.MkdirAll(exportDir, 0755); err != nil {
return "", err
}
// Get all accounts by IDs
var usernames []string
for _, id := range ids {
acc, err := GetAccountByID(id)
if err != nil {
continue // Skip if account not found
}
if acc.Username != "" {
usernames = append(usernames, acc.Username)
}
}
if len(usernames) == 0 {
return "", fmt.Errorf("no valid usernames found")
}
// Create TXT content (one username per line)
txtContent := ""
for i, username := range usernames {
if i > 0 {
txtContent += "\n"
}
txtContent += username
}
// Filename: twitterxmediabatchdownloader_multiple.txt
filePath := filepath.Join(exportDir, "twitterxmediabatchdownloader_multiple.txt")
if err := os.WriteFile(filePath, []byte(txtContent), 0644); err != nil {
return "", err
}
return filePath, nil
}
// ImportAccountFromFile imports account from JSON file (supports both old and new format) // ImportAccountFromFile imports account from JSON file (supports both old and new format)
func ImportAccountFromFile(filePath string) (string, error) { func ImportAccountFromFile(filePath string) (string, error) {
if db == nil { if db == nil {
+77 -38
View File
@@ -21,23 +21,29 @@ const (
// MediaItem represents a media item with metadata for download // MediaItem represents a media item with metadata for download
type MediaItem struct { type MediaItem struct {
URL string `json:"url"` URL string `json:"url"`
Date string `json:"date"` Date string `json:"date"`
TweetID int64 `json:"tweet_id"` TweetID int64 `json:"tweet_id"`
Type string `json:"type"` Type string `json:"type"`
Username string `json:"username"` Username string `json:"username"`
Content string `json:"content,omitempty"` // Tweet text content (for text-only tweets) Content string `json:"content,omitempty"` // Tweet text content (for text-only tweets)
OriginalFilename string `json:"original_filename,omitempty"` // Original Twitter media filename (15 char alphanumeric)
} }
// DownloadMediaFiles downloads media files from URLs to the output directory (legacy) // DownloadMediaFiles downloads media files from URLs to the output directory (legacy)
func DownloadMediaFiles(urls []string, outputDir string) (downloaded int, failed int, err error) { func DownloadMediaFiles(urls []string, outputDir string, customProxy string) (downloaded int, failed int, err error) {
// Create output directory if it doesn't exist // Create output directory if it doesn't exist
if err := os.MkdirAll(outputDir, 0755); err != nil { if err := os.MkdirAll(outputDir, 0755); err != nil {
return 0, len(urls), fmt.Errorf("failed to create output directory: %v", err) return 0, len(urls), fmt.Errorf("failed to create output directory: %v", err)
} }
client := &http.Client{ // Create HTTP client with proxy support
Timeout: 60 * time.Second, client, err := CreateHTTPClient(customProxy, 60*time.Second)
if err != nil {
// If proxy setup fails, use default client without proxy
client = &http.Client{
Timeout: 60 * time.Second,
}
} }
for _, mediaURL := range urls { for _, mediaURL := range urls {
@@ -73,38 +79,35 @@ type downloadTask struct {
index int index int
} }
// DownloadMediaWithMetadata downloads media files with proper naming and categorization
func DownloadMediaWithMetadata(items []MediaItem, outputDir string, username string) (downloaded int, failed int, err error) {
return DownloadMediaWithMetadataProgressAndStatus(items, outputDir, username, nil, nil, nil)
}
// DownloadMediaWithMetadataProgress downloads media files with progress callback and cancellation support
func DownloadMediaWithMetadataProgress(items []MediaItem, outputDir string, username string, progress ProgressCallback, ctx context.Context) (downloaded int, failed int, err error) {
return DownloadMediaWithMetadataProgressAndStatus(items, outputDir, username, progress, nil, ctx)
}
// DownloadMediaWithMetadataProgressAndStatus downloads media files with progress and per-item status callbacks // DownloadMediaWithMetadataProgressAndStatus downloads media files with progress and per-item status callbacks
func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir string, username string, progress ProgressCallback, itemStatus ItemStatusCallback, ctx context.Context) (downloaded int, failed int, err error) { // Returns: downloaded count, skipped count, failed count, error
func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir string, username string, progress ProgressCallback, itemStatus ItemStatusCallback, ctx context.Context, customProxy string) (downloaded int, skipped int, failed int, err error) {
if ctx == nil { if ctx == nil {
ctx = context.Background() ctx = context.Background()
} }
// Create base output directory
baseDir := filepath.Join(outputDir, username)
if err := os.MkdirAll(baseDir, 0755); err != nil {
return 0, len(items), fmt.Errorf("failed to create output directory: %v", err)
}
total := len(items) total := len(items)
if total == 0 { if total == 0 {
return 0, 0, nil return 0, 0, 0, nil
} }
// Prepare all tasks first (sequential to handle tweet media count) // Prepare all tasks first (sequential to handle tweet media count)
tweetMediaCount := make(map[int64]int) // For bookmarks and likes, each item may have different username, so we track per username
tweetMediaCount := make(map[string]map[int64]int) // username -> tweet_id -> count
tasks := make([]downloadTask, 0, total) tasks := make([]downloadTask, 0, total)
for i, item := range items { for i, item := range items {
// Use item.Username if available (for bookmarks/likes with different authors), otherwise use provided username
itemUsername := item.Username
if itemUsername == "" {
itemUsername = username
}
// Initialize tweet media count for this username if needed
if tweetMediaCount[itemUsername] == nil {
tweetMediaCount[itemUsername] = make(map[int64]int)
}
// Determine subfolder based on type // Determine subfolder based on type
var subfolder string var subfolder string
switch item.Type { switch item.Type {
@@ -120,6 +123,12 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
subfolder = "other" subfolder = "other"
} }
// Create base directory for this username
baseDir := filepath.Join(outputDir, itemUsername)
if err := os.MkdirAll(baseDir, 0755); err != nil {
continue
}
// Create type subfolder // Create type subfolder
typeDir := filepath.Join(baseDir, subfolder) typeDir := filepath.Join(baseDir, subfolder)
if err := os.MkdirAll(typeDir, 0755); err != nil { if err := os.MkdirAll(typeDir, 0755); err != nil {
@@ -132,12 +141,12 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
// Get file extension // Get file extension
ext := getExtension(item.URL, item.Type) ext := getExtension(item.URL, item.Type)
// Increment counter for this tweet_id // Increment counter for this username and tweet_id
tweetMediaCount[item.TweetID]++ tweetMediaCount[itemUsername][item.TweetID]++
mediaIndex := tweetMediaCount[item.TweetID] mediaIndex := tweetMediaCount[itemUsername][item.TweetID]
// Create filename: {username}_{timestamp}_{tweet_id}_{index}.{ext} // Create filename: {username}_{timestamp}_{tweet_id}_{index}.{ext}
filename := fmt.Sprintf("%s_%s_%d_%02d%s", username, timestamp, item.TweetID, mediaIndex, ext) filename := fmt.Sprintf("%s_%s_%d_%02d%s", itemUsername, timestamp, item.TweetID, mediaIndex, ext)
outputPath := filepath.Join(typeDir, filename) outputPath := filepath.Join(typeDir, filename)
tasks = append(tasks, downloadTask{ tasks = append(tasks, downloadTask{
@@ -149,6 +158,7 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
// Counters for parallel downloads // Counters for parallel downloads
var downloadedCount int64 var downloadedCount int64
var skippedCount int64
var failedCount int64 var failedCount int64
var completedCount int64 var completedCount int64
@@ -162,13 +172,23 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
numWorkers = len(tasks) numWorkers = len(tasks)
} }
// Create HTTP client once for all workers (shared client is more efficient)
var sharedClient *http.Client
client, err := CreateHTTPClient(customProxy, 60*time.Second)
if err != nil {
// If proxy setup fails, use default client without proxy
sharedClient = &http.Client{
Timeout: 60 * time.Second,
}
} else {
sharedClient = client
}
for i := 0; i < numWorkers; i++ { for i := 0; i < numWorkers; i++ {
wg.Add(1) wg.Add(1)
go func() { go func() {
defer wg.Done() defer wg.Done()
client := &http.Client{ client := sharedClient
Timeout: 60 * time.Second,
}
for task := range taskChan { for task := range taskChan {
// Check for cancellation // Check for cancellation
@@ -181,8 +201,13 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
var status string var status string
// Skip if file already exists // Skip if file already exists
if _, err := os.Stat(task.outputPath); err == nil { if _, err := os.Stat(task.outputPath); err == nil {
atomic.AddInt64(&downloadedCount, 1)
status = "skipped" status = "skipped"
// Emit status immediately for skipped files
if itemStatus != nil {
itemStatus(task.item.TweetID, task.index, status)
}
atomic.AddInt64(&skippedCount, 1)
continue // Skip to next task
} else if task.item.Type == "text" { } else if task.item.Type == "text" {
// For text tweets, write content to file // For text tweets, write content to file
if err := os.WriteFile(task.outputPath, []byte(task.item.Content), 0644); err != nil { if err := os.WriteFile(task.outputPath, []byte(task.item.Content), 0644); err != nil {
@@ -196,6 +221,20 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
atomic.AddInt64(&failedCount, 1) atomic.AddInt64(&failedCount, 1)
status = "failed" status = "failed"
} else { } else {
// Embed metadata after successful download
tweetURL := fmt.Sprintf("https://x.com/i/status/%d", task.item.TweetID)
// Always extract original filename from URL (simpler approach)
originalFilename := ExtractOriginalFilename(task.item.URL)
// For debugging: if original filename is still empty for video, it means it's not in the URL
// This is acceptable - video URLs from Twitter may not contain original filename
// Embed metadata (non-fatal: if it fails, file is still downloaded)
if err := EmbedMetadata(task.outputPath, task.item.Content, tweetURL, originalFilename); err != nil {
// Log error but don't fail the download
// Metadata embedding is optional
}
atomic.AddInt64(&downloadedCount, 1) atomic.AddInt64(&downloadedCount, 1)
status = "success" status = "success"
} }
@@ -220,7 +259,7 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
case <-ctx.Done(): case <-ctx.Done():
close(taskChan) close(taskChan)
wg.Wait() wg.Wait()
return int(downloadedCount), int(failedCount) + (total - int(completedCount)), ctx.Err() return int(downloadedCount), int(skippedCount), int(failedCount) + (total - int(completedCount)), ctx.Err()
case taskChan <- task: case taskChan <- task:
} }
} }
@@ -229,7 +268,7 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
// Wait for all workers to finish // Wait for all workers to finish
wg.Wait() wg.Wait()
return int(downloadedCount), int(failedCount), nil return int(downloadedCount), int(skippedCount), int(failedCount), nil
} }
// downloadFileWithContext downloads a single file with context support for cancellation // downloadFileWithContext downloads a single file with context support for cancellation
+348
View File
@@ -0,0 +1,348 @@
package backend
import (
"archive/zip"
"crypto/sha256"
"encoding/hex"
"fmt"
"io"
"net/http"
"os"
"os/exec"
"path/filepath"
"runtime"
"strings"
)
// ExifTool download URLs (SourceForge)
const (
// Windows 64-bit
exiftoolWindows64URL = "https://sourceforge.net/projects/exiftool/files/exiftool-13.43_64.zip/download"
// Windows 32-bit
exiftoolWindows32URL = "https://sourceforge.net/projects/exiftool/files/exiftool-13.43_32.zip/download"
// Unix (Linux/macOS): tar.gz
exiftoolUnixURL = "https://sourceforge.net/projects/exiftool/files/Image-ExifTool-13.43.tar.gz/download"
)
// ExifTool SHA256 hashes for verification
// Note: Hashes will be calculated during download if not provided
// For now, we'll skip hash verification for version 13.43 (can be added later if needed)
const (
exiftoolWindows64Hash = "" // Hash not provided, will skip verification
exiftoolWindows32Hash = "" // Hash not provided, will skip verification
exiftoolUnixHash = "" // Hash not provided, will skip verification
)
// GetExifToolPath returns the path to exiftool binary
func GetExifToolPath() string {
homeDir, _ := os.UserHomeDir()
baseDir := filepath.Join(homeDir, ".twitterxmediabatchdownloader")
switch runtime.GOOS {
case "windows":
return filepath.Join(baseDir, "exiftool.exe")
default:
// For Unix (Linux/macOS), exiftool is in Image-ExifTool-VERSION/exiftool
// We need to find the folder dynamically since version may vary
pattern := filepath.Join(baseDir, "Image-ExifTool-*")
matches, err := filepath.Glob(pattern)
if err == nil && len(matches) > 0 {
// Use the first match (should only be one)
exiftoolPath := filepath.Join(matches[0], "exiftool")
if _, err := os.Stat(exiftoolPath); err == nil {
return exiftoolPath
}
}
// Fallback: return path that will be created after extraction
return filepath.Join(baseDir, "exiftool")
}
}
// IsExifToolInstalled checks if exiftool is available
func IsExifToolInstalled() bool {
exiftoolPath := GetExifToolPath()
if _, err := os.Stat(exiftoolPath); err == nil {
// Test if it's executable by running version command
cmd := exec.Command(exiftoolPath, "-ver")
hideWindow(cmd)
if err := cmd.Run(); err == nil {
return true
}
}
return false
}
// calculateSHA256 calculates SHA256 hash of a file
func calculateSHA256(filePath string) (string, error) {
file, err := os.Open(filePath)
if err != nil {
return "", err
}
defer file.Close()
hash := sha256.New()
if _, err := io.Copy(hash, file); err != nil {
return "", err
}
return hex.EncodeToString(hash.Sum(nil)), nil
}
// verifyHash verifies the SHA256 hash of a downloaded file
func verifyHash(filePath, expectedHash string) error {
actualHash, err := calculateSHA256(filePath)
if err != nil {
return fmt.Errorf("failed to calculate hash: %v", err)
}
if !strings.EqualFold(actualHash, expectedHash) {
return fmt.Errorf("hash verification failed: expected %s, got %s", expectedHash, actualHash)
}
return nil
}
// is64Bit checks if the system is 64-bit
func is64Bit() bool {
return runtime.GOARCH == "amd64" || runtime.GOARCH == "arm64"
}
// DownloadExifTool downloads exiftool binary for current platform
func DownloadExifTool(progressCallback func(downloaded, total int64)) error {
var downloadURL string
var expectedHash string
switch runtime.GOOS {
case "windows":
if is64Bit() {
downloadURL = exiftoolWindows64URL
expectedHash = exiftoolWindows64Hash
} else {
downloadURL = exiftoolWindows32URL
expectedHash = exiftoolWindows32Hash
}
case "linux", "darwin":
// Linux and macOS use the same tar.gz archive
downloadURL = exiftoolUnixURL
expectedHash = exiftoolUnixHash
default:
return fmt.Errorf("unsupported platform: %s", runtime.GOOS)
}
// Create temp file for download
tempFile, err := os.CreateTemp("", "exiftool-*")
if err != nil {
return fmt.Errorf("failed to create temp file: %v", err)
}
tempPath := tempFile.Name()
defer os.Remove(tempPath)
defer tempFile.Close()
// Download file
resp, err := http.Get(downloadURL)
if err != nil {
return fmt.Errorf("failed to download exiftool: %v", err)
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return fmt.Errorf("failed to download exiftool: status %d", resp.StatusCode)
}
// Copy with progress
total := resp.ContentLength
var downloaded int64
buf := make([]byte, 32*1024)
for {
n, err := resp.Body.Read(buf)
if n > 0 {
_, writeErr := tempFile.Write(buf[:n])
if writeErr != nil {
return fmt.Errorf("failed to write temp file: %v", writeErr)
}
downloaded += int64(n)
if progressCallback != nil {
progressCallback(downloaded, total)
}
}
if err == io.EOF {
break
}
if err != nil {
return fmt.Errorf("failed to download: %v", err)
}
}
tempFile.Close()
// Verify hash before extraction
if expectedHash != "" {
if err := verifyHash(tempPath, expectedHash); err != nil {
return fmt.Errorf("hash verification failed: %v", err)
}
}
// Extract exiftool binary
exiftoolPath := GetExifToolPath()
baseDir := filepath.Dir(exiftoolPath)
if err := os.MkdirAll(baseDir, 0755); err != nil {
return fmt.Errorf("failed to create directory: %v", err)
}
switch runtime.GOOS {
case "windows":
return extractExifToolFromZip(tempPath, exiftoolPath)
case "linux", "darwin":
// For Linux/macOS, we need to extract and build
// For simplicity, we'll extract the exiftool script from tar.gz
return extractExifToolFromTarGz(tempPath, exiftoolPath)
}
return nil
}
// extractExifToolFromZip extracts exiftool from Windows zip archive
func extractExifToolFromZip(zipPath, destPath string) error {
r, err := zip.OpenReader(zipPath)
if err != nil {
return fmt.Errorf("failed to open zip: %v", err)
}
defer r.Close()
// Look for exiftool(-k).exe or exiftool.exe in the zip
var exiftoolFile *zip.File
for _, f := range r.File {
name := filepath.Base(f.Name)
// ExifTool Windows zip contains exiftool(-k).exe
if name == "exiftool(-k).exe" || name == "exiftool.exe" {
exiftoolFile = f
break
}
}
if exiftoolFile == nil {
return fmt.Errorf("exiftool.exe not found in archive")
}
rc, err := exiftoolFile.Open()
if err != nil {
return fmt.Errorf("failed to open file in zip: %v", err)
}
defer rc.Close()
out, err := os.Create(destPath)
if err != nil {
return fmt.Errorf("failed to create output file: %v", err)
}
defer out.Close()
if _, err := io.Copy(out, rc); err != nil {
return fmt.Errorf("failed to extract file: %v", err)
}
// Also need to extract the lib directory for Windows (exiftool_files folder)
libDir := filepath.Join(filepath.Dir(destPath), "exiftool_files")
for _, f := range r.File {
// Check if file is in exiftool_files directory
if strings.Contains(f.Name, "exiftool_files") && !strings.HasSuffix(f.Name, "/") {
// Extract relative path from exiftool_files
parts := strings.Split(f.Name, "exiftool_files/")
if len(parts) < 2 {
continue
}
relPath := parts[1]
if relPath == "" {
continue
}
targetPath := filepath.Join(libDir, relPath)
// Create directory structure
if err := os.MkdirAll(filepath.Dir(targetPath), 0755); err != nil {
continue
}
// Skip if it's a directory entry
if f.FileInfo().IsDir() {
os.MkdirAll(targetPath, 0755)
continue
}
// Extract file
rc, err := f.Open()
if err != nil {
continue // Skip on error
}
outFile, err := os.Create(targetPath)
if err != nil {
rc.Close()
continue
}
io.Copy(outFile, rc)
outFile.Close()
rc.Close()
}
}
return nil
}
// extractExifToolFromTarGz extracts exiftool from tar.gz archive (Linux/macOS)
func extractExifToolFromTarGz(tarGzPath, destPath string) error {
// For Linux/macOS, ExifTool is a Perl script that requires the lib directory
// We'll extract the entire folder and use exiftool directly from Image-ExifTool-VERSION/exiftool
// This is simpler than implementing tar.gz extraction in Go
baseDir := filepath.Dir(destPath)
// Use system tar command to extract
cmd := exec.Command("tar", "-xzf", tarGzPath, "-C", baseDir)
hideWindow(cmd)
output, err := cmd.CombinedOutput()
if err != nil {
return fmt.Errorf("failed to extract tar.gz: %v, output: %s", err, string(output))
}
// Find the extracted exiftool script
// The archive extracts to Image-ExifTool-VERSION/exiftool
// We need to find the folder dynamically since version may vary
var extractedDir string
var exiftoolScript string
// Use glob pattern to find Image-ExifTool-* directories
pattern := filepath.Join(baseDir, "Image-ExifTool-*")
matches, err := filepath.Glob(pattern)
if err == nil && len(matches) > 0 {
// Use the first match (should only be one)
extractedDir = matches[0]
exiftoolScript = filepath.Join(extractedDir, "exiftool")
} else {
// Fallback: try common version or alternative location
extractedDir = filepath.Join(baseDir, "Image-ExifTool-13.43")
exiftoolScript = filepath.Join(extractedDir, "exiftool")
}
// Check if exiftool script exists
if _, err := os.Stat(exiftoolScript); err != nil {
// Try alternative location
extractedDir = filepath.Join(baseDir, "exiftool")
exiftoolScript = filepath.Join(extractedDir, "exiftool")
if _, err := os.Stat(exiftoolScript); err != nil {
return fmt.Errorf("exiftool script not found in extracted archive (searched in: %s and %s)", pattern, extractedDir)
}
}
// Make exiftool executable (required for Unix systems)
if err := os.Chmod(exiftoolScript, 0755); err != nil {
return fmt.Errorf("failed to make exiftool executable: %v", err)
}
// For Unix, we keep the entire folder structure and use exiftool directly from it
// The folder will remain in baseDir and GetExifToolPath() will find it via glob pattern
// No need to copy or remove anything
return nil
}
+227
View File
@@ -0,0 +1,227 @@
package backend
import (
"fmt"
"net/url"
"os"
"os/exec"
"path/filepath"
"regexp"
"runtime"
"strings"
)
// ExtractOriginalFilename extracts the original filename from Twitter media URL
// Supports 3 formats:
// 1. animated_gif: https://video.twimg.com/tweet_video/GzstJyDbIAAPuX9.mp4 -> GzstJyDbIAAPuX9
// 2. photo: https://pbs.twimg.com/media/GynjhU0bYAAA_I4?format=jpg -> GynjhU0bYAAA_I4
// 3. video: https://video.twimg.com/amplify_video/.../Jpo0cDa7aNtjSv7o.mp4 -> Jpo0cDa7aNtjSv7o
func ExtractOriginalFilename(mediaURL string) string {
parsedURL, err := url.Parse(mediaURL)
if err != nil {
return ""
}
path := parsedURL.Path
parts := strings.Split(path, "/")
// 1. animated_gif: video.twimg.com/tweet_video/XXX.mp4
if strings.Contains(mediaURL, "/tweet_video/") {
for i, part := range parts {
if part == "tweet_video" && i+1 < len(parts) {
filename := parts[i+1]
// Remove extension
if idx := strings.LastIndex(filename, "."); idx > 0 {
filename = filename[:idx]
}
// Validate alphanumeric + underscore (Twitter filenames can contain _)
if matched, _ := regexp.MatchString(`^[A-Za-z0-9_]+$`, filename); matched && len(filename) > 0 {
return filename
}
}
}
}
// 2. photo: pbs.twimg.com/media/XXX
if strings.Contains(mediaURL, "pbs.twimg.com/media/") {
if len(parts) > 0 {
filename := parts[len(parts)-1]
// Remove extension if present
if idx := strings.LastIndex(filename, "."); idx > 0 {
filename = filename[:idx]
}
// Validate alphanumeric + underscore (Twitter filenames can contain _)
if matched, _ := regexp.MatchString(`^[A-Za-z0-9_]+$`, filename); matched && len(filename) > 0 {
return filename
}
}
}
// 3. video: video.twimg.com/amplify_video/.../XXX.mp4 or video.twimg.com/ext_tw_video/.../XXX.mp4
// Filename is the last segment (before extension)
// Note: Skip if already handled by tweet_video above
if strings.Contains(mediaURL, "video.twimg.com") && !strings.Contains(mediaURL, "/tweet_video/") {
if len(parts) > 0 {
filename := parts[len(parts)-1]
// Remove extension
if idx := strings.LastIndex(filename, "."); idx > 0 {
filename = filename[:idx]
}
// Validate: alphanumeric + underscore with at least one letter (to exclude pure numeric IDs)
if matched, _ := regexp.MatchString(`^[A-Za-z0-9_]+$`, filename); matched {
hasLetter, _ := regexp.MatchString(`[A-Za-z]`, filename)
if hasLetter && len(filename) >= 8 {
return filename
}
}
}
}
return ""
}
// EmbedMetadata embeds metadata into a media file
// Only supports JPG (images) and MP4 (videos)
func EmbedMetadata(filePath string, tweetContent string, tweetURL string, originalFilename string) error {
ext := strings.ToLower(filepath.Ext(filePath))
switch ext {
case ".jpg", ".jpeg":
return embedImageMetadata(filePath, tweetContent, tweetURL, originalFilename)
case ".mp4":
return embedVideoMetadata(filePath, tweetContent, tweetURL, originalFilename)
default:
// For unsupported formats, skip metadata embedding
return nil
}
}
// embedImageMetadata embeds metadata into image files using exiftool or similar
// Since we don't want to add heavy dependencies, we'll use a simple approach:
// For JPEG: We can use exiftool if available, or skip if not
// For PNG: Limited support, skip for now
func embedImageMetadata(filePath string, tweetContent string, tweetURL string, originalFilename string) error {
// Try to use exiftool if available (common tool for metadata)
exiftoolPath := findExifTool()
if exiftoolPath == "" {
// exiftool not found, skip metadata embedding for images
// This is acceptable as it's an optional feature
return nil
}
// Build metadata comment
metadataComment := buildMetadataComment(tweetContent, tweetURL, originalFilename)
// Use exiftool to add comment only (URL | filename)
args := []string{
"-overwrite_original",
"-Comment=" + metadataComment,
filePath,
}
cmd := exec.Command(exiftoolPath, args...)
hideWindow(cmd)
output, err := cmd.CombinedOutput()
if err != nil {
// Non-fatal: if exiftool fails, just skip metadata
return fmt.Errorf("exiftool error (non-fatal): %v, output: %s", err, string(output))
}
_ = output // Suppress unused variable warning
return nil
}
// embedVideoMetadata embeds metadata into video/GIF files using ExifTool
func embedVideoMetadata(filePath string, tweetContent string, tweetURL string, originalFilename string) error {
// Use ExifTool for video metadata (works well for MP4)
exiftoolPath := findExifTool()
if exiftoolPath == "" {
// ExifTool not available, skip metadata embedding (non-fatal)
return nil
}
return embedVideoMetadataWithExifTool(exiftoolPath, filePath, tweetContent, tweetURL, originalFilename)
}
// embedVideoMetadataWithExifTool embeds metadata using ExifTool (preferred for MP4)
func embedVideoMetadataWithExifTool(exiftoolPath string, filePath string, tweetContent string, tweetURL string, originalFilename string) error {
// Build metadata comment
metadataComment := buildMetadataComment(tweetContent, tweetURL, originalFilename)
// Use exiftool to add comment only (URL | filename)
args := []string{
"-overwrite_original",
"-Comment=" + metadataComment,
filePath,
}
cmd := exec.Command(exiftoolPath, args...)
hideWindow(cmd)
output, err := cmd.CombinedOutput()
if err != nil {
// Non-fatal: if exiftool fails, skip metadata (file still downloaded)
return fmt.Errorf("exiftool error (non-fatal): %v, output: %s", err, string(output))
}
_ = output // Suppress unused variable warning
return nil
}
// buildMetadataComment builds a formatted metadata comment string
func buildMetadataComment(tweetContent string, tweetURL string, originalFilename string) string {
var parts []string
if tweetURL != "" {
parts = append(parts, tweetURL)
}
if originalFilename != "" {
parts = append(parts, originalFilename)
}
// If no original filename, just return URL (don't add empty part)
if len(parts) == 0 {
return ""
}
return strings.Join(parts, " | ")
}
// findExifTool searches for exiftool, prioritizing the installed version in .twitterxmediabatchdownloader
func findExifTool() string {
// First, check if exiftool is installed in .twitterxmediabatchdownloader
if IsExifToolInstalled() {
return GetExifToolPath()
}
// Fallback: check common system locations
commonPaths := []string{
"exiftool",
"/usr/bin/exiftool",
"/usr/local/bin/exiftool",
"C:\\Program Files\\exiftool\\exiftool.exe",
"C:\\exiftool\\exiftool.exe",
}
for _, path := range commonPaths {
if runtime.GOOS == "windows" {
// On Windows, try .exe extension
if _, err := exec.LookPath(path); err == nil {
return path
}
} else {
// On Unix, check if executable
if _, err := os.Stat(path); err == nil {
return path
}
}
}
// Try to find in PATH
if path, err := exec.LookPath("exiftool"); err == nil {
return path
}
return ""
}
+75 -55
View File
@@ -213,6 +213,8 @@ type TimelineEntry struct {
ReplyCount int `json:"reply_count,omitempty"` ReplyCount int `json:"reply_count,omitempty"`
Source string `json:"source,omitempty"` Source string `json:"source,omitempty"`
Verified bool `json:"verified,omitempty"` Verified bool `json:"verified,omitempty"`
OriginalFilename string `json:"original_filename,omitempty"` // Original filename from API
AuthorUsername string `json:"author_username,omitempty"` // Username of tweet author (for bookmarks and likes)
} }
// AccountInfo represents Twitter account information (derived from metadata) // AccountInfo represents Twitter account information (derived from metadata)
@@ -395,27 +397,39 @@ func convertMetadataToTimelineEntry(meta TweetMetadata) TimelineEntry {
FavoriteCount: meta.FavoriteCount, FavoriteCount: meta.FavoriteCount,
RetweetCount: meta.RetweetCount, RetweetCount: meta.RetweetCount,
ReplyCount: meta.ReplyCount, ReplyCount: meta.ReplyCount,
AuthorUsername: meta.Author.Name,
} }
} }
// convertToTimelineEntry converts CLIMediaItem to TimelineEntry // convertToTimelineEntry converts CLIMediaItem to TimelineEntry
func convertToTimelineEntry(media CLIMediaItem) TimelineEntry { func convertToTimelineEntry(media CLIMediaItem) TimelineEntry {
// Get username from Author field (preferred for bookmarks/likes) or User field
// Author field always contains the tweet author, while User might be the account fetching for likes
authorUsername := ""
if media.Author.Name != "" {
authorUsername = media.Author.Name
} else if media.User.Name != "" {
authorUsername = media.User.Name
}
entry := TimelineEntry{ entry := TimelineEntry{
URL: media.URL, URL: media.URL,
TweetID: media.TweetID, TweetID: media.TweetID,
Date: media.Date, Date: media.Date,
Extension: media.Extension, Extension: media.Extension,
Width: media.Width, Width: media.Width,
Height: media.Height, Height: media.Height,
IsRetweet: media.RetweetID != 0, IsRetweet: media.RetweetID != 0,
Content: media.Content, Content: media.Content,
ViewCount: media.ViewCount, ViewCount: media.ViewCount,
BookmarkCount: media.BookmarkCount, BookmarkCount: media.BookmarkCount,
FavoriteCount: media.FavoriteCount, FavoriteCount: media.FavoriteCount,
RetweetCount: media.RetweetCount, RetweetCount: media.RetweetCount,
ReplyCount: media.ReplyCount, ReplyCount: media.ReplyCount,
Source: media.Source, Source: media.Source,
Verified: media.Author.Verified, Verified: media.Author.Verified,
AuthorUsername: authorUsername,
// OriginalFilename will be extracted from URL in download.go
} }
// Determine type - media item already has type from CLI // Determine type - media item already has type from CLI
@@ -627,6 +641,17 @@ func ExtractTimeline(req TimelineRequest) (*TwitterResponse, error) {
mediaTweetIDs[int64(media.TweetID)] = true mediaTweetIDs[int64(media.TweetID)] = true
} }
// For bookmarks and likes, keep name as "bookmarks"/"likes" (not from author tweet)
isBookmarks := req.TimelineType == "bookmarks"
isLikes := req.TimelineType == "likes"
if isBookmarks {
accountInfo.Name = "bookmarks"
accountInfo.Nick = "My Bookmarks"
} else if isLikes {
accountInfo.Name = "likes"
accountInfo.Nick = "My Likes"
}
if isTextOnly { if isTextOnly {
// Text-only mode: get tweets from metadata that don't have media // Text-only mode: get tweets from metadata that don't have media
timeline = make([]TimelineEntry, 0) timeline = make([]TimelineEntry, 0)
@@ -637,19 +662,31 @@ func ExtractTimeline(req TimelineRequest) (*TwitterResponse, error) {
} }
// Get account info from first media item if available, otherwise from metadata // Get account info from first media item if available, otherwise from metadata
if len(cliResponse.Media) > 0 { if !isBookmarks && !isLikes {
user := cliResponse.Media[0].User if len(cliResponse.Media) > 0 {
accountInfo.Name = user.Name user := cliResponse.Media[0].User
accountInfo.Nick = user.Nick accountInfo.Name = user.Name
accountInfo.Date = user.Date accountInfo.Nick = user.Nick
accountInfo.FollowersCount = user.FollowersCount accountInfo.Date = user.Date
accountInfo.FriendsCount = user.FriendsCount accountInfo.FollowersCount = user.FollowersCount
accountInfo.ProfileImage = user.ProfileImage accountInfo.FriendsCount = user.FriendsCount
accountInfo.StatusesCount = user.StatusesCount accountInfo.ProfileImage = user.ProfileImage
} else if len(cliResponse.Metadata) > 0 { accountInfo.StatusesCount = user.StatusesCount
firstMeta := cliResponse.Metadata[0] } else if len(cliResponse.Metadata) > 0 {
accountInfo.Name = firstMeta.Author.Name firstMeta := cliResponse.Metadata[0]
accountInfo.Nick = firstMeta.Author.Nick accountInfo.Name = firstMeta.Author.Name
accountInfo.Nick = firstMeta.Author.Nick
}
} else {
// For bookmarks and likes, get other info from first media item if available
if len(cliResponse.Media) > 0 {
user := cliResponse.Media[0].User
accountInfo.Date = user.Date
accountInfo.FollowersCount = user.FollowersCount
accountInfo.FriendsCount = user.FriendsCount
accountInfo.ProfileImage = user.ProfileImage
accountInfo.StatusesCount = user.StatusesCount
}
} }
} else if len(cliResponse.Media) > 0 { } else if len(cliResponse.Media) > 0 {
// Normal media items only (text tweets handled separately with "text" media type) // Normal media items only (text tweets handled separately with "text" media type)
@@ -662,8 +699,10 @@ func ExtractTimeline(req TimelineRequest) (*TwitterResponse, error) {
// Get account info from first media item // Get account info from first media item
user := cliResponse.Media[0].User user := cliResponse.Media[0].User
accountInfo.Name = user.Name if !isBookmarks && !isLikes {
accountInfo.Nick = user.Nick accountInfo.Name = user.Name
accountInfo.Nick = user.Nick
}
accountInfo.Date = user.Date accountInfo.Date = user.Date
accountInfo.FollowersCount = user.FollowersCount accountInfo.FollowersCount = user.FollowersCount
accountInfo.FriendsCount = user.FriendsCount accountInfo.FriendsCount = user.FriendsCount
@@ -688,13 +727,16 @@ func ExtractTimeline(req TimelineRequest) (*TwitterResponse, error) {
FavoriteCount: meta.FavoriteCount, FavoriteCount: meta.FavoriteCount,
RetweetCount: meta.RetweetCount, RetweetCount: meta.RetweetCount,
ReplyCount: meta.ReplyCount, ReplyCount: meta.ReplyCount,
AuthorUsername: meta.Author.Name,
} }
timeline = append(timeline, entry) timeline = append(timeline, entry)
} }
// Get account info from first metadata // Get account info from first metadata
firstMeta := cliResponse.Metadata[0] if !isBookmarks && !isLikes {
accountInfo.Name = firstMeta.Author.Name firstMeta := cliResponse.Metadata[0]
accountInfo.Nick = firstMeta.Author.Nick accountInfo.Name = firstMeta.Author.Name
accountInfo.Nick = firstMeta.Author.Nick
}
} }
// Determine if there's more data to fetch // Determine if there's more data to fetch
@@ -874,25 +916,3 @@ func extractJSON(output string) string {
return "" return ""
} }
// GetThumbnailURL converts a Twitter media URL to thumbnail size
func GetThumbnailURL(url string) string {
// For images: https://pbs.twimg.com/media/XXX?format=jpg&name=thumb
if strings.Contains(url, "pbs.twimg.com/media/") {
// Check if it already has format parameter
if strings.Contains(url, "?format=") {
// Replace name parameter with thumb
if strings.Contains(url, "&name=") {
parts := strings.Split(url, "&name=")
return parts[0] + "&name=thumb"
}
return url + "&name=thumb"
}
// Add format and name parameters
if strings.Contains(url, "?") {
return url + "&name=thumb"
}
return url + "?format=jpg&name=thumb"
}
return url
}
+10 -9
View File
@@ -16,31 +16,32 @@
"@radix-ui/react-checkbox": "^1.3.3", "@radix-ui/react-checkbox": "^1.3.3",
"@radix-ui/react-context-menu": "^2.2.16", "@radix-ui/react-context-menu": "^2.2.16",
"@radix-ui/react-dialog": "^1.1.15", "@radix-ui/react-dialog": "^1.1.15",
"@radix-ui/react-dropdown-menu": "^2.1.16",
"@radix-ui/react-label": "^2.1.8", "@radix-ui/react-label": "^2.1.8",
"@radix-ui/react-progress": "^1.1.8", "@radix-ui/react-progress": "^1.1.8",
"@radix-ui/react-radio-group": "^1.3.8", "@radix-ui/react-radio-group": "^1.3.8",
"@radix-ui/react-select": "^2.2.6", "@radix-ui/react-select": "^2.2.6",
"@radix-ui/react-slot": "^1.2.4", "@radix-ui/react-slot": "^1.2.4",
"@radix-ui/react-switch": "^1.1.4", "@radix-ui/react-switch": "^1.2.6",
"@radix-ui/react-tabs": "^1.1.13", "@radix-ui/react-tabs": "^1.1.13",
"@radix-ui/react-tooltip": "^1.2.8", "@radix-ui/react-tooltip": "^1.2.8",
"@tailwindcss/vite": "^4.1.17", "@tailwindcss/vite": "^4.1.17",
"class-variance-authority": "^0.7.1", "class-variance-authority": "^0.7.1",
"clsx": "^2.1.1", "clsx": "^2.1.1",
"lucide-react": "^0.554.0", "lucide-react": "^0.559.0",
"next-themes": "^0.4.6", "next-themes": "^0.4.6",
"react": "^19.2.0", "react": "^19.2.1",
"react-dom": "^19.2.0", "react-dom": "^19.2.1",
"sonner": "^2.0.7", "sonner": "^2.0.7",
"tailwind-merge": "^3.4.0", "tailwind-merge": "^3.4.0",
"tailwindcss": "^4.1.17" "tailwindcss": "^4.1.17"
}, },
"devDependencies": { "devDependencies": {
"@eslint/js": "^9.39.1", "@eslint/js": "^9.39.1",
"@types/node": "^24.10.1", "@types/node": "^25.0.0",
"@types/react": "^19.2.6", "@types/react": "^19.2.7",
"@types/react-dom": "^19.2.3", "@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1", "@vitejs/plugin-react": "^5.1.2",
"eslint": "^9.39.1", "eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1", "eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24", "eslint-plugin-react-refresh": "^0.4.24",
@@ -48,7 +49,7 @@
"sharp": "^0.34.5", "sharp": "^0.34.5",
"tw-animate-css": "^1.4.0", "tw-animate-css": "^1.4.0",
"typescript": "~5.9.3", "typescript": "~5.9.3",
"typescript-eslint": "^8.47.0", "typescript-eslint": "^8.49.0",
"vite": "^7.2.4" "vite": "^7.2.7"
} }
} }
+1 -1
View File
@@ -1 +1 @@
6d6b26a2fed70996ef14dbc3e325f141 9fa5d67c42a33ac8765a4b51d8bc1bb5
+550 -646
View File
File diff suppressed because it is too large. Load diff
+1133 -50
View File
File diff suppressed because it is too large. Load diff
+254 -104
View File
@@ -28,16 +28,22 @@ import {
} from "@/components/ui/tooltip"; } from "@/components/ui/tooltip";
import { Checkbox } from "@/components/ui/checkbox"; import { Checkbox } from "@/components/ui/checkbox";
import { Spinner } from "@/components/ui/spinner"; import { Spinner } from "@/components/ui/spinner";
import { Trash2, Eye, FileInput, FileOutput, Pencil, Tag, Shuffle, X, Download, StopCircle, Globe, Lock, Bookmark, Heart, Image, Images, Video, Film, FileText, Filter, AlertCircle } from "lucide-react"; import {
DropdownMenu,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuTrigger,
} from "@/components/ui/dropdown-menu";
import { Trash2, FileInput, FileOutput, Pencil, Tag, Shuffle, X, Download, StopCircle, Globe, Lock, Bookmark, Heart, Image, Images, Video, Film, FileText, Filter, AlertCircle, MoreVertical, FileBraces, CloudBackup } from "lucide-react";
import { toastWithSound as toast } from "@/lib/toast-with-sound"; import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { getSettings } from "@/lib/settings"; import { getSettings } from "@/lib/settings";
import { import {
GetAllAccountsFromDB, GetAllAccountsFromDB,
GetAccountFromDB, GetAccountFromDB,
DeleteAccountFromDB, DeleteAccountFromDB,
ClearAllAccountsFromDB,
SaveAccountToDB, SaveAccountToDB,
ExportAccountJSON, ExportAccountJSON,
ExportAccountsTXT,
UpdateAccountGroup, UpdateAccountGroup,
GetAllGroups, GetAllGroups,
DownloadMediaWithMetadata, DownloadMediaWithMetadata,
@@ -96,11 +102,12 @@ interface GroupInfo {
interface DatabaseViewProps { interface DatabaseViewProps {
onBack: () => void; onBack: () => void;
onLoadAccount: (responseJSON: string, username: string) => void; onLoadAccount: (responseJSON: string, username: string) => void;
onUpdateSelected?: (usernames: string[]) => void;
} }
const ITEMS_PER_PAGE = 10; const ITEMS_PER_PAGE = 10;
export function DatabaseView({ onLoadAccount }: DatabaseViewProps) { export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewProps) {
const [accounts, setAccounts] = useState<AccountListItem[]>([]); const [accounts, setAccounts] = useState<AccountListItem[]>([]);
const [loading, setLoading] = useState(true); const [loading, setLoading] = useState(true);
const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set()); const [selectedIds, setSelectedIds] = useState<Set<number>>(new Set());
@@ -230,25 +237,59 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
} }
const settings = getSettings(); const settings = getSettings();
// Check if it's bookmarks or likes by checking account_info.nick or username (for backward compatibility)
const isBookmarks = data.account_info?.nick === "My Bookmarks" || username === "bookmarks";
const isLikes = data.account_info?.nick === "My Likes" || username === "likes";
let outputDir = settings.downloadPath;
if (isBookmarks) {
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
outputDir = `${settings.downloadPath}${separator}My Bookmarks`;
} else if (isLikes) {
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
outputDir = `${settings.downloadPath}${separator}My Likes`;
}
// Use actual username from account_info if available, otherwise use stored username
const actualUsername = data.account_info?.name || username;
setIsDownloading(true); setIsDownloading(true);
setDownloadingAccountId(id); setDownloadingAccountId(id);
setDownloadProgress({ current: 0, total: timeline.length, percent: 0 }); setDownloadProgress({ current: 0, total: timeline.length, percent: 0 });
const request = new main.DownloadMediaWithMetadataRequest({ const request = new main.DownloadMediaWithMetadataRequest({
items: timeline.map((item: { url: string; date: string; tweet_id: string; type: string }) => new main.MediaItemRequest({ items: timeline.map((item: { url: string; date: string; tweet_id: string; type: string; original_filename?: string; author_username?: string }) => new main.MediaItemRequest({
url: item.url, url: item.url,
date: item.date, date: item.date,
tweet_id: item.tweet_id, tweet_id: item.tweet_id,
type: item.type, type: item.type,
original_filename: item.original_filename || "",
author_username: item.author_username || "",
})), })),
output_dir: settings.downloadPath, output_dir: outputDir,
username: username, username: actualUsername,
proxy: settings.proxy || "",
}); });
const response = await DownloadMediaWithMetadata(request); const response = await DownloadMediaWithMetadata(request);
if (response.success) { if (response.success) {
toast.success(`Downloaded ${response.downloaded} files for @${username}`); const parts: string[] = [];
if (response.downloaded > 0) {
parts.push(`${response.downloaded} file${response.downloaded !== 1 ? 's' : ''} downloaded`);
}
if (response.skipped > 0) {
parts.push(`${response.skipped} file${response.skipped !== 1 ? 's' : ''} already exist${response.skipped !== 1 ? '' : 's'}`);
}
if (response.failed > 0) {
parts.push(`${response.failed} failed`);
}
const message = parts.length > 0 ? `${parts.join(', ')} for @${username}` : `Download completed for @${username}`;
// Use info toast if only skipped files (no downloaded, no failed)
if (response.downloaded === 0 && response.failed === 0 && response.skipped > 0) {
toast.info(message);
} else {
toast.success(message);
}
} else { } else {
toast.error(response.message || "Download failed"); toast.error(response.message || "Download failed");
} }
@@ -287,6 +328,7 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
const settings = getSettings(); const settings = getSettings();
let totalDownloaded = 0; let totalDownloaded = 0;
let totalSkipped = 0;
let downloadedAccounts = 0; let downloadedAccounts = 0;
for (let i = 0; i < idsToDownload.length; i++) { for (let i = 0; i < idsToDownload.length; i++) {
@@ -318,20 +360,38 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
setDownloadProgress({ current: 0, total: timeline.length, percent: 0 }); setDownloadProgress({ current: 0, total: timeline.length, percent: 0 });
// Check if it's bookmarks or likes by checking account_info.nick or username (for backward compatibility)
const isBookmarks = data.account_info?.nick === "My Bookmarks" || account.username === "bookmarks";
const isLikes = data.account_info?.nick === "My Likes" || account.username === "likes";
let outputDir = settings.downloadPath;
if (isBookmarks) {
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
outputDir = `${settings.downloadPath}${separator}My Bookmarks`;
} else if (isLikes) {
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
outputDir = `${settings.downloadPath}${separator}My Likes`;
}
// Use actual username from account_info if available, otherwise use stored username
const actualUsername = data.account_info?.name || account.username;
const request = new main.DownloadMediaWithMetadataRequest({ const request = new main.DownloadMediaWithMetadataRequest({
items: timeline.map((item: { url: string; date: string; tweet_id: string; type: string }) => new main.MediaItemRequest({ items: timeline.map((item: { url: string; date: string; tweet_id: string; type: string; author_username?: string; original_filename?: string }) => new main.MediaItemRequest({
url: item.url, url: item.url,
date: item.date, date: item.date,
tweet_id: item.tweet_id, tweet_id: item.tweet_id,
type: item.type, type: item.type,
author_username: item.author_username || "",
original_filename: item.original_filename || "",
})), })),
output_dir: settings.downloadPath, output_dir: outputDir,
username: account.username, username: actualUsername,
proxy: settings.proxy || "",
}); });
const response = await DownloadMediaWithMetadata(request); const response = await DownloadMediaWithMetadata(request);
if (response.success) { if (response.success) {
totalDownloaded += response.downloaded; totalDownloaded += response.downloaded;
totalSkipped += response.skipped || 0;
downloadedAccounts++; downloadedAccounts++;
} }
} catch (error) { } catch (error) {
@@ -345,8 +405,22 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
setBulkDownloadCurrent(0); setBulkDownloadCurrent(0);
setBulkDownloadTotal(0); setBulkDownloadTotal(0);
if (totalDownloaded > 0 && !stopBulkDownloadRef.current) { if ((totalDownloaded > 0 || totalSkipped > 0) && !stopBulkDownloadRef.current) {
toast.success(`Downloaded ${totalDownloaded} files from ${downloadedAccounts} accounts`); const parts: string[] = [];
if (totalDownloaded > 0) {
parts.push(`${totalDownloaded} file${totalDownloaded !== 1 ? 's' : ''} downloaded`);
}
if (totalSkipped > 0) {
parts.push(`${totalSkipped} file${totalSkipped !== 1 ? 's' : ''} already exist${totalSkipped !== 1 ? '' : 's'}`);
}
const message = parts.length > 0 ? `${parts.join(', ')} from ${downloadedAccounts} account${downloadedAccounts !== 1 ? 's' : ''}` : `Download completed from ${downloadedAccounts} account${downloadedAccounts !== 1 ? 's' : ''}`;
// Use info toast if only skipped files (no downloaded)
if (totalDownloaded === 0 && totalSkipped > 0) {
toast.info(message);
} else {
toast.success(message);
}
} }
}; };
@@ -375,7 +449,7 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
} }
}; };
const handleExport = async () => { const handleExportJSON = async () => {
const idsToExport = selectedIds.size > 0 ? Array.from(selectedIds) : accounts.map((a) => a.id); const idsToExport = selectedIds.size > 0 ? Array.from(selectedIds) : accounts.map((a) => a.id);
if (idsToExport.length === 0) { if (idsToExport.length === 0) {
@@ -398,6 +472,34 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
} }
}; };
const handleExportTXT = async () => {
const idsToExport = selectedIds.size > 0 ? Array.from(selectedIds) : accounts.map((a) => a.id);
if (idsToExport.length === 0) {
toast.error("No accounts to export");
return;
}
const settings = getSettings();
const outputDir = settings.downloadPath || "";
try {
await ExportAccountsTXT(idsToExport, outputDir);
toast.success(`Exported ${idsToExport.length} account(s) to ${outputDir}\\twitterxmediabatchdownloader_backups\\twitterxmediabatchdownloader_multiple.txt`);
} catch (error) {
toast.error("Failed to export");
}
};
// Check if any selected accounts are private (bookmarks/likes)
const hasPrivateAccountSelected = () => {
if (selectedIds.size === 0) return false;
return Array.from(selectedIds).some((id) => {
const account = accounts.find((a) => a.id === id);
return account && isPrivateAccount(account.username);
});
};
const handleImport = () => { const handleImport = () => {
const input = document.createElement("input"); const input = document.createElement("input");
input.type = "file"; input.type = "file";
@@ -522,29 +624,29 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
<div className="flex items-center gap-3"> <div className="flex items-center gap-3">
<h2 className="text-2xl font-bold">Saved Accounts</h2> <h2 className="text-2xl font-bold">Saved Accounts</h2>
{/* Public/Private Toggle */} {/* Public/Private Toggle */}
<div className="flex gap-1 p-1 bg-muted rounded-lg"> <div className="flex gap-0.5 p-0.5 bg-muted rounded-lg">
<button <button
type="button" type="button"
onClick={() => setViewMode("public")} onClick={() => setViewMode("public")}
className={`flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium transition-all ${ className={`flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all ${
viewMode === "public" viewMode === "public"
? "bg-background text-foreground shadow-sm" ? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground" : "text-muted-foreground hover:text-foreground"
}`} }`}
> >
<Globe className="h-4 w-4" /> <Globe className="h-3 w-3" />
Public ({publicAccounts.length}) Public ({publicAccounts.length})
</button> </button>
<button <button
type="button" type="button"
onClick={() => setViewMode("private")} onClick={() => setViewMode("private")}
className={`flex items-center gap-2 px-3 py-1.5 rounded-md text-sm font-medium transition-all ${ className={`flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all ${
viewMode === "private" viewMode === "private"
? "bg-background text-foreground shadow-sm" ? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground" : "text-muted-foreground hover:text-foreground"
}`} }`}
> >
<Lock className="h-4 w-4" /> <Lock className="h-3 w-3" />
Private ({privateAccounts.length}) Private ({privateAccounts.length})
</button> </button>
</div> </div>
@@ -558,13 +660,62 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
</TooltipTrigger> </TooltipTrigger>
<TooltipContent>Import JSON</TooltipContent> <TooltipContent>Import JSON</TooltipContent>
</Tooltip> </Tooltip>
<DropdownMenu>
<Tooltip>
<TooltipTrigger asChild>
<DropdownMenuTrigger asChild>
<Button variant="outline" size="icon" disabled={selectedIds.size === 0}>
<FileOutput className="h-4 w-4" />
</Button>
</DropdownMenuTrigger>
</TooltipTrigger>
<TooltipContent>Export Selected ({selectedIds.size})</TooltipContent>
</Tooltip>
<DropdownMenuContent align="end">
<DropdownMenuItem onClick={handleExportJSON}>
<FileBraces className="h-4 w-4 mr-2" />
Export JSON
</DropdownMenuItem>
<DropdownMenuItem onClick={handleExportTXT} disabled={hasPrivateAccountSelected()}>
<FileText className="h-4 w-4 mr-2" />
Export TXT
</DropdownMenuItem>
</DropdownMenuContent>
</DropdownMenu>
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<Button variant="outline" size="icon" onClick={handleExport} disabled={selectedIds.size === 0}> <Button
<FileOutput className="h-4 w-4" /> variant="outline"
size="icon"
onClick={() => {
const idsToUpdate = selectedIds.size > 0 ? Array.from(selectedIds) : accounts.map((a) => a.id);
if (idsToUpdate.length === 0) {
toast.error("No accounts selected");
return;
}
const usernames = idsToUpdate
.map((id) => {
const account = accounts.find((a) => a.id === id);
return account?.username;
})
.filter((username): username is string => !!username);
if (usernames.length === 0) {
toast.error("No valid usernames found");
return;
}
if (onUpdateSelected) {
onUpdateSelected(usernames);
toast.success(`Added ${usernames.length} account(s) to multiple fetch`);
}
}}
disabled={selectedIds.size === 0 || hasPrivateAccountSelected()}
>
<CloudBackup className="h-4 w-4" />
</Button> </Button>
</TooltipTrigger> </TooltipTrigger>
<TooltipContent>Export Selected</TooltipContent> <TooltipContent>Update Selected ({selectedIds.size})</TooltipContent>
</Tooltip> </Tooltip>
{isBulkDownloading ? ( {isBulkDownloading ? (
<Tooltip> <Tooltip>
@@ -589,12 +740,12 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<DialogTrigger asChild> <DialogTrigger asChild>
<Button variant="destructive" size="icon" disabled={accounts.length === 0}> <Button variant="destructive" size="icon" disabled={baseAccounts.length === 0}>
<Trash2 className="h-4 w-4" /> <Trash2 className="h-4 w-4" />
</Button> </Button>
</DialogTrigger> </DialogTrigger>
</TooltipTrigger> </TooltipTrigger>
<TooltipContent>Clear All</TooltipContent> <TooltipContent>Clear All {viewMode === "public" ? "Public" : "Private"}</TooltipContent>
</Tooltip> </Tooltip>
<DialogContent className="[&>button]:hidden"> <DialogContent className="[&>button]:hidden">
<div className="absolute right-4 top-4"> <div className="absolute right-4 top-4">
@@ -608,9 +759,9 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
</Button> </Button>
</div> </div>
<DialogHeader> <DialogHeader>
<DialogTitle>Clear All Accounts?</DialogTitle> <DialogTitle>Clear All {viewMode === "public" ? "Public" : "Private"} Accounts?</DialogTitle>
<DialogDescription> <DialogDescription>
This will permanently delete all {formatNumberWithComma(accounts.length)} saved accounts. This action cannot be undone. This will permanently delete all {formatNumberWithComma(baseAccounts.length)} {viewMode === "public" ? "public" : "private"} saved accounts. This action cannot be undone.
</DialogDescription> </DialogDescription>
</DialogHeader> </DialogHeader>
<DialogFooter> <DialogFooter>
@@ -618,8 +769,12 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
variant="destructive" variant="destructive"
onClick={async () => { onClick={async () => {
try { try {
await ClearAllAccountsFromDB(); // Delete only accounts matching the current view mode
toast.success("All accounts deleted"); const accountsToDelete = baseAccounts.map((acc) => acc.id);
for (const id of accountsToDelete) {
await DeleteAccountFromDB(id);
}
toast.success(`All ${viewMode === "public" ? "public" : "private"} accounts deleted`);
setClearAllDialogOpen(false); setClearAllDialogOpen(false);
loadAccounts(); loadAccounts();
} catch (error) { } catch (error) {
@@ -627,7 +782,7 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
} }
}} }}
> >
Delete All Delete All {viewMode === "public" ? "Public" : "Private"}
</Button> </Button>
</DialogFooter> </DialogFooter>
</DialogContent> </DialogContent>
@@ -754,7 +909,10 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
{(currentPage - 1) * ITEMS_PER_PAGE + index + 1} {(currentPage - 1) * ITEMS_PER_PAGE + index + 1}
</span> </span>
{isPrivateAccount(account.username) ? ( {isPrivateAccount(account.username) ? (
<div className="w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center"> <div
className="w-12 h-12 rounded-full bg-primary/10 flex items-center justify-center cursor-pointer hover:bg-primary/20 transition-colors"
onClick={() => handleView(account.id, account.username)}
>
{account.username === "bookmarks" ? ( {account.username === "bookmarks" ? (
<Bookmark className="h-6 w-6 text-primary" /> <Bookmark className="h-6 w-6 text-primary" />
) : ( ) : (
@@ -765,7 +923,8 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
<img <img
src={account.profile_image} src={account.profile_image}
alt={account.name} alt={account.name}
className="w-12 h-12 rounded-full" className="w-12 h-12 rounded-full cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => handleView(account.id, account.username)}
/> />
)} )}
<div className="flex-1 min-w-0"> <div className="flex-1 min-w-0">
@@ -809,57 +968,14 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
</Badge> </Badge>
)} )}
</div> </div>
<div className="text-sm text-muted-foreground">@{account.username}</div> {!isPrivateAccount(account.username) && (
<div className="text-sm text-muted-foreground">@{account.username}</div>
)}
<div className="text-sm text-muted-foreground"> <div className="text-sm text-muted-foreground">
{account.last_fetched} {getRelativeTime(account.last_fetched)} {account.last_fetched} {getRelativeTime(account.last_fetched)}
</div> </div>
</div> </div>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="icon"
onClick={() => handleEditGroup(account)}
>
<Pencil className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Edit Group</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="icon"
onClick={() => handleView(account.id, account.username)}
>
<Eye className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>View</TooltipContent>
</Tooltip>
<Tooltip>
<TooltipTrigger asChild>
<Button
variant="outline"
size="icon"
onClick={async () => {
const settings = getSettings();
const outputDir = settings.downloadPath || "";
try {
await ExportAccountJSON(account.id, outputDir);
toast.success(`Exported @${account.username} to ${outputDir}\\twitterxmediabatchdownloader_backups`);
} catch (error) {
toast.error("Failed to export");
}
}}
>
<FileOutput className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Export JSON</TooltipContent>
</Tooltip>
{downloadingAccountId === account.id ? ( {downloadingAccountId === account.id ? (
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>
@@ -892,41 +1008,75 @@ export function DatabaseView({ onLoadAccount }: DatabaseViewProps) {
<TooltipContent>Download All Media</TooltipContent> <TooltipContent>Download All Media</TooltipContent>
</Tooltip> </Tooltip>
)} )}
<Dialog> <DropdownMenu>
<Tooltip> <Tooltip>
<TooltipTrigger asChild> <TooltipTrigger asChild>
<DialogTrigger asChild> <DropdownMenuTrigger asChild>
<Button variant="destructive" size="icon"> <Button variant="outline" size="icon">
<Trash2 className="h-4 w-4" /> <MoreVertical className="h-4 w-4" />
</Button> </Button>
</DialogTrigger> </DropdownMenuTrigger>
</TooltipTrigger> </TooltipTrigger>
<TooltipContent>Delete</TooltipContent> <TooltipContent>More Options</TooltipContent>
</Tooltip> </Tooltip>
<DialogContent className="[&>button]:hidden"> <DropdownMenuContent align="end">
<div className="absolute right-4 top-4"> <DropdownMenuItem onClick={() => handleEditGroup(account)}>
<Pencil className="h-4 w-4 mr-2" />
Edit Group
</DropdownMenuItem>
<DropdownMenuItem
onClick={async () => {
const settings = getSettings();
const outputDir = settings.downloadPath || "";
try {
await ExportAccountJSON(account.id, outputDir);
toast.success(`Exported @${account.username} to ${outputDir}\\twitterxmediabatchdownloader_backups`);
} catch (error) {
toast.error("Failed to export");
}
}}
>
<FileOutput className="h-4 w-4 mr-2" />
Export JSON
</DropdownMenuItem>
<Dialog>
<DialogTrigger asChild> <DialogTrigger asChild>
<Button variant="ghost" size="icon" className="h-6 w-6 opacity-70 hover:opacity-100"> <DropdownMenuItem
<X className="h-4 w-4" /> onSelect={(e: Event) => {
</Button> e.preventDefault();
}}
className="text-destructive focus:text-destructive"
>
<Trash2 className="h-4 w-4 mr-2" />
Delete
</DropdownMenuItem>
</DialogTrigger> </DialogTrigger>
</div> <DialogContent className="[&>button]:hidden">
<DialogHeader> <div className="absolute right-4 top-4">
<DialogTitle>Delete @{account.username}?</DialogTitle> <DialogTrigger asChild>
<DialogDescription> <Button variant="ghost" size="icon" className="h-6 w-6 opacity-70 hover:opacity-100">
This will permanently delete the saved data for this account. <X className="h-4 w-4" />
</DialogDescription> </Button>
</DialogHeader> </DialogTrigger>
<DialogFooter> </div>
<Button <DialogHeader>
variant="destructive" <DialogTitle>Delete @{account.username}?</DialogTitle>
onClick={() => handleDelete(account.id, account.username)} <DialogDescription>
> This will permanently delete the saved data for this account.
Delete </DialogDescription>
</Button> </DialogHeader>
</DialogFooter> <DialogFooter>
</DialogContent> <Button
</Dialog> variant="destructive"
onClick={() => handleDelete(account.id, account.username)}
>
Delete
</Button>
</DialogFooter>
</DialogContent>
</Dialog>
</DropdownMenuContent>
</DropdownMenu>
</div> </div>
</div> </div>
{/* Progress bar for this account */} {/* Progress bar for this account */}
-132
View File
@@ -1,132 +0,0 @@
import { useState, useEffect, useRef } from "react";
import { Bug, Trash2, X, Copy, Check } from "lucide-react";
import { Button } from "@/components/ui/button";
import {
Dialog,
DialogContent,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import { logger, type LogEntry } from "@/lib/logger";
const levelColors: Record<string, string> = {
info: "text-blue-500",
success: "text-green-500",
warning: "text-yellow-500",
error: "text-red-500",
debug: "text-gray-500",
};
function formatTime(date: Date): string {
return date.toLocaleTimeString("en-US", {
hour12: false,
hour: "2-digit",
minute: "2-digit",
second: "2-digit",
});
}
export function DebugLogger() {
const [open, setOpen] = useState(false);
const [logs, setLogs] = useState<LogEntry[]>([]);
const [copied, setCopied] = useState(false);
const scrollRef = useRef<HTMLDivElement>(null);
useEffect(() => {
const unsubscribe = logger.subscribe(() => {
setLogs(logger.getLogs());
});
setLogs(logger.getLogs());
return () => {
unsubscribe();
};
}, []);
useEffect(() => {
if (scrollRef.current) {
scrollRef.current.scrollTop = scrollRef.current.scrollHeight;
}
}, [logs]);
const handleClear = () => {
logger.clear();
};
const handleCopy = async () => {
const logText = logs
.map((log) => `[${formatTime(log.timestamp)}] [${log.level}] ${log.message}`)
.join("\n");
try {
await navigator.clipboard.writeText(logText);
setCopied(true);
setTimeout(() => setCopied(false), 500);
} catch (err) {
console.error("Failed to copy logs:", err);
}
};
return (
<Dialog open={open} onOpenChange={setOpen}>
<DialogTrigger asChild>
<Button
variant="ghost"
size="icon"
className="h-6 w-6 opacity-50 hover:opacity-100"
>
<Bug className="h-3.5 w-3.5" />
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[600px] max-h-[80vh] p-6 [&>button]:hidden">
<DialogTitle className="text-sm font-medium">Debug Logs</DialogTitle>
<div className="absolute right-4 top-4 flex items-center gap-1">
<Button
variant="ghost"
size="icon"
className="h-6 w-6 opacity-70 hover:opacity-100"
onClick={handleCopy}
disabled={logs.length === 0}
>
{copied ? <Check className="h-4 w-4" /> : <Copy className="h-4 w-4" />}
</Button>
<Button
variant="ghost"
size="icon"
className="h-6 w-6 opacity-70 hover:opacity-100"
onClick={handleClear}
>
<Trash2 className="h-4 w-4" />
</Button>
<Button
variant="ghost"
size="icon"
className="h-6 w-6 opacity-70 hover:opacity-100"
onClick={() => setOpen(false)}
>
<X className="h-4 w-4" />
</Button>
</div>
<div
ref={scrollRef}
className="h-[400px] overflow-y-auto bg-muted/50 rounded-md p-3 font-mono text-xs"
>
{logs.length === 0 ? (
<p className="text-muted-foreground lowercase">no logs yet...</p>
) : (
logs.map((log, i) => (
<div key={i} className="flex gap-2 py-0.5">
<span className="text-muted-foreground shrink-0">
[{formatTime(log.timestamp)}]
</span>
<span className={`shrink-0 w-16 ${levelColors[log.level]}`}>
[{log.level}]
</span>
<span className="break-all">{log.message}</span>
</div>
))
)}
</div>
</DialogContent>
</Dialog>
);
}
+198 -58
View File
@@ -72,21 +72,33 @@ interface MediaListProps {
timeline: TimelineEntry[]; timeline: TimelineEntry[];
totalUrls: number; totalUrls: number;
fetchedMediaType?: string; fetchedMediaType?: string;
newMediaCount?: number | null;
} }
function getThumbnailUrl(url: string): string { function getThumbnailUrl(url: string): string {
// For animated_gif: video.twimg.com/tweet_video/XXX.mp4 -> pbs.twimg.com/tweet_video_thumb/XXX?format=jpg&name=360x360
if (url.includes("video.twimg.com/tweet_video/")) {
// Extract filename from URL (e.g., GzstJyDbIAAPuX9.mp4 -> GzstJyDbIAAPuX9)
const match = url.match(/tweet_video\/([^\/]+)\.mp4/);
if (match && match[1]) {
const filename = match[1];
return `https://pbs.twimg.com/tweet_video_thumb/${filename}?format=jpg&name=360x360`;
}
}
// For photos: pbs.twimg.com/media/XXX -> use 360x360 for consistency
if (url.includes("pbs.twimg.com/media/")) { if (url.includes("pbs.twimg.com/media/")) {
if (url.includes("?format=")) { if (url.includes("?format=")) {
if (url.includes("&name=")) { if (url.includes("&name=")) {
const parts = url.split("&name="); const parts = url.split("&name=");
return parts[0] + "&name=thumb"; return parts[0] + "&name=360x360";
} }
return url + "&name=thumb"; return url + "&name=360x360";
} }
if (url.includes("?")) { if (url.includes("?")) {
return url + "&name=thumb"; return url + "&name=360x360";
} }
return url + "?format=jpg&name=thumb"; return url + "?format=jpg&name=360x360";
} }
return url; return url;
} }
@@ -209,6 +221,7 @@ export function MediaList({
timeline, timeline,
totalUrls, totalUrls,
fetchedMediaType = "all", fetchedMediaType = "all",
newMediaCount = null,
}: MediaListProps) { }: MediaListProps) {
const [selectedItems, setSelectedItems] = useState<Set<number>>(new Set()); const [selectedItems, setSelectedItems] = useState<Set<number>>(new Set());
const [sortBy, setSortBy] = useState<string>("date-desc"); const [sortBy, setSortBy] = useState<string>("date-desc");
@@ -227,6 +240,9 @@ export function MediaList({
const [failedItems, setFailedItems] = useState<Set<string>>(new Set()); const [failedItems, setFailedItems] = useState<Set<string>>(new Set());
const [skippedItems, setSkippedItems] = useState<Set<string>>(new Set()); const [skippedItems, setSkippedItems] = useState<Set<string>>(new Set());
const [downloadingItem, setDownloadingItem] = useState<string | null>(null); const [downloadingItem, setDownloadingItem] = useState<string | null>(null);
// Lazy loading: start with 10 thumbnails, load more on scroll
const [visibleCount, setVisibleCount] = useState<number>(10);
const loadMoreRef = useRef<HTMLDivElement>(null);
// Listen for scroll to show/hide scroll-to-top button // Listen for scroll to show/hide scroll-to-top button
useEffect(() => { useEffect(() => {
@@ -237,6 +253,69 @@ export function MediaList({
return () => window.removeEventListener("scroll", handleScroll); return () => window.removeEventListener("scroll", handleScroll);
}, []); }, []);
// Filter and sort timeline
const filteredTimeline = useMemo(() => {
let filtered = [...timeline];
// Filter by media type
if (filterType !== "all") {
filtered = filtered.filter((item) => {
if (filterType === "photo") return item.type === "photo";
if (filterType === "video") return item.type === "video";
if (filterType === "gif") return item.type === "animated_gif" || item.type === "gif";
if (filterType === "text") return item.type === "text";
return true;
});
}
// Sort
filtered.sort((a, b) => {
if (sortBy === "date-desc") {
return new Date(b.date).getTime() - new Date(a.date).getTime();
} else if (sortBy === "date-asc") {
return new Date(a.date).getTime() - new Date(b.date).getTime();
} else if (sortBy === "tweet-id-desc") {
return Number(b.tweet_id) - Number(a.tweet_id);
} else if (sortBy === "tweet-id-asc") {
return Number(a.tweet_id) - Number(b.tweet_id);
}
return 0;
});
return filtered;
}, [timeline, filterType, sortBy]);
// Reset visible count when filtered timeline changes
useEffect(() => {
setVisibleCount(10);
}, [filteredTimeline.length]);
// Intersection Observer for lazy loading thumbnails
useEffect(() => {
if (!loadMoreRef.current) return;
const observer = new IntersectionObserver(
(entries) => {
if (entries[0].isIntersecting) {
setVisibleCount((prev) => {
// Load 10 more items at a time
const filteredLength = filteredTimeline.length;
return Math.min(prev + 10, filteredLength);
});
}
},
{ threshold: 0.1 }
);
observer.observe(loadMoreRef.current);
return () => {
if (loadMoreRef.current) {
observer.unobserve(loadMoreRef.current);
}
};
}, [filteredTimeline.length]);
const scrollToTop = () => { const scrollToTop = () => {
window.scrollTo({ top: 0, behavior: "smooth" }); window.scrollTo({ top: 0, behavior: "smooth" });
}; };
@@ -328,31 +407,6 @@ export function MediaList({
}; };
}, []); }, []);
// Filter and sort timeline
const filteredTimeline = useMemo(() => {
let filtered = [...timeline];
// Filter by media type
if (filterType !== "all") {
filtered = filtered.filter((item) => {
if (filterType === "photo") return item.type === "photo";
if (filterType === "video") return item.type === "video";
if (filterType === "gif") return item.type === "gif" || item.type === "animated_gif";
if (filterType === "text") return item.type === "text";
return true;
});
}
// Sort
if (sortBy === "date-asc") {
filtered.sort((a, b) => new Date(a.date).getTime() - new Date(b.date).getTime());
} else {
filtered.sort((a, b) => new Date(b.date).getTime() - new Date(a.date).getTime());
}
return filtered;
}, [timeline, sortBy, filterType]);
const goToPrevious = () => { const goToPrevious = () => {
if (previewIndex !== null && previewIndex > 0) { if (previewIndex !== null && previewIndex > 0) {
setPreviewIndex(previewIndex - 1); setPreviewIndex(previewIndex - 1);
@@ -407,9 +461,21 @@ export function MediaList({
setSelectedItems(newSelected); setSelectedItems(newSelected);
}; };
const handleDownload = async () => { // Helper function to get output directory (adds "My Bookmarks" or "My Likes" folder)
const getOutputDir = (): string => {
const settings = getSettings(); const settings = getSettings();
const isBookmarks = accountInfo.nick === "My Bookmarks";
const isLikes = accountInfo.nick === "My Likes";
if (isBookmarks || isLikes) {
// Use path separator that backend will normalize (filepath.Join handles both / and \)
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
const folderName = isBookmarks ? "My Bookmarks" : "My Likes";
return `${settings.downloadPath}${separator}${folderName}`;
}
return settings.downloadPath;
};
const handleDownload = async () => {
// Get items with their original indices in filteredTimeline // Get items with their original indices in filteredTimeline
const itemsWithIndices = selectedItems.size > 0 const itemsWithIndices = selectedItems.size > 0
? Array.from(selectedItems).map((i) => ({ item: filteredTimeline[i], originalIndex: i })) ? Array.from(selectedItems).map((i) => ({ item: filteredTimeline[i], originalIndex: i }))
@@ -432,6 +498,7 @@ export function MediaList({
logger.info(`Starting download of ${itemsWithIndices.length} files...`); logger.info(`Starting download of ${itemsWithIndices.length} files...`);
try { try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({ const request = new main.DownloadMediaWithMetadataRequest({
items: itemsWithIndices.map(({ item }) => new main.MediaItemRequest({ items: itemsWithIndices.map(({ item }) => new main.MediaItemRequest({
url: item.url, url: item.url,
@@ -439,15 +506,36 @@ export function MediaList({
tweet_id: item.tweet_id, tweet_id: item.tweet_id,
type: item.type, type: item.type,
content: item.content || "", content: item.content || "",
original_filename: item.original_filename || "",
author_username: item.author_username || "",
})), })),
output_dir: settings.downloadPath, output_dir: getOutputDir(),
username: accountInfo.name, username: accountInfo.name,
proxy: settings.proxy || "",
}); });
const response = await DownloadMediaWithMetadata(request); const response = await DownloadMediaWithMetadata(request);
if (response.success) { if (response.success) {
logger.success(`Downloaded ${response.downloaded} files`); const parts: string[] = [];
toast.success(`${response.downloaded} files downloaded`); if (response.downloaded > 0) {
parts.push(`${response.downloaded} file${response.downloaded !== 1 ? 's' : ''} downloaded`);
}
if (response.skipped > 0) {
parts.push(`${response.skipped} file${response.skipped !== 1 ? 's' : ''} already exist${response.skipped !== 1 ? '' : 's'}`);
}
if (response.failed > 0) {
parts.push(`${response.failed} failed`);
}
const message = parts.length > 0 ? parts.join(', ') : 'Download completed';
// Use info toast if only skipped files (no downloaded, no failed)
if (response.downloaded === 0 && response.failed === 0 && response.skipped > 0) {
logger.info(message);
toast.info(message);
} else {
logger.success(message);
toast.success(message);
}
setHasDownloaded(true); setHasDownloaded(true);
// Check if there are GIFs and FFmpeg is installed // Check if there are GIFs and FFmpeg is installed
@@ -486,10 +574,22 @@ export function MediaList({
const handleOpenFolder = async () => { const handleOpenFolder = async () => {
const settings = getSettings(); const settings = getSettings();
// Build path - backend will handle path separators with filepath.Clean const isBookmarks = accountInfo.nick === "My Bookmarks";
const folderPath = settings.downloadPath const isLikes = accountInfo.nick === "My Likes";
? `${settings.downloadPath}/${accountInfo.name}`
: accountInfo.name; // Build path - for bookmarks/likes, use the folder structure
let folderPath: string;
if (isBookmarks || isLikes) {
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
const folderName = isBookmarks ? "My Bookmarks" : "My Likes";
folderPath = settings.downloadPath
? `${settings.downloadPath}${separator}${folderName}`
: folderName;
} else {
folderPath = settings.downloadPath
? `${settings.downloadPath}/${accountInfo.name}`
: accountInfo.name;
}
try { try {
await OpenFolder(folderPath); await OpenFolder(folderPath);
@@ -508,8 +608,18 @@ export function MediaList({
const handleConvertGifs = async () => { const handleConvertGifs = async () => {
const settings = getSettings(); const settings = getSettings();
// Use forward slash for cross-platform compatibility (Go's filepath.Join handles it) const isBookmarks = accountInfo.nick === "My Bookmarks";
const folderPath = `${settings.downloadPath}/${accountInfo.name}`; const isLikes = accountInfo.nick === "My Likes";
// Build path - for bookmarks/likes, use the folder structure
let folderPath: string;
if (isBookmarks || isLikes) {
const separator = settings.downloadPath.includes("/") ? "/" : "\\";
const folderName = isBookmarks ? "My Bookmarks" : "My Likes";
folderPath = `${settings.downloadPath}${separator}${folderName}`;
} else {
folderPath = `${settings.downloadPath}/${accountInfo.name}`;
}
setIsConverting(true); setIsConverting(true);
logger.info("Converting GIFs..."); logger.info("Converting GIFs...");
@@ -542,20 +652,28 @@ export function MediaList({
return ( return (
<div className="space-y-4"> <div className="space-y-4">
{/* Account Info Card */} {/* Account Info Card */}
{accountInfo.name === "bookmarks" ? ( {accountInfo.name === "bookmarks" || accountInfo.name === "likes" ? (
// Bookmarks mode - simple card without account info // Bookmarks/Likes mode - simple card without account info
<div className="flex items-center gap-4 p-4 bg-muted/50 rounded-lg"> <div className="flex items-center gap-4 p-4 bg-muted/50 rounded-lg">
<div className="w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center"> <div className="w-16 h-16 rounded-full bg-primary/10 flex items-center justify-center">
<Bookmark className="h-8 w-8 text-primary" /> {accountInfo.name === "bookmarks" ? (
<Bookmark className="h-8 w-8 text-primary" />
) : (
<Heart className="h-8 w-8 text-primary" />
)}
</div> </div>
<div className="flex-1"> <div className="flex-1">
<h2 className="text-xl font-semibold">My Bookmarks</h2> <h2 className="text-xl font-semibold">{accountInfo.nick}</h2>
<p className="text-sm text-muted-foreground mt-1">
Your saved tweets from various accounts
</p>
</div> </div>
<div className="text-right"> <div className="text-right">
<div className="text-2xl font-bold text-primary">{formatNumberWithComma(totalUrls)}</div> <div className="flex items-center justify-end gap-2">
{newMediaCount !== null && newMediaCount > 0 && (
<div className="text-lg font-semibold text-green-600 dark:text-green-400 animate-in fade-in slide-in-from-left-2 duration-300">
{formatNumberWithComma(newMediaCount)}+
</div>
)}
<div className="text-2xl font-bold text-primary">{formatNumberWithComma(totalUrls)}</div>
</div>
<div className="text-sm text-muted-foreground">items found</div> <div className="text-sm text-muted-foreground">items found</div>
</div> </div>
</div> </div>
@@ -594,7 +712,14 @@ export function MediaList({
</div> </div>
</div> </div>
<div className="text-right"> <div className="text-right">
<div className="text-2xl font-bold text-primary">{formatNumberWithComma(totalUrls)}</div> <div className="flex items-center justify-end gap-2">
{newMediaCount !== null && newMediaCount > 0 && (
<div className="text-lg font-semibold text-green-600 dark:text-green-400 animate-in fade-in slide-in-from-left-2 duration-300">
{formatNumberWithComma(newMediaCount)}+
</div>
)}
<div className="text-2xl font-bold text-primary">{formatNumberWithComma(totalUrls)}</div>
</div>
<div className="text-sm text-muted-foreground">items found</div> <div className="text-sm text-muted-foreground">items found</div>
</div> </div>
</div> </div>
@@ -745,7 +870,7 @@ export function MediaList({
{/* Media Grid/List */} {/* Media Grid/List */}
{viewMode === "list" ? ( {viewMode === "list" ? (
<div className="space-y-2"> <div className="space-y-2">
{filteredTimeline.map((item, index) => { {filteredTimeline.slice(0, visibleCount).map((item, index) => {
const isSelected = selectedItems.has(index); const isSelected = selectedItems.has(index);
const itemKey = getItemKey(item); const itemKey = getItemKey(item);
const isItemDownloaded = downloadedItems.has(itemKey); const isItemDownloaded = downloadedItems.has(itemKey);
@@ -770,7 +895,7 @@ export function MediaList({
className="w-16 h-16 rounded overflow-hidden bg-muted shrink-0 cursor-pointer hover:opacity-80 transition-opacity" className="w-16 h-16 rounded overflow-hidden bg-muted shrink-0 cursor-pointer hover:opacity-80 transition-opacity"
onClick={() => openPreview(index)} onClick={() => openPreview(index)}
> >
{item.type === "photo" ? ( {item.type === "photo" || item.type === "animated_gif" || item.type === "gif" ? (
<img <img
src={getThumbnailUrl(item.url)} src={getThumbnailUrl(item.url)}
alt="" alt=""
@@ -828,10 +953,10 @@ export function MediaList({
size="icon" size="icon"
variant="default" variant="default"
onClick={async () => { onClick={async () => {
const settings = getSettings();
setDownloadingItem(itemKey); setDownloadingItem(itemKey);
currentDownloadingItemKeyRef.current = itemKey; currentDownloadingItemKeyRef.current = itemKey;
try { try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({ const request = new main.DownloadMediaWithMetadataRequest({
items: [new main.MediaItemRequest({ items: [new main.MediaItemRequest({
url: item.url, url: item.url,
@@ -839,9 +964,12 @@ export function MediaList({
tweet_id: item.tweet_id, tweet_id: item.tweet_id,
type: item.type, type: item.type,
content: item.content || "", content: item.content || "",
original_filename: item.original_filename || "",
author_username: item.author_username || "",
})], })],
output_dir: settings.downloadPath, output_dir: getOutputDir(),
username: accountInfo.name, username: accountInfo.name,
proxy: settings.proxy || "",
}); });
const response = await DownloadMediaWithMetadata(request); const response = await DownloadMediaWithMetadata(request);
if (response.success) { if (response.success) {
@@ -903,7 +1031,7 @@ export function MediaList({
</div> </div>
) : ( ) : (
<div className={`grid gap-3 ${viewMode === "large" ? "grid-cols-4" : "grid-cols-6"}`}> <div className={`grid gap-3 ${viewMode === "large" ? "grid-cols-4" : "grid-cols-6"}`}>
{filteredTimeline.map((item, index) => { {filteredTimeline.slice(0, visibleCount).map((item, index) => {
const isSelected = selectedItems.has(index); const isSelected = selectedItems.has(index);
const itemKey = getItemKey(item); const itemKey = getItemKey(item);
const isItemDownloaded = downloadedItems.has(itemKey); const isItemDownloaded = downloadedItems.has(itemKey);
@@ -923,7 +1051,7 @@ export function MediaList({
className="aspect-square bg-muted relative cursor-pointer" className="aspect-square bg-muted relative cursor-pointer"
onClick={() => openPreview(index)} onClick={() => openPreview(index)}
> >
{item.type === "photo" ? ( {item.type === "photo" || item.type === "animated_gif" || item.type === "gif" ? (
<img <img
src={getThumbnailUrl(item.url)} src={getThumbnailUrl(item.url)}
alt="" alt=""
@@ -946,10 +1074,10 @@ export function MediaList({
className="h-8 w-8" className="h-8 w-8"
onClick={async (e) => { onClick={async (e) => {
e.stopPropagation(); e.stopPropagation();
const settings = getSettings();
setDownloadingItem(itemKey); setDownloadingItem(itemKey);
currentDownloadingItemKeyRef.current = itemKey; currentDownloadingItemKeyRef.current = itemKey;
try { try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({ const request = new main.DownloadMediaWithMetadataRequest({
items: [new main.MediaItemRequest({ items: [new main.MediaItemRequest({
url: item.url, url: item.url,
@@ -957,9 +1085,11 @@ export function MediaList({
tweet_id: item.tweet_id, tweet_id: item.tweet_id,
type: item.type, type: item.type,
content: item.content || "", content: item.content || "",
author_username: item.author_username || "",
})], })],
output_dir: settings.downloadPath, output_dir: getOutputDir(),
username: accountInfo.name, username: accountInfo.name,
proxy: settings.proxy || "",
}); });
const response = await DownloadMediaWithMetadata(request); const response = await DownloadMediaWithMetadata(request);
if (response.success) { if (response.success) {
@@ -1075,6 +1205,13 @@ export function MediaList({
</div> </div>
)} )}
{/* Sentinel for lazy loading - only show if there are more items to load */}
{visibleCount < filteredTimeline.length && (
<div ref={loadMoreRef} className="h-20 flex items-center justify-center w-full">
<Spinner />
</div>
)}
{/* Media Preview Overlay */} {/* Media Preview Overlay */}
{previewIndex !== null && filteredTimeline[previewIndex] && ( {previewIndex !== null && filteredTimeline[previewIndex] && (
<div <div
@@ -1193,10 +1330,10 @@ export function MediaList({
size="sm" size="sm"
className="h-9" className="h-9"
onClick={async () => { onClick={async () => {
const settings = getSettings();
setDownloadingItem(itemKey); setDownloadingItem(itemKey);
currentDownloadingItemKeyRef.current = itemKey; currentDownloadingItemKeyRef.current = itemKey;
try { try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({ const request = new main.DownloadMediaWithMetadataRequest({
items: [new main.MediaItemRequest({ items: [new main.MediaItemRequest({
url: item.url, url: item.url,
@@ -1204,9 +1341,12 @@ export function MediaList({
tweet_id: item.tweet_id, tweet_id: item.tweet_id,
type: item.type, type: item.type,
content: item.content || "", content: item.content || "",
original_filename: item.original_filename || "",
author_username: item.author_username || "",
})], })],
output_dir: settings.downloadPath, output_dir: getOutputDir(),
username: accountInfo.name, username: accountInfo.name,
proxy: settings.proxy || "",
}); });
const response = await DownloadMediaWithMetadata(request); const response = await DownloadMediaWithMetadata(request);
if (response.success) { if (response.success) {
+400 -31
View File
@@ -3,7 +3,6 @@ import { Button } from "@/components/ui/button";
import { InputWithContext } from "@/components/ui/input-with-context"; import { InputWithContext } from "@/components/ui/input-with-context";
import { Label } from "@/components/ui/label"; import { Label } from "@/components/ui/label";
import { import {
Search,
XCircle, XCircle,
Calendar, Calendar,
StopCircle, StopCircle,
@@ -19,6 +18,14 @@ import {
Info, Info,
RotateCcw, RotateCcw,
Trash2, Trash2,
Clock,
CloudDownload,
User,
Users,
FileText,
Hourglass,
CheckCircle,
AlertCircle,
} from "lucide-react"; } from "lucide-react";
import { Spinner } from "@/components/ui/spinner"; import { Spinner } from "@/components/ui/spinner";
import { Checkbox } from "@/components/ui/checkbox"; import { Checkbox } from "@/components/ui/checkbox";
@@ -41,11 +48,30 @@ import { cn } from "@/lib/utils";
export type FetchMode = "public" | "private"; export type FetchMode = "public" | "private";
export type PrivateType = "bookmarks" | "likes"; export type PrivateType = "bookmarks" | "likes";
export type FetchType = "single" | "multiple";
// Local storage keys for auth tokens // Local storage keys for auth tokens
const PUBLIC_AUTH_TOKEN_KEY = "twitter_public_auth_token"; const PUBLIC_AUTH_TOKEN_KEY = "twitter_public_auth_token";
const PRIVATE_AUTH_TOKEN_KEY = "twitter_private_auth_token"; const PRIVATE_AUTH_TOKEN_KEY = "twitter_private_auth_token";
export interface MultipleAccount {
id: string;
username: string;
status: "pending" | "fetching" | "completed" | "incomplete" | "failed";
accountInfo?: {
name: string;
nick: string;
profile_image: string;
};
mediaCount: number;
previousMediaCount: number;
elapsedTime: number;
remainingTime: number | null;
error?: string;
showDiff?: boolean;
cursor?: string;
}
interface SearchBarProps { interface SearchBarProps {
username: string; username: string;
loading: boolean; loading: boolean;
@@ -69,6 +95,22 @@ interface SearchBarProps {
onHistorySelect: (item: HistoryItem) => void; onHistorySelect: (item: HistoryItem) => void;
onHistoryRemove: (id: string) => void; onHistoryRemove: (id: string) => void;
hasResult: boolean; hasResult: boolean;
elapsedTime?: number;
remainingTime?: number | null;
// Multiple mode props
fetchType?: FetchType;
onFetchTypeChange?: (type: FetchType) => void;
multipleAccounts?: MultipleAccount[];
onImportFile?: () => void;
onFetchAll?: () => void;
onStopAll?: () => void;
onStopAccount?: (accountId: string) => void;
onRetryAccount?: (accountId: string) => void;
isFetchingAll?: boolean;
// Mode control
mode?: FetchMode;
privateType?: PrivateType;
onModeChange?: (mode: FetchMode, privateType?: PrivateType) => void;
} }
export function SearchBar({ export function SearchBar({
@@ -84,14 +126,41 @@ export function SearchBar({
onHistorySelect, onHistorySelect,
onHistoryRemove, onHistoryRemove,
hasResult, hasResult,
elapsedTime = 0,
remainingTime = null,
fetchType = "single",
onFetchTypeChange,
multipleAccounts = [],
onImportFile,
onFetchAll,
onStopAll,
onStopAccount,
onRetryAccount,
isFetchingAll = false,
mode: externalMode,
privateType: externalPrivateType,
onModeChange,
}: SearchBarProps) { }: SearchBarProps) {
const [useDateRange, setUseDateRange] = useState(false); const [useDateRange, setUseDateRange] = useState(false);
const [startDate, setStartDate] = useState(""); const [startDate, setStartDate] = useState("");
const [endDate, setEndDate] = useState(""); const [endDate, setEndDate] = useState("");
const [mediaType, setMediaType] = useState("all"); const [mediaType, setMediaType] = useState("all");
const [retweets, setRetweets] = useState(false); const [retweets, setRetweets] = useState(false);
const [mode, setMode] = useState<FetchMode>("public"); const [mode, setMode] = useState<FetchMode>(externalMode || "public");
const [privateType, setPrivateType] = useState<PrivateType>("bookmarks"); const [privateType, setPrivateType] = useState<PrivateType>(externalPrivateType || "bookmarks");
// Sync with external mode if provided
useEffect(() => {
if (externalMode !== undefined) {
setMode(externalMode);
}
}, [externalMode]);
useEffect(() => {
if (externalPrivateType !== undefined) {
setPrivateType(externalPrivateType);
}
}, [externalPrivateType]);
const [showAuthInput, setShowAuthInput] = useState(false); const [showAuthInput, setShowAuthInput] = useState(false);
const [showAdvanced, setShowAdvanced] = useState(false); const [showAdvanced, setShowAdvanced] = useState(false);
@@ -138,42 +207,150 @@ export function SearchBar({
const isLikesMode = mode === "private" && privateType === "likes"; const isLikesMode = mode === "private" && privateType === "likes";
const isBookmarksMode = mode === "private" && privateType === "bookmarks"; const isBookmarksMode = mode === "private" && privateType === "bookmarks";
const formatTime = (seconds: number): string => {
const mins = Math.floor(seconds / 60);
const secs = seconds % 60;
return `${mins}:${String(secs).padStart(2, "0")}`;
};
return ( return (
<div className="space-y-3"> <div className="space-y-3">
{/* Mode Toggle */} {/* Fetch Type and Mode Toggle (Single/Multiple and Public/Private in one line) */}
<div className="flex justify-center"> <div className="flex justify-center gap-2">
<div className="flex gap-1 p-1 bg-muted rounded-lg w-fit"> <div className="flex gap-0.5 p-0.5 bg-muted rounded-lg w-fit">
<button <button
type="button" type="button"
onClick={() => setMode("public")} onClick={() => onFetchTypeChange?.("single")}
className={cn( className={cn(
"flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all cursor-pointer", "flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
mode === "public" fetchType === "single"
? "bg-background text-foreground shadow-sm" ? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground" : "text-muted-foreground hover:text-foreground"
)} )}
> >
<Globe className="h-4 w-4" /> <User className="h-3 w-3" />
Public Single
</button> </button>
<button <button
type="button" type="button"
onClick={() => setMode("private")} onClick={() => onFetchTypeChange?.("multiple")}
className={cn( className={cn(
"flex items-center gap-2 px-4 py-2 rounded-md text-sm font-medium transition-all cursor-pointer", "flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
mode === "private" fetchType === "multiple"
? "bg-background text-foreground shadow-sm" ? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground" : "text-muted-foreground hover:text-foreground"
)} )}
> >
<Lock className="h-4 w-4" /> <Users className="h-3 w-3" />
Private Multiple
</button> </button>
</div> </div>
{fetchType === "single" && (
<div className="flex gap-0.5 p-0.5 bg-muted rounded-lg w-fit">
<button
type="button"
onClick={() => {
setMode("public");
onModeChange?.("public");
}}
className={cn(
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
mode === "public"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
)}
>
<Globe className="h-3 w-3" />
Public
</button>
<button
type="button"
onClick={() => {
setMode("private");
onModeChange?.("private");
}}
className={cn(
"flex items-center gap-1 px-2 py-1 rounded-md text-xs font-medium transition-all cursor-pointer",
mode === "private"
? "bg-background text-foreground shadow-sm"
: "text-muted-foreground hover:text-foreground"
)}
>
<Lock className="h-3 w-3" />
Private
</button>
</div>
)}
</div> </div>
{/* Username Input - for public mode and likes mode */} {/* Multiple Mode UI - Import and Fetch All Buttons */}
{(mode === "public" || isLikesMode) && ( {fetchType === "multiple" && (
<div className="space-y-2">
<div className="flex items-center gap-2">
<Label htmlFor="import-txt" className="text-sm">
Import Accounts
</Label>
<Tooltip>
<TooltipTrigger asChild>
<Info className="h-4 w-4 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent className="max-w-xs">
<p className="text-sm">
One username per line, example:
<br />
<span className="font-mono text-xs">masteraoko</span>
<br />
<span className="font-mono text-xs">xbatchdemo</span>
<br />
<span className="font-mono text-xs">takomayuyi</span>
</p>
</TooltipContent>
</Tooltip>
</div>
<div className="flex items-center gap-2">
<Button
id="import-txt"
variant="outline"
onClick={onImportFile}
className="flex items-center gap-2 flex-1"
>
<FileText className="h-4 w-4" />
Import TXT File
</Button>
<Button
variant="default"
onClick={onFetchAll}
disabled={multipleAccounts.length === 0 || isFetchingAll}
className="flex items-center gap-2 flex-1"
>
{isFetchingAll ? (
<>
<Spinner />
Fetching All...
</>
) : (
<>
<CloudDownload className="h-4 w-4" />
Fetch All
</>
)}
</Button>
{isFetchingAll && (
<Button
variant="destructive"
onClick={onStopAll}
className="flex items-center gap-2"
>
<StopCircle className="h-4 w-4" />
Stop All
</Button>
)}
</div>
</div>
)}
{/* Username Input - for public mode and likes mode, only in single mode */}
{fetchType === "single" && (mode === "public" || isLikesMode) && (
<div className="space-y-2"> <div className="space-y-2">
<Label htmlFor="username"> <Label htmlFor="username">
{isLikesMode ? "Your Username" : "Username"} {isLikesMode ? "Your Username" : "Username"}
@@ -205,10 +382,23 @@ export function SearchBar({
</div> </div>
<div className="flex items-center gap-2"> <div className="flex items-center gap-2">
{loading && ( {loading && (
<Button variant="destructive" onClick={onStopFetch}> <>
<StopCircle className="h-4 w-4" /> {/* Timer Display */}
Stop {(remainingTime !== null || elapsedTime > 0) && (
</Button> <div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
<span className="font-mono">
{remainingTime !== null && remainingTime >= 0
? `${Math.floor(remainingTime / 60)}:${String(remainingTime % 60).padStart(2, "0")}`
: `${Math.floor(elapsedTime / 60)}:${String(elapsedTime % 60).padStart(2, "0")}`}
</span>
</div>
)}
<Button variant="destructive" onClick={onStopFetch}>
<StopCircle className="h-4 w-4" />
Stop
</Button>
</>
)} )}
{/* Resume button - show when there's resumable data */} {/* Resume button - show when there's resumable data */}
{!loading && resumeInfo?.canResume && mode === "public" && ( {!loading && resumeInfo?.canResume && mode === "public" && (
@@ -235,7 +425,7 @@ export function SearchBar({
</> </>
) : ( ) : (
<> <>
{isLikesMode ? <Heart className="h-4 w-4" /> : <Search className="h-4 w-4" />} {isLikesMode ? <Heart className="h-4 w-4" /> : <CloudDownload className="h-4 w-4" />}
{isLikesMode ? "Fetch Likes" : "Fetch"} {isLikesMode ? "Fetch Likes" : "Fetch"}
</> </>
)} )}
@@ -270,11 +460,14 @@ export function SearchBar({
</button> </button>
{/* Private Mode Options - My Bookmarks / My Likes */} {/* Private Mode Options - My Bookmarks / My Likes */}
{mode === "private" && ( {mode === "private" && fetchType === "single" && (
<> <>
<button <button
type="button" type="button"
onClick={() => setPrivateType("bookmarks")} onClick={() => {
setPrivateType("bookmarks");
onModeChange?.("private", "bookmarks");
}}
className={cn( className={cn(
"flex items-center gap-2 px-4 py-2 rounded-lg border text-sm font-medium transition-all cursor-pointer", "flex items-center gap-2 px-4 py-2 rounded-lg border text-sm font-medium transition-all cursor-pointer",
privateType === "bookmarks" privateType === "bookmarks"
@@ -287,7 +480,10 @@ export function SearchBar({
</button> </button>
<button <button
type="button" type="button"
onClick={() => setPrivateType("likes")} onClick={() => {
setPrivateType("likes");
onModeChange?.("private", "likes");
}}
className={cn( className={cn(
"flex items-center gap-2 px-4 py-2 rounded-lg border text-sm font-medium transition-all cursor-pointer", "flex items-center gap-2 px-4 py-2 rounded-lg border text-sm font-medium transition-all cursor-pointer",
privateType === "likes" privateType === "likes"
@@ -305,10 +501,23 @@ export function SearchBar({
{isBookmarksMode && ( {isBookmarksMode && (
<div className="flex items-center gap-2 ml-auto"> <div className="flex items-center gap-2 ml-auto">
{loading && ( {loading && (
<Button variant="destructive" onClick={onStopFetch}> <>
<StopCircle className="h-4 w-4" /> {/* Timer Display */}
Stop {(remainingTime !== null || elapsedTime > 0) && (
</Button> <div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
<span className="font-mono">
{remainingTime !== null && remainingTime >= 0
? `${Math.floor(remainingTime / 60)}:${String(remainingTime % 60).padStart(2, "0")}`
: `${Math.floor(elapsedTime / 60)}:${String(elapsedTime % 60).padStart(2, "0")}`}
</span>
</div>
)}
<Button variant="destructive" onClick={onStopFetch}>
<StopCircle className="h-4 w-4" />
Stop
</Button>
</>
)} )}
<Button onClick={handleFetch} disabled={loading || !hasAuthToken}> <Button onClick={handleFetch} disabled={loading || !hasAuthToken}>
{loading ? ( {loading ? (
@@ -471,7 +680,167 @@ export function SearchBar({
</div> </div>
)} )}
{!hasResult && mode === "public" && ( {/* Statistics for Multiple Fetch - below auth token and advanced settings */}
{fetchType === "multiple" && multipleAccounts.length > 0 && (
<div className="p-3 border rounded-lg bg-muted/30">
<div className="flex items-center gap-6 text-sm">
<div className="flex items-center gap-2">
<CheckCircle className="h-4 w-4 text-green-600 dark:text-green-400" />
<span className="text-muted-foreground">Completed:</span>
<span className="font-medium">
{multipleAccounts.filter((acc) => acc.status === "completed").length}
</span>
</div>
<div className="flex items-center gap-2">
<AlertCircle className="h-4 w-4 text-yellow-600 dark:text-yellow-400" />
<span className="text-muted-foreground">Incomplete:</span>
<span className="font-medium">
{multipleAccounts.filter((acc) => acc.status === "incomplete").length}
</span>
</div>
<div className="flex items-center gap-2">
<XCircle className="h-4 w-4 text-red-600 dark:text-red-400" />
<span className="text-muted-foreground">Failed:</span>
<span className="font-medium">
{multipleAccounts.filter((acc) => acc.status === "failed").length}
</span>
</div>
<div className="flex items-center gap-2 ml-auto">
<span className="text-muted-foreground">Total:</span>
<span className="font-medium">
{multipleAccounts.filter((acc) =>
acc.status === "completed" || acc.status === "incomplete" || acc.status === "failed"
).length}/{multipleAccounts.length}
</span>
</div>
</div>
</div>
)}
{/* Account List - below auth token and advanced settings */}
{fetchType === "multiple" && multipleAccounts.length > 0 && (
<div className="space-y-2">
<p className="text-sm text-muted-foreground">Accounts to Fetch ({multipleAccounts.length})</p>
<div className="space-y-2 max-h-[400px] overflow-y-auto">
{multipleAccounts.map((account) => (
<div
key={account.id}
className="p-3 border rounded-lg bg-card"
>
<div className="flex items-center gap-3">
{account.accountInfo ? (
<img
src={account.accountInfo.profile_image}
alt={account.accountInfo.nick}
className="w-10 h-10 rounded-full"
/>
) : (
<div className="w-10 h-10 rounded-full bg-muted flex items-center justify-center">
<User className="h-5 w-5 text-muted-foreground" />
</div>
)}
<div className="flex-1 min-w-0">
{account.accountInfo ? (
<>
<div className="flex items-center gap-2">
<span className="font-medium">{account.accountInfo.nick}</span>
<span className="text-sm text-muted-foreground">@{account.accountInfo.name}</span>
</div>
<div className="flex items-center gap-2 mt-1">
<span className="text-sm text-muted-foreground">
<span className="text-primary">{account.mediaCount.toLocaleString()}</span> items found
</span>
{account.showDiff && account.previousMediaCount > 0 && account.mediaCount > account.previousMediaCount && (
<span className="text-sm text-green-600 dark:text-green-400 font-medium">
+{account.mediaCount - account.previousMediaCount}
</span>
)}
</div>
</>
) : (
<div className="flex items-center gap-2">
<span className="font-medium">@{account.username}</span>
</div>
)}
</div>
<div className="flex items-center gap-2">
{account.status === "fetching" && (
<>
<div className="flex items-center gap-1.5 px-3 py-1.5 border rounded-md bg-muted/50 text-sm w-[85px]">
<Clock className="h-3.5 w-3.5 text-muted-foreground flex-shrink-0" />
<span className="font-mono">
{account.remainingTime !== null && account.remainingTime >= 0
? formatTime(account.remainingTime)
: formatTime(account.elapsedTime)}
</span>
</div>
<Button
variant="destructive"
onClick={() => onStopAccount?.(account.id)}
className="flex items-center gap-2"
>
<StopCircle className="h-4 w-4" />
Stop
</Button>
</>
)}
{account.status === "pending" && (
<span className="text-xs px-2 py-1 bg-gray-500/20 text-gray-600 dark:text-gray-400 rounded flex items-center gap-1.5">
<Hourglass className="h-3 w-3" />
Pending
</span>
)}
{account.status === "completed" && (
<span className="text-xs px-2 py-1 bg-green-500/20 text-green-600 dark:text-green-400 rounded flex items-center gap-1.5">
<CheckCircle className="h-3 w-3" />
Completed
</span>
)}
{account.status === "incomplete" && (
<>
<span className="text-xs px-2 py-1 bg-yellow-500/20 text-yellow-600 dark:text-yellow-400 rounded flex items-center gap-1.5">
<AlertCircle className="h-3 w-3" />
Incomplete
</span>
<Button
variant="outline"
size="sm"
onClick={() => onRetryAccount?.(account.id)}
disabled={isFetchingAll}
className="flex items-center gap-2"
>
<RotateCcw className="h-3.5 w-3.5" />
Retry
</Button>
</>
)}
{account.status === "failed" && (
<>
<span className="text-xs px-2 py-1 bg-red-500/20 text-red-600 dark:text-red-400 rounded flex items-center gap-1.5">
<XCircle className="h-3 w-3" />
Failed
</span>
<Button
variant="outline"
size="sm"
onClick={() => onRetryAccount?.(account.id)}
disabled={isFetchingAll}
className="flex items-center gap-2"
>
<RotateCcw className="h-3.5 w-3.5" />
Retry
</Button>
</>
)}
</div>
</div>
</div>
))}
</div>
</div>
)}
{!hasResult && mode === "public" && fetchType === "single" && (
<FetchHistory <FetchHistory
history={history} history={history}
onSelect={onHistorySelect} onSelect={onHistorySelect}
-327
View File
@@ -1,327 +0,0 @@
import { useState, useEffect } from "react";
import { Button } from "@/components/ui/button";
import { InputWithContext } from "@/components/ui/input-with-context";
import { Label } from "@/components/ui/label";
import {
Dialog,
DialogContent,
DialogFooter,
DialogTitle,
DialogTrigger,
} from "@/components/ui/dialog";
import {
Select,
SelectContent,
SelectItem,
SelectTrigger,
SelectValue,
} from "@/components/ui/select";
import { Settings as SettingsIcon, FolderOpen, Save, RotateCcw, X, Info, Download, Check, Volume2 } from "lucide-react";
import { Spinner } from "@/components/ui/spinner";
import {
Tooltip,
TooltipContent,
TooltipTrigger,
} from "@/components/ui/tooltip";
import { Switch } from "@/components/ui/switch";
import { getSettings, getSettingsWithDefaults, saveSettings, resetToDefaultSettings, applyThemeMode, type Settings as SettingsType } from "@/lib/settings";
import { themes, applyTheme } from "@/lib/themes";
import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { SelectFolder, IsFFmpegInstalled, DownloadFFmpeg } from "../../wailsjs/go/main/App";
export function Settings() {
const [open, setOpen] = useState(false);
const [savedSettings, setSavedSettings] = useState<SettingsType>(getSettings());
const [tempSettings, setTempSettings] = useState<SettingsType>(savedSettings);
const [, setIsLoadingDefaults] = useState(false);
const [isDark, setIsDark] = useState(document.documentElement.classList.contains('dark'));
const [ffmpegInstalled, setFfmpegInstalled] = useState(false);
const [downloadingFFmpeg, setDownloadingFFmpeg] = useState(false);
useEffect(() => {
applyThemeMode(savedSettings.themeMode);
applyTheme(savedSettings.theme);
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
const handleChange = () => {
if (savedSettings.themeMode === "auto") {
applyThemeMode("auto");
applyTheme(savedSettings.theme);
}
};
mediaQuery.addEventListener("change", handleChange);
return () => mediaQuery.removeEventListener("change", handleChange);
}, [savedSettings.themeMode, savedSettings.theme]);
useEffect(() => {
if (open) {
applyThemeMode(tempSettings.themeMode);
applyTheme(tempSettings.theme);
setTimeout(() => {
setIsDark(document.documentElement.classList.contains('dark'));
}, 0);
const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
const handleChange = () => {
if (tempSettings.themeMode === "auto") {
applyThemeMode("auto");
applyTheme(tempSettings.theme);
setTimeout(() => {
setIsDark(document.documentElement.classList.contains('dark'));
}, 0);
}
};
mediaQuery.addEventListener("change", handleChange);
return () => mediaQuery.removeEventListener("change", handleChange);
}
}, [open, tempSettings.themeMode, tempSettings.theme]);
useEffect(() => {
const loadDefaults = async () => {
if (!savedSettings.downloadPath) {
setIsLoadingDefaults(true);
const settingsWithDefaults = await getSettingsWithDefaults();
setSavedSettings(settingsWithDefaults);
setTempSettings(settingsWithDefaults);
setIsLoadingDefaults(false);
}
};
loadDefaults();
// Check FFmpeg status
IsFFmpegInstalled().then(setFfmpegInstalled);
}, []);
useEffect(() => {
if (open) {
setTempSettings(savedSettings);
}
}, [open, savedSettings]);
const handleSave = () => {
saveSettings(tempSettings);
setSavedSettings(tempSettings);
setOpen(false);
};
const handleReset = async () => {
const defaultSettings = await resetToDefaultSettings();
setTempSettings(defaultSettings);
setSavedSettings(defaultSettings);
applyThemeMode(defaultSettings.themeMode);
applyTheme(defaultSettings.theme);
};
const handleCancel = () => {
applyThemeMode(savedSettings.themeMode);
applyTheme(savedSettings.theme);
setTempSettings(savedSettings);
setOpen(false);
};
const handleOpenChange = (newOpen: boolean) => {
if (!newOpen) {
applyThemeMode(savedSettings.themeMode);
applyTheme(savedSettings.theme);
setTempSettings(savedSettings);
}
setOpen(newOpen);
};
const handleBrowseFolder = async () => {
try {
const selectedPath = await SelectFolder(tempSettings.downloadPath || "");
if (selectedPath && selectedPath.trim() !== "") {
setTempSettings((prev) => ({ ...prev, downloadPath: selectedPath }));
}
} catch (error) {
console.error("Error selecting folder:", error);
}
};
const handleDownloadFFmpeg = async () => {
setDownloadingFFmpeg(true);
try {
await DownloadFFmpeg();
setFfmpegInstalled(true);
toast.success("FFmpeg downloaded successfully");
} catch (error) {
toast.error("Failed to download FFmpeg");
console.error("Error downloading FFmpeg:", error);
} finally {
setDownloadingFFmpeg(false);
}
};
return (
<Dialog open={open} onOpenChange={handleOpenChange}>
<DialogTrigger asChild>
<Button variant="outline" size="icon">
<SettingsIcon className="h-5 w-5" />
</Button>
</DialogTrigger>
<DialogContent className="sm:max-w-[480px] flex flex-col p-6 [&>button]:hidden" aria-describedby={undefined}>
<div className="absolute right-4 top-4">
<Button
variant="ghost"
size="icon"
className="h-6 w-6 opacity-70 hover:opacity-100"
onClick={handleCancel}
>
<X className="h-4 w-4" />
</Button>
</div>
<DialogTitle className="text-sm font-medium">Settings</DialogTitle>
{/* 2 Column Grid Layout */}
<div className="grid grid-cols-2 gap-x-6 gap-y-4 py-2">
{/* LEFT COLUMN */}
{/* Download Path */}
<div className="space-y-2 col-span-2">
<Label htmlFor="download-path">Download Path</Label>
<div className="flex gap-2">
<InputWithContext
id="download-path"
value={tempSettings.downloadPath}
onChange={(e) => setTempSettings((prev) => ({ ...prev, downloadPath: e.target.value }))}
placeholder="C:\Users\YourUsername\Pictures"
/>
<Tooltip>
<TooltipTrigger asChild>
<Button type="button" onClick={handleBrowseFolder} size="icon">
<FolderOpen className="h-4 w-4" />
</Button>
</TooltipTrigger>
<TooltipContent>Browse Folder</TooltipContent>
</Tooltip>
</div>
</div>
{/* LEFT: Mode */}
<div className="space-y-2">
<Label htmlFor="theme-mode">Mode</Label>
<Select
value={tempSettings.themeMode}
onValueChange={(value) => setTempSettings((prev) => ({ ...prev, themeMode: value as any }))}
>
<SelectTrigger id="theme-mode">
<SelectValue placeholder="Select theme mode" />
</SelectTrigger>
<SelectContent>
<SelectItem value="auto">Auto</SelectItem>
<SelectItem value="light">Light</SelectItem>
<SelectItem value="dark">Dark</SelectItem>
</SelectContent>
</Select>
</div>
{/* RIGHT: GIF Conversion */}
<div className="space-y-2">
<Label className="flex items-center gap-2">
GIF Conversion
<Tooltip>
<TooltipTrigger asChild>
<Info className="h-3.5 w-3.5 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent side="top">
<p>FFmpeg is required to convert Twitter's MP4 to actual GIF format</p>
</TooltipContent>
</Tooltip>
</Label>
<div className="h-9 flex items-center">
{ffmpegInstalled ? (
<div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
<Check className="h-4 w-4" />
Installed
</div>
) : (
<Button
variant="outline"
size="sm"
className="h-9"
onClick={handleDownloadFFmpeg}
disabled={downloadingFFmpeg}
>
{downloadingFFmpeg ? (
<>
<Spinner />
Downloading...
</>
) : (
<>
<Download className="h-4 w-4" />
Download FFmpeg
</>
)}
</Button>
)}
</div>
</div>
{/* LEFT: Accent */}
<div className="space-y-2">
<Label htmlFor="theme">Accent</Label>
<Select
value={tempSettings.theme}
onValueChange={(value) => setTempSettings((prev) => ({ ...prev, theme: value }))}
>
<SelectTrigger id="theme">
<SelectValue placeholder="Select a theme" />
</SelectTrigger>
<SelectContent>
{themes.map((theme) => (
<SelectItem key={theme.name} value={theme.name}>
<span className="flex items-center gap-2">
<span
className="w-3 h-3 rounded-full border border-border"
style={{
backgroundColor: isDark
? theme.cssVars.dark.primary
: theme.cssVars.light.primary
}}
/>
{theme.label}
</span>
</SelectItem>
))}
</SelectContent>
</Select>
</div>
{/* RIGHT: Sound Effects */}
<div className="space-y-2">
<Label htmlFor="sfx-enabled" className="flex items-center gap-2">
<Volume2 className="h-4 w-4 text-muted-foreground" />
Sound Effects
</Label>
<div className="h-9 flex items-center">
<Switch
id="sfx-enabled"
checked={tempSettings.sfxEnabled}
onCheckedChange={(checked) => setTempSettings(prev => ({ ...prev, sfxEnabled: checked }))}
/>
</div>
</div>
</div>
<DialogFooter className="gap-2 sm:justify-between">
<Button variant="outline" onClick={handleReset} className="gap-1.5">
<RotateCcw className="h-4 w-4" />
Reset to Default
</Button>
<div className="flex gap-2">
<Button variant="outline" onClick={handleCancel}>
Cancel
</Button>
<Button onClick={handleSave} className="gap-1.5">
<Save className="h-4 w-4" />
Save Changes
</Button>
</div>
</DialogFooter>
</DialogContent>
</Dialog>
);
}
+129 -2
View File
@@ -15,7 +15,7 @@ import { Spinner } from "@/components/ui/spinner";
import { Switch } from "@/components/ui/switch"; import { Switch } from "@/components/ui/switch";
import { getSettings, getSettingsWithDefaults, saveSettings, resetToDefaultSettings, applyThemeMode, applyFont, FONT_OPTIONS, type Settings as SettingsType, type FontFamily, type GifQuality, type GifResolution } from "@/lib/settings"; import { getSettings, getSettingsWithDefaults, saveSettings, resetToDefaultSettings, applyThemeMode, applyFont, FONT_OPTIONS, type Settings as SettingsType, type FontFamily, type GifQuality, type GifResolution } from "@/lib/settings";
import { themes, applyTheme } from "@/lib/themes"; import { themes, applyTheme } from "@/lib/themes";
import { SelectFolder, IsFFmpegInstalled, DownloadFFmpeg } from "../../wailsjs/go/main/App"; import { SelectFolder, IsFFmpegInstalled, DownloadFFmpeg, IsExifToolInstalled, DownloadExifTool } from "../../wailsjs/go/main/App";
import { toastWithSound as toast } from "@/lib/toast-with-sound"; import { toastWithSound as toast } from "@/lib/toast-with-sound";
export function SettingsPage() { export function SettingsPage() {
@@ -24,6 +24,8 @@ export function SettingsPage() {
const [isDark, setIsDark] = useState(document.documentElement.classList.contains('dark')); const [isDark, setIsDark] = useState(document.documentElement.classList.contains('dark'));
const [ffmpegInstalled, setFfmpegInstalled] = useState(false); const [ffmpegInstalled, setFfmpegInstalled] = useState(false);
const [downloadingFFmpeg, setDownloadingFFmpeg] = useState(false); const [downloadingFFmpeg, setDownloadingFFmpeg] = useState(false);
const [exiftoolInstalled, setExiftoolInstalled] = useState(false);
const [downloadingExifTool, setDownloadingExifTool] = useState(false);
useEffect(() => { useEffect(() => {
applyThemeMode(savedSettings.themeMode); applyThemeMode(savedSettings.themeMode);
@@ -60,8 +62,9 @@ export function SettingsPage() {
}; };
loadDefaults(); loadDefaults();
// Check FFmpeg status // Check FFmpeg and ExifTool status
IsFFmpegInstalled().then(setFfmpegInstalled); IsFFmpegInstalled().then(setFfmpegInstalled);
IsExifToolInstalled().then(setExiftoolInstalled);
}, []); }, []);
const handleSave = () => { const handleSave = () => {
@@ -106,6 +109,20 @@ export function SettingsPage() {
} }
}; };
const handleDownloadExifTool = async () => {
setDownloadingExifTool(true);
try {
await DownloadExifTool();
setExiftoolInstalled(true);
toast.success("ExifTool downloaded successfully");
} catch (error) {
toast.error("Failed to download ExifTool");
console.error("Error downloading ExifTool:", error);
} finally {
setDownloadingExifTool(false);
}
};
return ( return (
<div className="space-y-6"> <div className="space-y-6">
<h1 className="text-2xl font-bold">Settings</h1> <h1 className="text-2xl font-bold">Settings</h1>
@@ -210,6 +227,49 @@ export function SettingsPage() {
{/* Right Column */} {/* Right Column */}
<div className="space-y-4"> <div className="space-y-4">
{/* Metadata Embedding */}
<div className="space-y-2">
<Label className="flex items-center gap-2">
Metadata Embedding
<Tooltip>
<TooltipTrigger asChild>
<Info className="h-3.5 w-3.5 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent side="top">
<p>ExifTool is required to embed tweet URL and original filename into media file metadata</p>
</TooltipContent>
</Tooltip>
</Label>
<div className="h-9 flex items-center">
{exiftoolInstalled ? (
<div className="flex items-center gap-2 text-sm text-green-600 dark:text-green-400">
<Check className="h-4 w-4" />
Installed
</div>
) : (
<Button
variant="outline"
size="sm"
className="h-9"
onClick={handleDownloadExifTool}
disabled={downloadingExifTool}
>
{downloadingExifTool ? (
<>
<Spinner />
Downloading...
</>
) : (
<>
<Download className="h-4 w-4" />
Download ExifTool
</>
)}
</Button>
)}
</div>
</div>
{/* GIF Conversion */} {/* GIF Conversion */}
<div className="space-y-2"> <div className="space-y-2">
<Label className="flex items-center gap-2"> <Label className="flex items-center gap-2">
@@ -301,6 +361,73 @@ export function SettingsPage() {
)} )}
</> </>
)} )}
{/* Proxy */}
<div className="space-y-2">
<Label htmlFor="proxy" className="flex items-center gap-2">
Proxy
<Tooltip>
<TooltipTrigger asChild>
<Info className="h-3.5 w-3.5 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent side="top">
<p>If download fails, try using a proxy server</p>
</TooltipContent>
</Tooltip>
</Label>
<InputWithContext
id="proxy"
value={tempSettings.proxy || ""}
onChange={(e) => setTempSettings((prev) => ({ ...prev, proxy: e.target.value }))}
placeholder="http://proxy:port or socks5://proxy:port (optional)"
className="w-[90%]"
/>
</div>
{/* Fetch Timeout */}
<div className="space-y-2">
<Label htmlFor="fetch-timeout" className="flex items-center gap-2">
Fetch Timeout
<Tooltip>
<TooltipTrigger asChild>
<Info className="h-3.5 w-3.5 text-muted-foreground cursor-help" />
</TooltipTrigger>
<TooltipContent side="top">
<p>Timeout in seconds. Fetch stops automatically when reached</p>
</TooltipContent>
</Tooltip>
</Label>
<InputWithContext
id="fetch-timeout"
type="number"
value={tempSettings.fetchTimeout || 60}
onChange={(e) => {
const inputValue = e.target.value;
// Allow empty input for user to type freely
if (inputValue === "") {
setTempSettings((prev) => ({ ...prev, fetchTimeout: 60 }));
return;
}
const value = parseInt(inputValue, 10);
// Allow any number while typing (including values less than min during typing)
// Validation will happen on blur
if (!isNaN(value)) {
setTempSettings((prev) => ({ ...prev, fetchTimeout: value }));
}
}}
onBlur={(e) => {
// Validate and clamp value on blur
const value = parseInt(e.target.value, 10);
if (isNaN(value) || value < 30) {
setTempSettings((prev) => ({ ...prev, fetchTimeout: 30 }));
} else if (value > 900) {
setTempSettings((prev) => ({ ...prev, fetchTimeout: 900 }));
}
}}
placeholder="60"
className="w-[20%]"
/>
</div>
</div> </div>
</div> </div>
@@ -0,0 +1,200 @@
import * as React from "react"
import * as DropdownMenuPrimitive from "@radix-ui/react-dropdown-menu"
import { CheckIcon, ChevronRightIcon } from "lucide-react"
import { cn } from "@/lib/utils"
const DropdownMenu = DropdownMenuPrimitive.Root
const DropdownMenuTrigger = DropdownMenuPrimitive.Trigger
const DropdownMenuGroup = DropdownMenuPrimitive.Group
const DropdownMenuPortal = DropdownMenuPrimitive.Portal
const DropdownMenuSub = DropdownMenuPrimitive.Sub
const DropdownMenuRadioGroup = DropdownMenuPrimitive.RadioGroup
const DropdownMenuSubTrigger = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.SubTrigger>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubTrigger> & {
inset?: boolean
}
>(({ className, inset, children, ...props }, ref) => (
<DropdownMenuPrimitive.SubTrigger
ref={ref}
className={cn(
"flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none focus:bg-accent data-[state=open]:bg-accent",
inset && "pl-8",
className
)}
{...props}
>
{children}
<ChevronRightIcon className="ml-auto h-4 w-4" />
</DropdownMenuPrimitive.SubTrigger>
))
DropdownMenuSubTrigger.displayName =
DropdownMenuPrimitive.SubTrigger.displayName
const DropdownMenuSubContent = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.SubContent>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.SubContent>
>(({ className, ...props }, ref) => (
<DropdownMenuPrimitive.SubContent
ref={ref}
className={cn(
"z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-lg data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
)}
{...props}
/>
))
DropdownMenuSubContent.displayName =
DropdownMenuPrimitive.SubContent.displayName
const DropdownMenuContent = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Content>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Content>
>(({ className, sideOffset = 4, ...props }, ref) => (
<DropdownMenuPrimitive.Portal>
<DropdownMenuPrimitive.Content
ref={ref}
sideOffset={sideOffset}
className={cn(
"z-50 min-w-32 overflow-hidden rounded-md border bg-popover p-1 text-popover-foreground shadow-md data-[state=open]:animate-in data-[state=closed]:animate-out data-[state=closed]:fade-out-0 data-[state=open]:fade-in-0 data-[state=closed]:zoom-out-95 data-[state=open]:zoom-in-95 data-[side=bottom]:slide-in-from-top-2 data-[side=left]:slide-in-from-right-2 data-[side=right]:slide-in-from-left-2 data-[side=top]:slide-in-from-bottom-2",
className
)}
{...props}
/>
</DropdownMenuPrimitive.Portal>
))
DropdownMenuContent.displayName = DropdownMenuPrimitive.Content.displayName
const DropdownMenuItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Item>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Item> & {
inset?: boolean
}
>(({ className, inset, ...props }, ref) => (
<DropdownMenuPrimitive.Item
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm px-2 py-1.5 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
inset && "pl-8",
className
)}
{...props}
/>
))
DropdownMenuItem.displayName = DropdownMenuPrimitive.Item.displayName
const DropdownMenuCheckboxItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.CheckboxItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.CheckboxItem>
>(({ className, children, checked, ...props }, ref) => (
<DropdownMenuPrimitive.CheckboxItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
className
)}
checked={checked}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<CheckIcon className="h-4 w-4" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.CheckboxItem>
))
DropdownMenuCheckboxItem.displayName =
DropdownMenuPrimitive.CheckboxItem.displayName
const DropdownMenuRadioItem = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.RadioItem>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.RadioItem>
>(({ className, children, ...props }, ref) => (
<DropdownMenuPrimitive.RadioItem
ref={ref}
className={cn(
"relative flex cursor-default select-none items-center rounded-sm py-1.5 pl-8 pr-2 text-sm outline-none transition-colors focus:bg-accent focus:text-accent-foreground data-disabled:pointer-events-none data-disabled:opacity-50",
className
)}
{...props}
>
<span className="absolute left-2 flex h-3.5 w-3.5 items-center justify-center">
<DropdownMenuPrimitive.ItemIndicator>
<CheckIcon className="h-4 w-4" />
</DropdownMenuPrimitive.ItemIndicator>
</span>
{children}
</DropdownMenuPrimitive.RadioItem>
))
DropdownMenuRadioItem.displayName = DropdownMenuPrimitive.RadioItem.displayName
const DropdownMenuLabel = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Label>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Label> & {
inset?: boolean
}
>(({ className, inset, ...props }, ref) => (
<DropdownMenuPrimitive.Label
ref={ref}
className={cn(
"px-2 py-1.5 text-sm font-semibold",
inset && "pl-8",
className
)}
{...props}
/>
))
DropdownMenuLabel.displayName = DropdownMenuPrimitive.Label.displayName
const DropdownMenuSeparator = React.forwardRef<
React.ElementRef<typeof DropdownMenuPrimitive.Separator>,
React.ComponentPropsWithoutRef<typeof DropdownMenuPrimitive.Separator>
>(({ className, ...props }, ref) => (
<DropdownMenuPrimitive.Separator
ref={ref}
className={cn("-mx-1 my-1 h-px bg-muted", className)}
{...props}
/>
))
DropdownMenuSeparator.displayName = DropdownMenuPrimitive.Separator.displayName
const DropdownMenuShortcut = ({
className,
...props
}: React.HTMLAttributes<HTMLSpanElement>) => {
return (
<span
className={cn("ml-auto text-xs tracking-widest opacity-60", className)}
{...props}
/>
)
}
DropdownMenuShortcut.displayName = "DropdownMenuShortcut"
export {
DropdownMenu,
DropdownMenuTrigger,
DropdownMenuContent,
DropdownMenuItem,
DropdownMenuCheckboxItem,
DropdownMenuRadioItem,
DropdownMenuLabel,
DropdownMenuSeparator,
DropdownMenuShortcut,
DropdownMenuGroup,
DropdownMenuPortal,
DropdownMenuSub,
DropdownMenuSubContent,
DropdownMenuSubTrigger,
DropdownMenuRadioGroup,
}
+58
View File
@@ -6,6 +6,7 @@
import type { TwitterResponse, TimelineEntry, AccountInfo } from "@/types/api"; import type { TwitterResponse, TimelineEntry, AccountInfo } from "@/types/api";
const FETCH_STATE_KEY = "twitter_fetch_state"; const FETCH_STATE_KEY = "twitter_fetch_state";
const CURSOR_STATE_KEY = "twitter_cursor_state"; // Lightweight cursor-only storage
export interface FetchState { export interface FetchState {
username: string; username: string;
@@ -166,6 +167,63 @@ export function stateToResponse(state: FetchState): TwitterResponse | null {
}; };
} }
/**
* Save cursor only (lightweight, can be called every batch)
*/
export function saveCursor(username: string, cursor: string): void {
try {
const allCursors = getAllCursors();
allCursors[username.toLowerCase()] = {
cursor,
lastUpdated: Date.now(),
};
localStorage.setItem(CURSOR_STATE_KEY, JSON.stringify(allCursors));
} catch (error) {
console.error("Failed to save cursor:", error);
}
}
/**
* Get cursor for username from localStorage (lightweight, synchronous)
*/
export function getCursor(username: string): string | null {
try {
const allCursors = getAllCursors();
return allCursors[username.toLowerCase()]?.cursor || null;
} catch (error) {
console.error("Failed to get cursor:", error);
return null;
}
}
/**
* Get all cursors
*/
function getAllCursors(): Record<string, { cursor: string; lastUpdated: number }> {
try {
const stored = localStorage.getItem(CURSOR_STATE_KEY);
if (stored) {
return JSON.parse(stored);
}
} catch (error) {
console.error("Failed to parse cursors:", error);
}
return {};
}
/**
* Clear cursor for username
*/
export function clearCursor(username: string): void {
try {
const allCursors = getAllCursors();
delete allCursors[username.toLowerCase()];
localStorage.setItem(CURSOR_STATE_KEY, JSON.stringify(allCursors));
} catch (error) {
console.error("Failed to clear cursor:", error);
}
}
/** /**
* Merge new timeline entries with existing (deduplicate by tweet_id) * Merge new timeline entries with existing (deduplicate by tweet_id)
*/ */
+4
View File
@@ -12,6 +12,8 @@ export interface Settings {
sfxEnabled: boolean; sfxEnabled: boolean;
gifQuality: GifQuality; gifQuality: GifQuality;
gifResolution: GifResolution; gifResolution: GifResolution;
proxy: string; // Proxy URL (e.g., http://proxy:port or socks5://proxy:port). Empty to use system proxy or no proxy.
fetchTimeout: number; // Fetch timeout in seconds. Default: 60 seconds.
} }
export const DEFAULT_SETTINGS: Settings = { export const DEFAULT_SETTINGS: Settings = {
@@ -22,6 +24,8 @@ export const DEFAULT_SETTINGS: Settings = {
sfxEnabled: true, sfxEnabled: true,
gifQuality: "fast", gifQuality: "fast",
gifResolution: "high", gifResolution: "high",
proxy: "",
fetchTimeout: 60, // Default: 60 seconds
}; };
export const FONT_OPTIONS: { value: FontFamily; label: string; fontFamily: string }[] = [ export const FONT_OPTIONS: { value: FontFamily; label: string; fontFamily: string }[] = [
+2
View File
@@ -27,6 +27,8 @@ export interface TimelineEntry {
reply_count?: number; reply_count?: number;
source?: string; source?: string;
verified?: boolean; verified?: boolean;
original_filename?: string; // Original filename from API
author_username?: string; // Username of tweet author (for bookmarks and likes)
} }
export interface ExtractMetadata { export interface ExtractMetadata {
-8
View File
@@ -52,11 +52,3 @@ python -m nuitka --onefile --output-filename=extractor.exe --include-package=gal
- PyInstaller: `dist/extractor` or `dist/extractor.exe` - PyInstaller: `dist/extractor` or `dist/extractor.exe`
- Nuitka: `extractor` or `extractor.exe` (in current directory) - Nuitka: `extractor` or `extractor.exe` (in current directory)
---
## Notes
- The main application automatically manages the binary (extracts, updates, and uses it)
- Manual building is only needed if you're developing or customizing the extractor
- The pre-built binary is kept in sync with the application version
+1 -51
View File
@@ -1,29 +1,7 @@
# twitter_cli.py — Usage Guide # Usage Guide
CLI tool for extracting media and metadata from Twitter/X using gallery-dl extractor. CLI tool for extracting media and metadata from Twitter/X using gallery-dl extractor.
## Quickstart
1. **Set up environment**
```powershell
cd helper
python -m venv .venv
.\.venv\Scripts\Activate.ps1
pip install -r requirements.txt
```
2. **Verify gallery-dl**
```powershell
python -c "import gallery_dl; print(gallery_dl.__version__)"
```
3. **Quick test** (using demo account):
```powershell
python twitter_cli.py https://x.com/xbatchdemo/media --limit 1 --json --guest
```
---
## Command Line Arguments ## Command Line Arguments
### Required ### Required
@@ -277,34 +255,6 @@ Use in search URLs:
--- ---
## Authentication
### Getting Your Auth Token
1. Open Twitter/X in your browser
2. Open Developer Tools (F12)
3. Go to Application/Storage → Cookies
4. Find cookie named `auth_token`
5. Copy its value
### Security Notes
- Use a dummy/secondary account for scraping
- Don't share your auth token
- Excessive usage may cause account suspension
- Guest mode has stricter rate limits
---
## Rate Limits
- **Guest mode**: Lower limits, may hit rate limit faster
- **Authenticated**: Higher limits but still restricted
- **Rate limit hit**: Script will wait and retry automatically
- **Best practice**: Use `--limit` to control fetch size
---
## Tips & Tricks ## Tips & Tricks
### 1. Progressive Fetch with Resume ### 1. Progressive Fetch with Resume
+1 -1
View File
@@ -1,3 +1,3 @@
{ {
"version": "4.0" "version": "4.1"
} }
+1 -1
View File
@@ -11,7 +11,7 @@
}, },
"info": { "info": {
"productName": "Twitter/X Media Batch Downloader", "productName": "Twitter/X Media Batch Downloader",
"productVersion": "4.0" "productVersion": "4.1"
}, },
"wailsjsdir": "./frontend", "wailsjsdir": "./frontend",
"assetdir": "./frontend/dist", "assetdir": "./frontend/dist",