Compare commits

...
10 Commits
Author SHA1 Message Date
afkarxyz 1f378bb356 v5.0.0 2026-07-29 14:59:28 +07:00
afkarxyz 492a318399 Update README 2026-07-16 18:41:16 +07:00
afkarxyz 2ada5da9bf v4.9 2026-07-16 18:27:23 +07:00
afkarxyz 3fb8bda2ff Update README 2026-07-15 12:26:49 +07:00
asdfghjkkly b4dfb75f5b Fix group editing and skip existing downloads (#105) 2026-07-12 10:59:29 +07:00
afkarxyz 7e584aff2c Update README 2026-07-12 10:58:42 +07:00
afkarxyz 76acb6f5e1 v4.8 2026-07-05 19:09:54 +07:00
afkarxyz 6bd03678f8 Merge pull request #103 from asdfghjkkly/fix-windows-folder-and-reposts
Fix repost folder routing and Windows folder opening
2026-07-05 17:00:37 +07:00
asdfghjkkly e400df6ea7 Fix repost folder routing and Windows folder opening 2026-07-05 05:41:36 -04:00
afkarxyz 52ffa5ba17 Update README 2026-06-22 14:31:56 +07:00
22 changed files with 690 additions and 496 deletions

No files matched your search

+30 -11
View File
@@ -1,20 +1,39 @@
# Twitter/X Media Batch Downloader
A GUI tool to download original-quality images and videos from Twitter/X accounts.
![Windows](https://img.shields.io/badge/Windows-10%2B-0078D6?style=for-the-badge&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgMjAgMjAiPjxwYXRoIGZpbGw9IiNmZmZmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTIwIDEwLjg3M1YyMEw4LjQ3OSAxOC41MzdsLjAwMS03LjY2NEgyMFptLTEzLjEyIDBsLS4wMDEgNy40NjFMMCAxNy40NjF2LTYuNTg4aDYuODhaTTIwIDkuMjczSDguNDhsLS4wMDEtNy44MUwyMCAwdjkuMjczWk02Ljg3OSAxLjY2NmwuMDAxIDcuNjA3SDBWMi41MzlsNi44NzktLjg3M1oiLz48L3N2Zz4=)
![macOS](https://img.shields.io/badge/macOS-10.13%2B-000000?style=for-the-badge&logo=apple&logoColor=white)
![Linux](https://img.shields.io/badge/Linux-Any-FCC624?style=for-the-badge&logo=linux&logoColor=white)
<div align="left">
<h1>Twitter/X Media Batch Downloader</h1>
<p>
Downloads original-quality images and videos from Twitter/X accounts.
</p>
<p>
<a href="https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/stargazers"><img
src="https://img.shields.io/github/stars/afkarxyz/Twitter-X-Media-Batch-Downloader?color=ffcb47&labelColor=black&logo=github&label=Stars" /></a><a
href="https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases"><img
src="https://img.shields.io/github/downloads/afkarxyz/Twitter-X-Media-Batch-Downloader/total?color=22c55e&labelColor=black&logo=github&label=Downloads" /></a><a
href="https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest"><img
src="https://img.shields.io/github/v/release/afkarxyz/Twitter-X-Media-Batch-Downloader?color=8b5cf6&labelColor=black&logo=github&label=Latest%20Release" /></a><a
href="https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest"><img
src="https://img.shields.io/badge/Windows-10%2B-369eff?labelColor=black&logo=data:image/svg+xml;base64,PHN2ZyB4bWxucz0iaHR0cDovL3d3dy53My5vcmcvMjAwMC9zdmciIHdpZHRoPSI1MTIiIGhlaWdodD0iNTEyIiB2aWV3Qm94PSIwIDAgMjAgMjAiPjxwYXRoIGZpbGw9IiNmZmZmZmYiIGZpbGwtcnVsZT0iZXZlbm9kZCIgZD0iTTIwIDEwLjg3M1YyMEw4LjQ3OSAxOC41MzdsLjAwMS03LjY2NEgyMFptLTEzLjEyIDBsLS4wMDEgNy40NjFMMCAxNy40NjF2LTYuNTg4aDYuODhaTTIwIDkuMjczSDguNDhsLS4wMDEtNy44MUwyMCAwdjkuMjczWk02Ljg3OSAxLjY2NmwuMDAxIDcuNjA3SDBWMi41MzlsNi44NzktLjg3M1oiLz48L3N2Zz4=" /></a><a
href="https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest"><img
src="https://img.shields.io/badge/macOS-10.13%2B-FFFFFF?labelColor=black&logo=apple&logoColor=white" /></a><a
href="https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest"><img
src="https://img.shields.io/badge/Linux-Any-FCC624?labelColor=black&logo=linux&logoColor=white" /></a>
<br />
<br />
<a href="https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest" target="_blank"><img
src="https://github.com/user-attachments/assets/556bc876-871b-4ac1-af9e-a9001c6b9bbf" alt="Dark"
width="49%" /></a>
<a href="https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases/latest" target="_blank"><img
src="https://github.com/user-attachments/assets/338f11b5-9ddb-4074-8185-aaee13772bdf" alt="Light"
width="49%" /></a>
</p>
</div>
### [Download](https://github.com/afkarxyz/Twitter-X-Media-Batch-Downloader/releases)
![Image](https://github.com/user-attachments/assets/324243e4-b64b-4ea2-9f3d-8b08575a138e)
- If you're familiar with userscripts, install it [**here**](https://greasyfork.org/en/scripts/523157)
- To install the Chrome extension version, click [**here**](https://chromewebstore.google.com/detail/cboceolmgkoobpfjiojkigmihijfgmdo)
- Also available on the web at [**MediaBatchDL.com**](https://mediabatchdl.com)
- Also available on the web at [**TwitterDL.app**](https://twitterdl.app)
## How to Obtain Auth Token
@@ -31,4 +50,4 @@ A GUI tool to download original-quality images and videos from Twitter/X account
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
![image](https://github.com/user-attachments/assets/8e81dd8f-f8be-4254-9cf6-cacfa97743e9)
![image](https://github.com/user-attachments/assets/8e81dd8f-f8be-4254-9cf6-cacfa97743e9)
+9 -1
View File
@@ -243,6 +243,7 @@ type MediaItemRequest struct {
Content string `json:"content,omitempty"`
OriginalFilename string `json:"original_filename,omitempty"`
AuthorUsername string `json:"author_username,omitempty"`
AccountName string `json:"account_name,omitempty"`
}
type DownloadMediaWithMetadataRequest struct {
@@ -256,6 +257,9 @@ type DownloadMediaWithMetadataRequest struct {
Proxy string `json:"proxy,omitempty"`
FilenameTemplate string `json:"filename_template,omitempty"`
FolderTemplate string `json:"folder_template,omitempty"`
AutoConvertGIFs bool `json:"auto_convert_gifs,omitempty"`
GIFQuality string `json:"gif_quality,omitempty"`
GIFResolution string `json:"gif_resolution,omitempty"`
}
type DownloadMediaResponse struct {
@@ -350,7 +354,7 @@ func (a *App) DownloadMediaWithMetadata(req DownloadMediaWithMetadataRequest) (D
}
username := req.Username
if item.AuthorUsername != "" {
if (req.Username == "bookmarks" || req.Username == "likes") && item.AuthorUsername != "" {
username = item.AuthorUsername
}
@@ -360,6 +364,7 @@ func (a *App) DownloadMediaWithMetadata(req DownloadMediaWithMetadataRequest) (D
TweetID: int64(item.TweetID),
Type: item.Type,
Username: username,
AccountName: item.AccountName,
Content: item.Content,
OriginalFilename: originalFilename,
}
@@ -402,6 +407,9 @@ func (a *App) DownloadMediaWithMetadata(req DownloadMediaWithMetadataRequest) (D
RetryAttempts: req.RetryAttempts,
FilenameTemplate: req.FilenameTemplate,
FolderTemplate: req.FolderTemplate,
AutoConvertGIFs: req.AutoConvertGIFs,
GIFQuality: req.GIFQuality,
GIFResolution: req.GIFResolution,
}
downloaded, skipped, failed, err := backend.DownloadMediaWithMetadataProgressAndStatus(
+143 -18
View File
@@ -49,6 +49,9 @@ type DownloadOptions struct {
RetryAttempts int
FilenameTemplate string
FolderTemplate string
AutoConvertGIFs bool
GIFQuality string
GIFResolution string
}
func NormalizeDownloadOptions(options DownloadOptions) DownloadOptions {
@@ -63,6 +66,7 @@ type MediaItem struct {
TweetID int64 `json:"tweet_id"`
Type string `json:"type"`
Username string `json:"username"`
AccountName string `json:"account_name,omitempty"`
Content string `json:"content,omitempty"`
OriginalFilename string `json:"original_filename,omitempty"`
}
@@ -247,6 +251,13 @@ type downloadTask struct {
index int
}
type pendingDownloadTask struct {
task downloadTask
typeDir string
baseName string
ext string
}
func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir string, username string, progress ProgressCallback, itemStatus ItemStatusCallback, ctx context.Context, options DownloadOptions, customProxy string) (downloaded int, skipped int, failed int, err error) {
if ctx == nil {
ctx = context.Background()
@@ -259,7 +270,8 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
}
tweetMediaCount := make(map[string]map[int64]int)
tasks := make([]downloadTask, 0, total)
pendingTasks := make([]pendingDownloadTask, 0, total)
filenameCounts := make(map[string]int)
downloadDate := time.Now().Format("20060102")
for i, item := range items {
@@ -268,6 +280,10 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
if itemUsername == "" {
itemUsername = username
}
itemAccountName := item.AccountName
if itemAccountName == "" {
itemAccountName = itemUsername
}
if tweetMediaCount[itemUsername] == nil {
tweetMediaCount[itemUsername] = make(map[int64]int)
@@ -287,7 +303,7 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
subfolder = "other"
}
baseDir := filepath.Join(outputDir, renderFolder(options.FolderTemplate, itemUsername, downloadDate))
baseDir := filepath.Join(outputDir, renderFolder(options.FolderTemplate, itemUsername, itemAccountName, downloadDate))
if err := os.MkdirAll(baseDir, 0755); err != nil {
continue
}
@@ -309,20 +325,53 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
mediaID = ExtractOriginalFilename(item.URL)
}
filename := renderFilename(options.FilenameTemplate, itemUsername, timestamp, item.TweetID, item.Type, mediaIndex, mediaID) + ext
outputPath := filepath.Join(typeDir, filename)
baseName := renderFilename(options.FilenameTemplate, itemUsername, itemAccountName, timestamp, item.TweetID, item.Type, mediaIndex, mediaID)
filenameCounts[filenameCollisionKey(typeDir, baseName, ext)]++
tasks = append(tasks, downloadTask{
item: item,
outputPath: outputPath,
index: i,
pendingTasks = append(pendingTasks, pendingDownloadTask{
task: downloadTask{
item: item,
index: i,
},
typeDir: typeDir,
baseName: baseName,
ext: ext,
})
}
filenameIndexes := make(map[string]int, len(filenameCounts))
tasks := make([]downloadTask, 0, len(pendingTasks))
for _, pending := range pendingTasks {
key := filenameCollisionKey(pending.typeDir, pending.baseName, pending.ext)
filenameIndexes[key]++
filename := formatDownloadFilename(
pending.baseName,
pending.ext,
filenameCounts[key],
filenameIndexes[key],
)
if options.SkipExistingFiles {
canonicalPath := filepath.Join(pending.typeDir, formatDownloadFilename(pending.baseName, pending.ext, 1, 1))
if exists, err := fileExists(canonicalPath); err == nil && exists {
pending.task.outputPath = canonicalPath
tasks = append(tasks, pending.task)
continue
}
}
pending.task.outputPath = filepath.Join(pending.typeDir, filename)
tasks = append(tasks, pending.task)
}
var downloadedCount int64
var skippedCount int64
var failedCount int64
var completedCount int64
var conversionWG sync.WaitGroup
taskChan := make(chan downloadTask, len(tasks))
var wg sync.WaitGroup
@@ -421,6 +470,15 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
atomic.AddInt64(&downloadedCount, 1)
status = "success"
if shouldAutoConvertGIF(task.item.Type, options) && ctx.Err() == nil {
conversionWG.Add(1)
go func(inputPath string) {
defer conversionWG.Done()
outputPath := strings.TrimSuffix(inputPath, filepath.Ext(inputPath)) + ".gif"
_ = ConvertMP4ToGIFWithContext(ctx, inputPath, outputPath, normalizeGIFQuality(options.GIFQuality), normalizeGIFResolution(options.GIFResolution))
}(task.outputPath)
}
}
if itemStatus != nil {
@@ -444,6 +502,7 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
close(taskChan)
wg.Wait()
conversionWG.Wait()
if err := ctx.Err(); err != nil {
return int(downloadedCount), int(skippedCount), int(failedCount), err
@@ -452,6 +511,34 @@ func DownloadMediaWithMetadataProgressAndStatus(items []MediaItem, outputDir str
return int(downloadedCount), int(skippedCount), int(failedCount), nil
}
func shouldAutoConvertGIF(mediaType string, options DownloadOptions) bool {
if !options.AutoConvertGIFs || !IsFFmpegInstalled() {
return false
}
switch mediaType {
case "gif", "animated_gif":
return true
default:
return false
}
}
func normalizeGIFQuality(quality string) string {
if quality == "better" {
return quality
}
return "fast"
}
func normalizeGIFResolution(resolution string) string {
switch resolution {
case "original", "high", "medium", "low":
return resolution
default:
return "original"
}
}
func downloadFileWithContext(ctx context.Context, client *http.Client, url, outputPath string, allowOverwrite bool, keepPartialOnFailure bool) error {
req, err := http.NewRequestWithContext(ctx, "GET", url, nil)
if err != nil {
@@ -527,12 +614,15 @@ func formatTimestamp(dateStr string) string {
return "00000000_000000"
}
func renderFilename(template, username, timestamp string, tweetID int64, mediaType string, index int, mediaID string) string {
func renderFilename(template, username, accountName, timestamp string, tweetID int64, mediaType string, index int, mediaID string) string {
if strings.TrimSpace(template) == "" {
template = "{username}_{date}_{tweet_id}_{index}"
template = "{handle}_{date}_{tweet_id}"
}
replacer := strings.NewReplacer(
"{handle}", sanitizeFilenamePart(username),
"{name}", sanitizeFilenamePart(accountName),
"{username}", sanitizeFilenamePart(username),
"{account_name}", sanitizeFilenamePart(accountName),
"{date}", timestamp,
"{tweet_id}", fmt.Sprintf("%d", tweetID),
"{index}", fmt.Sprintf("%02d", index),
@@ -540,25 +630,37 @@ func renderFilename(template, username, timestamp string, tweetID int64, mediaTy
"{type}", sanitizeFilenamePart(mediaType),
)
name := strings.TrimSpace(replacer.Replace(template))
name = sanitizeFilenamePart(name)
if name == "" {
name = fmt.Sprintf("%s_%s_%d_%02d", username, timestamp, tweetID, index)
}
if mediaID != "" && !strings.Contains(template, "{media_id}") {
name = name + "_" + sanitizeFilenamePart(mediaID)
name = sanitizeFilenamePart(fmt.Sprintf("%s_%s_%d", username, timestamp, tweetID))
}
return name
}
func renderFolder(template, username, date string) string {
func filenameCollisionKey(dir, baseName, ext string) string {
return dir + "\x00" + baseName + ext
}
func formatDownloadFilename(baseName, ext string, duplicateCount, duplicateIndex int) string {
if duplicateCount > 1 {
return fmt.Sprintf("%s_%02d%s", baseName, duplicateIndex, ext)
}
return baseName + ext
}
func renderFolder(template, username, accountName, date string) string {
if strings.TrimSpace(template) == "" {
template = "{username}"
template = "{handle}"
}
replacer := strings.NewReplacer(
"{handle}", sanitizeFilenamePart(username),
"{name}", sanitizeFilenamePart(accountName),
"{username}", sanitizeFilenamePart(username),
"{account_name}", sanitizeFilenamePart(accountName),
"{date}", date,
)
name := strings.TrimSpace(replacer.Replace(template))
name = sanitizeFilenamePart(name)
if name == "" {
name = sanitizeFilenamePart(username)
}
@@ -566,13 +668,36 @@ func renderFolder(template, username, date string) string {
}
func sanitizeFilenamePart(s string) string {
return strings.TrimSpace(strings.Map(func(r rune) rune {
cleaned := strings.TrimSpace(strings.Map(func(r rune) rune {
switch r {
case '\\', '/', ':', '*', '?', '"', '<', '>', '|':
return -1
}
if r >= 0 && r < 32 {
return -1
}
return r
}, s))
cleaned = strings.TrimRight(cleaned, ". ")
if isWindowsReservedName(cleaned) {
return cleaned + "_"
}
return cleaned
}
func isWindowsReservedName(name string) bool {
base := name
if dotIndex := strings.IndexByte(base, '.'); dotIndex >= 0 {
base = base[:dotIndex]
}
base = strings.ToUpper(strings.TrimSpace(base))
switch base {
case "CON", "PRN", "AUX", "NUL":
return true
}
return len(base) == 4 &&
((strings.HasPrefix(base, "COM") && base[3] >= '1' && base[3] <= '9') ||
(strings.HasPrefix(base, "LPT") && base[3] >= '1' && base[3] <= '9'))
}
func getExtension(mediaURL string, mediaType string) string {
+12 -1
View File
@@ -2,6 +2,7 @@ package backend
import (
"archive/zip"
"context"
"encoding/json"
"fmt"
"io"
@@ -531,11 +532,18 @@ func normalizeFFmpegVersion(version string) string {
}
func ConvertMP4ToGIF(inputPath, outputPath, quality, resolution string) error {
return ConvertMP4ToGIFWithContext(context.Background(), inputPath, outputPath, quality, resolution)
}
func ConvertMP4ToGIFWithContext(ctx context.Context, inputPath, outputPath, quality, resolution string) error {
ffmpegPath := GetFFmpegPath()
if !IsFFmpegInstalled() {
return fmt.Errorf("ffmpeg not installed")
}
if ctx == nil {
ctx = context.Background()
}
var args []string
@@ -598,10 +606,13 @@ func ConvertMP4ToGIF(inputPath, outputPath, quality, resolution string) error {
}
}
cmd := exec.Command(ffmpegPath, args...)
cmd := exec.CommandContext(ctx, ffmpegPath, args...)
hideWindow(cmd)
output, err := cmd.CombinedOutput()
if err != nil {
if ctx.Err() != nil {
return ctx.Err()
}
return fmt.Errorf("ffmpeg error: %v, output: %s", err, string(output))
}
+2 -1
View File
@@ -11,6 +11,7 @@ import (
)
func OpenFolderInExplorer(path string) error {
os.WriteFile(filepath.Join(os.TempDir(), "openfolder.txt"), []byte(path), 0644)
info, err := os.Stat(path)
if err != nil {
return err
@@ -23,7 +24,7 @@ func OpenFolderInExplorer(path string) error {
switch runtime.GOOS {
case "windows":
cmd = exec.Command("explorer", path)
cmd = exec.Command("cmd", "/C", "start", "", path)
case "darwin":
cmd = exec.Command("open", path)
case "linux":
+34 -44
View File
@@ -41,21 +41,33 @@ func unregisterExtractorCommand(cmd *exec.Cmd) {
activeExtractorCommands.Unlock()
}
func runTrackedExtractorCommand(cmd *exec.Cmd) ([]byte, error) {
var output bytes.Buffer
cmd.Stdout = &output
cmd.Stderr = &output
func runTrackedExtractorCommand(cmd *exec.Cmd) (stdout, stderr []byte, err error) {
var stdoutBuffer bytes.Buffer
var stderrBuffer bytes.Buffer
cmd.Stdout = &stdoutBuffer
cmd.Stderr = &stderrBuffer
hideWindow(cmd)
if err := cmd.Start(); err != nil {
return nil, err
return nil, nil, err
}
registerExtractorCommand(cmd)
defer unregisterExtractorCommand(cmd)
err := cmd.Wait()
return output.Bytes(), err
err = cmd.Wait()
return stdoutBuffer.Bytes(), stderrBuffer.Bytes(), err
}
func extractorErrorOutput(stdout, stderr []byte) string {
parts := make([]string, 0, 2)
if text := strings.TrimSpace(string(stderr)); text != "" {
parts = append(parts, text)
}
if text := strings.TrimSpace(string(stdout)); text != "" {
parts = append(parts, text)
}
return strings.Join(parts, "\n")
}
func getExecutableName() string {
@@ -272,6 +284,7 @@ type TimelineEntry struct {
Verified bool `json:"verified,omitempty"`
OriginalFilename string `json:"original_filename,omitempty"`
AuthorUsername string `json:"author_username,omitempty"`
AuthorName string `json:"author_name,omitempty"`
}
type AccountInfo struct {
@@ -575,6 +588,7 @@ func textEntry(t richTweet) TimelineEntry {
Source: t.Source,
Verified: isVerified(t.Author),
AuthorUsername: t.Author.Username,
AuthorName: t.Author.Name,
}
}
@@ -608,6 +622,7 @@ func mediaEntry(t richTweet, m richMedia, videoQuality, imageSize string) Timeli
Source: t.Source,
Verified: isVerified(t.Author),
AuthorUsername: t.Author.Username,
AuthorName: t.Author.Name,
}
}
@@ -695,11 +710,10 @@ func ExtractTimeline(req TimelineRequest) (*TwitterResponse, error) {
}
includeText := req.IncludeText
wantsRetweets := req.Retweets
timelineType := req.TimelineType
if timelineType == "" {
if includeText || wantsRetweets {
if includeText {
timelineType = "tweets"
} else {
timelineType = "media"
@@ -722,7 +736,7 @@ func ExtractTimeline(req TimelineRequest) (*TwitterResponse, error) {
args = append(args, "--limit", fmt.Sprintf("%d", req.BatchSize))
}
if timelineType == "tweets" || timelineType == "timeline" {
if timelineType == "tweets" || timelineType == "timeline" || timelineType == "media" {
if req.Retweets {
args = append(args, "--retweets", "include")
} else {
@@ -743,10 +757,10 @@ func ExtractTimeline(req TimelineRequest) (*TwitterResponse, error) {
"PYTHONIOENCODING=utf-8",
"PYTHONUTF8=1",
)
output, err := runTrackedExtractorCommand(cmd)
stdout, stderr, err := runTrackedExtractorCommand(cmd)
if err != nil {
outputStr := string(output)
outputStr := extractorErrorOutput(stdout, stderr)
if strings.TrimSpace(outputStr) == "" {
return nil, fmt.Errorf("xtractor process terminated before returning data")
}
@@ -754,13 +768,12 @@ func ExtractTimeline(req TimelineRequest) (*TwitterResponse, error) {
return nil, fmt.Errorf("%s", errorMsg)
}
jsonStr := extractJSON(string(output))
jsonStr := strings.TrimSpace(string(stdout))
if jsonStr == "" {
outputStr := string(output)
if strings.TrimSpace(outputStr) == "" {
if strings.TrimSpace(string(stderr)) == "" {
return nil, fmt.Errorf("empty_response: Xtractor returned no data. The timeline may be empty or inaccessible")
}
return nil, fmt.Errorf("parse_error: Could not parse xtractor output. Raw output: %s", outputStr)
return nil, fmt.Errorf("empty_response: Xtractor returned no JSON. Logs: %s", strings.TrimSpace(string(stderr)))
}
resp, err := parseRichResponse(jsonStr)
@@ -845,10 +858,10 @@ func ExtractDateRange(req DateRangeRequest) (*TwitterResponse, error) {
"PYTHONIOENCODING=utf-8",
"PYTHONUTF8=1",
)
output, err := runTrackedExtractorCommand(cmd)
stdout, stderr, err := runTrackedExtractorCommand(cmd)
if err != nil {
outputStr := string(output)
outputStr := extractorErrorOutput(stdout, stderr)
if strings.TrimSpace(outputStr) == "" {
return nil, fmt.Errorf("xtractor process terminated before returning data")
}
@@ -856,13 +869,12 @@ func ExtractDateRange(req DateRangeRequest) (*TwitterResponse, error) {
return nil, fmt.Errorf("%s", errorMsg)
}
jsonStr := extractJSON(string(output))
jsonStr := strings.TrimSpace(string(stdout))
if jsonStr == "" {
outputStr := string(output)
if strings.TrimSpace(outputStr) == "" {
if strings.TrimSpace(string(stderr)) == "" {
return nil, fmt.Errorf("empty_response: Xtractor returned no data. The timeline may be empty or inaccessible")
}
return nil, fmt.Errorf("parse_error: Could not parse xtractor output. Raw output: %s", outputStr)
return nil, fmt.Errorf("empty_response: Xtractor returned no JSON. Logs: %s", strings.TrimSpace(string(stderr)))
}
resp, err := parseRichResponse(jsonStr)
@@ -903,25 +915,3 @@ func getExtractorPath() string {
baseDir := filepath.Join(homeDir, ".twitterxmediabatchdownloader")
return filepath.Join(baseDir, getExecutableName())
}
func extractJSON(output string) string {
start := strings.Index(output, "{")
if start == -1 {
return ""
}
depth := 0
for i := start; i < len(output); i++ {
if output[i] == '{' {
depth++
} else if output[i] == '}' {
depth--
if depth == 0 {
return output[start : i+1]
}
}
}
return ""
}
+1 -1
View File
@@ -1 +1 @@
66d76291490cdae022ca7ad778594a1f
b9015b5860764ef52b634f74fd0f1180
+8 -2
View File
@@ -9,6 +9,7 @@ import { openExternal } from "@/lib/utils";
import { compareVersionNumbers } from "@/lib/version";
import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { logger } from "@/lib/logger";
import { initDownloadProgressEvents } from "@/lib/download-state";
import { saveFetchState, getFetchState, clearFetchState, getResumableInfo, mergeTimelines, saveCursor, getCursor, clearCursor, type FetchState, } from "@/lib/fetch-state";
import { TitleBar } from "@/components/TitleBar";
import { Sidebar, type PageType } from "@/components/Sidebar";
@@ -165,10 +166,12 @@ function App() {
}
};
mediaQuery.addEventListener("change", handleChange);
const cleanupDownloadProgress = initDownloadProgressEvents();
checkForUpdates();
loadHistory();
return () => {
mediaQuery.removeEventListener("change", handleChange);
cleanupDownloadProgress();
};
}, []);
useEffect(() => {
@@ -438,7 +441,7 @@ function App() {
}
else {
const batchSize = BATCH_SIZE;
let timelineType = (settings.includeText || retweets) ? "tweets" : "media";
let timelineType = settings.includeText ? "tweets" : "media";
if (isBookmarks) {
timelineType = "bookmarks";
}
@@ -1503,6 +1506,9 @@ function App() {
</>);
}
};
const usesWideContent = currentPage === "main"
? fetchType === "multiple" || !!result
: !["settings", "support"].includes(currentPage);
return (<TooltipProvider>
<div className="h-screen overflow-hidden bg-background">
<DependencySetupDialog />
@@ -1511,7 +1517,7 @@ function App() {
<div id="app-content-scroll" className="fixed top-10 right-0 bottom-0 left-14 overflow-y-auto overflow-x-hidden">
<div className="p-4 md:p-8">
<div className="max-w-5xl mx-auto">
<div className={usesWideContent ? "w-full" : "max-w-5xl mx-auto"}>
{renderPage()}
</div>
</div>
Binary file not shown.

After

Width:  |  Height:  |  Size: 45 KiB

Binary file not shown.

After

Width:  |  Height:  |  Size: 44 KiB

+33 -17
View File
@@ -316,17 +316,24 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
toast.error("Failed to load account data");
}
};
const handleOpenFolder = async (username: string) => {
const handleOpenFolder = async (account: AccountListItem) => {
const settings = getSettings();
let folderName = username;
if (username === "bookmarks") {
folderName = "My Bookmarks";
const basePath = settings.downloadPath || "";
if (!basePath) {
toast.error("Download folder is not set");
return;
}
else if (username === "likes") {
folderName = "My Likes";
}
const folderPath = await GetFolderPath(settings.downloadPath, folderName);
let username = account.username || account.name || "";
try {
const responseJSON = await GetAccountFromDB(account.id);
const data = JSON.parse(responseJSON);
username = data.account_info?.name || username;
}
catch {
}
const folderName = getFolderNameForAccount(username);
try {
const folderPath = await GetFolderPath(basePath, folderName);
await OpenFolder(folderPath);
}
catch (error) {
@@ -1053,13 +1060,13 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
{formatNumberWithComma(account.total_media)} media
</div>
</div>
<div className="flex gap-1">
<div className="flex gap-1" onClick={(e) => e.stopPropagation()}>
{downloadingAccountId === account.id ? (<Button variant="outline" size="icon" className="h-8 w-8" onClick={handleStopDownload}>
<StopCircle className="h-4 w-4 text-destructive"/>
</Button>) : (<Button variant="default" size="icon" className="h-8 w-8" onClick={() => handleDownload(account.id, account.username)} disabled={isDownloading}>
<Download className="h-4 w-4"/>
</Button>)}
<Button variant="outline" size="icon" className="h-8 w-8" onClick={() => handleOpenFolder(account.username)} disabled={!folderExistence.get(account.id)}>
<Button variant="outline" size="icon" className="h-8 w-8" onClick={() => handleOpenFolder(account)} disabled={!folderExistence.get(account.id)}>
<FolderOpen className="h-4 w-4"/>
</Button>
<DropdownMenu>
@@ -1069,7 +1076,10 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{!isPrivateAccount(account.username) && (<DropdownMenuItem onClick={() => handleEditGroup(account)}>
{!isPrivateAccount(account.username) && (<DropdownMenuItem onSelect={(event) => {
event.preventDefault();
handleEditGroup(account);
}}>
<Pencil className="h-4 w-4 mr-2"/>
Edit Group
</DropdownMenuItem>)}
@@ -1147,13 +1157,13 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
{formatNumberWithComma(account.total_media)} media
</div>
</div>
<div className="flex gap-1">
<div className="flex gap-1" onClick={(e) => e.stopPropagation()}>
{downloadingAccountId === account.id ? (<Button variant="outline" size="icon" className="h-7 w-7" onClick={handleStopDownload}>
<StopCircle className="h-3 w-3 text-destructive"/>
</Button>) : (<Button variant="default" size="icon" className="h-7 w-7" onClick={() => handleDownload(account.id, account.username)} disabled={isDownloading}>
<Download className="h-3 w-3"/>
</Button>)}
<Button variant="outline" size="icon" className="h-7 w-7" onClick={() => handleOpenFolder(account.username)} disabled={!folderExistence.get(account.id)}>
<Button variant="outline" size="icon" className="h-7 w-7" onClick={() => handleOpenFolder(account)} disabled={!folderExistence.get(account.id)}>
<FolderOpen className="h-3 w-3"/>
</Button>
<DropdownMenu>
@@ -1163,7 +1173,10 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
</Button>
</DropdownMenuTrigger>
<DropdownMenuContent align="end">
{!isPrivateAccount(account.username) && (<DropdownMenuItem onClick={() => handleEditGroup(account)}>
{!isPrivateAccount(account.username) && (<DropdownMenuItem onSelect={(event) => {
event.preventDefault();
handleEditGroup(account);
}}>
<Pencil className="h-4 w-4 mr-2"/>
Edit Group
</DropdownMenuItem>)}
@@ -1258,7 +1271,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
{account.last_fetched} {getRelativeTime(account.last_fetched)}
</div>
</div>
<div className="flex items-center gap-2">
<div className="flex items-center gap-2" onClick={(e) => e.stopPropagation()}>
{downloadingAccountId === account.id ? (<Tooltip>
<TooltipTrigger asChild>
<Button variant="outline" size="icon" onClick={handleStopDownload}>
@@ -1276,7 +1289,7 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
</Tooltip>)}
<Tooltip>
<TooltipTrigger asChild>
<Button variant="outline" size="icon" onClick={() => handleOpenFolder(account.username)} disabled={!folderExistence.get(account.id)}>
<Button variant="outline" size="icon" onClick={() => handleOpenFolder(account)} disabled={!folderExistence.get(account.id)}>
<FolderOpen className="h-4 w-4"/>
</Button>
</TooltipTrigger>
@@ -1294,7 +1307,10 @@ export function DatabaseView({ onLoadAccount, onUpdateSelected }: DatabaseViewPr
<TooltipContent>More Options</TooltipContent>
</Tooltip>
<DropdownMenuContent align="end">
{!isPrivateAccount(account.username) && (<DropdownMenuItem onClick={() => handleEditGroup(account)}>
{!isPrivateAccount(account.username) && (<DropdownMenuItem onSelect={(event) => {
event.preventDefault();
handleEditGroup(account);
}}>
<Pencil className="h-4 w-4 mr-2"/>
Edit Group
</DropdownMenuItem>)}
@@ -4,30 +4,40 @@ import { Button } from "@/components/ui/button";
import { Dialog, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, } from "@/components/ui/dialog";
import { Spinner } from "@/components/ui/spinner";
import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { compareVersionNumbers } from "@/lib/version";
import { Quit } from "../../wailsjs/runtime/runtime";
import { DownloadExtractor, IsExtractorInstalled } from "../../wailsjs/go/main/App";
import { DownloadExtractor, GetExtractorVersionStatus } from "../../wailsjs/go/main/App";
interface DependencySetupDialogProps {
onInstalled?: () => void;
}
interface GithubReleaseResponse {
tag_name?: string;
interface ExtractorVersionStatus {
installed: boolean;
installed_version?: string;
latest_version?: string;
}
const extractorReleaseAPIURL = "https://api.github.com/repos/afkarxyz/xtractor-binaries/releases/latest";
export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProps) {
const [open, setOpen] = useState(false);
const [checking, setChecking] = useState(true);
const [downloading, setDownloading] = useState(false);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [updateRequired, setUpdateRequired] = useState(false);
const [installedVersion, setInstalledVersion] = useState<string | null>(null);
const [releaseVersion, setReleaseVersion] = useState<string | null>(null);
const [releaseStatusMessage, setReleaseStatusMessage] = useState("Checking latest GitHub release...");
useEffect(() => {
let cancelled = false;
const abortController = new AbortController();
const checkDependency = async () => {
try {
const installed = await IsExtractorInstalled();
const status = await GetExtractorVersionStatus() as ExtractorVersionStatus;
const nextInstalledVersion = status.installed_version?.trim() || null;
const nextLatestVersion = status.latest_version?.trim() || null;
const nextUpdateRequired = !!(status.installed && nextLatestVersion && (!nextInstalledVersion || compareVersionNumbers(nextLatestVersion, nextInstalledVersion) > 0));
if (!cancelled) {
setOpen(!installed);
setUpdateRequired(nextUpdateRequired);
setInstalledVersion(nextInstalledVersion);
setReleaseVersion(nextLatestVersion);
setReleaseStatusMessage(nextLatestVersion ? `Latest GitHub release: ${nextLatestVersion}` : "Latest GitHub release unavailable.");
setOpen(!status.installed || nextUpdateRequired);
setErrorMessage(null);
}
}
@@ -43,39 +53,9 @@ export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProp
}
}
};
const loadReleaseInfo = async () => {
try {
const response = await fetch(extractorReleaseAPIURL, {
headers: {
Accept: "application/vnd.github+json",
},
signal: abortController.signal,
});
if (!response.ok) {
throw new Error(`GitHub release status ${response.status}`);
}
const release = (await response.json()) as GithubReleaseResponse;
const version = release.tag_name?.trim();
if (!version) {
throw new Error("Missing GitHub release tag");
}
if (!cancelled) {
setReleaseVersion(version);
setReleaseStatusMessage(`Latest GitHub release: ${version}`);
}
}
catch {
if (!cancelled && !abortController.signal.aborted) {
setReleaseVersion(null);
setReleaseStatusMessage("Latest GitHub release unavailable.");
}
}
};
void checkDependency();
void loadReleaseInfo();
return () => {
cancelled = true;
abortController.abort();
};
}, []);
const handleDownload = async () => {
@@ -84,7 +64,7 @@ export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProp
try {
await DownloadExtractor();
setOpen(false);
toast.success("Xtractor installed");
toast.success(updateRequired ? "Xtractor updated" : "Xtractor installed");
onInstalled?.();
}
catch (error) {
@@ -114,11 +94,16 @@ export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProp
<div className="mb-2 flex h-12 w-12 items-center justify-center rounded-2xl border bg-muted/50">
<Package className="h-6 w-6"/>
</div>
<DialogTitle>Download Xtractor</DialogTitle>
<DialogDescription>Xtractor is required before you can use this app.</DialogDescription>
<DialogTitle>{updateRequired ? "Update Xtractor" : "Download Xtractor"}</DialogTitle>
<DialogDescription>
{updateRequired ? "A newer Xtractor binary is available or the installed version could not be verified." : "Xtractor is required before you can use this app."}
</DialogDescription>
</DialogHeader>
<div className="space-y-3">
{updateRequired && releaseVersion && (<p className="text-sm text-amber-600 dark:text-amber-400">
Installed: {installedVersion || "unknown"} - Latest: {releaseVersion}
</p>)}
<p className="text-sm text-muted-foreground">{releaseVersion ? `Latest GitHub release: ${releaseVersion}` : releaseStatusMessage}</p>
{errorMessage && (<div className="flex items-start gap-2 rounded-lg border border-destructive/40 bg-destructive/10 p-3 text-sm text-destructive">
@@ -134,10 +119,10 @@ export function DependencySetupDialog({ onInstalled }: DependencySetupDialogProp
<Button onClick={handleDownload} disabled={downloading}>
{downloading ? (<>
<Spinner />
Downloading Xtractor...
{updateRequired ? "Updating Xtractor..." : "Downloading Xtractor..."}
</>) : (<>
<Download className="h-4 w-4"/>
Download Xtractor
{updateRequired ? "Update Xtractor" : "Download Xtractor"}
</>)}
</Button>
</DialogFooter>
+102 -313
View File
@@ -11,21 +11,11 @@ import type { TimelineEntry, AccountInfo } from "@/types/api";
import { logger } from "@/lib/logger";
import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { getSettings, renderFolderTemplate } from "@/lib/settings";
import { getCachedDependencyStatus, getCachedMediaFolderStatus, setCachedDependencyStatus, setCachedMediaFolderStatus } from "@/lib/runtime-cache";
import { beginDownload, finishDownload, setDownloadItemStatus, useDownloadState } from "@/lib/download-state";
import { getCachedMediaFolderStatus, setCachedMediaFolderStatus } from "@/lib/runtime-cache";
import { openExternal } from "@/lib/utils";
import { DownloadMediaWithMetadata, DownloadProfileImage, OpenFolder, IsFFmpegInstalled, ConvertGIFs, StopDownload, CheckFolderExists, CheckGifsFolderHasMP4 } from "../../wailsjs/go/main/App";
import { EventsOn } from "../../wailsjs/runtime/runtime";
import { DownloadMediaWithMetadata, DownloadProfileImage, OpenFolder, StopDownload, CheckFolderExists } from "../../wailsjs/go/main/App";
import { main } from "../../wailsjs/go/models";
interface DownloadProgress {
current: number;
total: number;
percent: number;
}
interface DownloadItemStatus {
tweet_id: number;
index: number;
status: "success" | "failed" | "skipped";
}
interface MediaListProps {
accountInfo: AccountInfo;
timeline: TimelineEntry[];
@@ -188,6 +178,7 @@ function getAccountFolderName(accountInfo: AccountInfo): string {
const now = new Date();
const rendered = renderFolderTemplate(template, {
username: accountInfo.name,
accountName: accountInfo.nick,
date: `${now.getFullYear()}${pad(now.getMonth() + 1)}${pad(now.getDate())}`,
});
return rendered || accountInfo.name;
@@ -206,6 +197,12 @@ function pickVariantUrl(variants: {
export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType = "all", newMediaCount = null, }: MediaListProps) {
const settings = getSettings();
const folderName = getAccountFolderName(accountInfo);
const downloadState = useDownloadState();
const anyDownloadActive = downloadState.active;
const isDownloading = downloadState.active && downloadState.scope === "media";
const downloadProgress = isDownloading ? downloadState.progress : null;
const downloadingItem = isDownloading ? downloadState.currentItemKey : null;
const itemStatusByKey = downloadState.itemStatusByKey;
const cachedMediaFolderStatus = settings.downloadPath
? getCachedMediaFolderStatus(settings.downloadPath, folderName)
: null;
@@ -219,19 +216,10 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
useEffect(() => {
localStorage.setItem("resultViewMode", viewMode);
}, [viewMode]);
const [isDownloading, setIsDownloading] = useState(false);
const [downloadProgress, setDownloadProgress] = useState<DownloadProgress | null>(null);
const [hasDownloaded, setHasDownloaded] = useState(false);
const [isConverting, setIsConverting] = useState(false);
const [ffmpegInstalled, setFfmpegInstalled] = useState(() => getCachedDependencyStatus("ffmpeg").installed ?? false);
const [showScrollTop, setShowScrollTop] = useState(false);
const [folderExists, setFolderExists] = useState(cachedMediaFolderStatus?.folderExists ?? false);
const [gifsFolderHasMP4, setGifsFolderHasMP4] = useState(cachedMediaFolderStatus?.gifsFolderHasMP4 ?? false);
const [previewIndex, setPreviewIndex] = useState<number | null>(null);
const [downloadedItems, setDownloadedItems] = useState<Set<string>>(new Set());
const [failedItems, setFailedItems] = useState<Set<string>>(new Set());
const [skippedItems, setSkippedItems] = useState<Set<string>>(new Set());
const [downloadingItem, setDownloadingItem] = useState<string | null>(null);
const [visibleCount, setVisibleCount] = useState<number>(MEDIA_LIST_PAGE_SIZE);
const loadMoreRef = useRef<HTMLDivElement>(null);
useEffect(() => {
@@ -282,24 +270,19 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
setVisibleCount(MEDIA_LIST_PAGE_SIZE);
}, [filteredTimeline.length]);
useEffect(() => {
const checkFoldersAndFFmpeg = async () => {
const checkFolders = async () => {
const settings = getSettings();
const basePath = settings.downloadPath;
const installed = await IsFFmpegInstalled();
setCachedDependencyStatus("ffmpeg", { installed });
setFfmpegInstalled(installed);
if (!basePath || !accountInfo.name)
return;
const exists = await CheckFolderExists(basePath, folderName);
const hasMP4 = exists ? await CheckGifsFolderHasMP4(basePath, folderName) : false;
setCachedMediaFolderStatus(basePath, folderName, {
folderExists: exists,
gifsFolderHasMP4: hasMP4,
gifsFolderHasMP4: false,
});
setFolderExists(exists);
setGifsFolderHasMP4(hasMP4);
};
checkFoldersAndFFmpeg();
checkFolders();
}, [accountInfo.name, accountInfo.nick, folderName, hasDownloaded]);
useEffect(() => {
const sentinel = loadMoreRef.current;
@@ -340,58 +323,6 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
document.body.style.overflow = previousOverflow;
};
}, [previewIndex]);
useEffect(() => {
const unsubscribe = EventsOn("download-progress", (progress: DownloadProgress) => {
setDownloadProgress(progress);
});
return () => {
unsubscribe();
};
}, []);
const currentDownloadingItemKeyRef = useRef<string | null>(null);
const bulkDownloadKeyMapRef = useRef<Map<number, string>>(new Map());
useEffect(() => {
const unsubscribe = EventsOn("download-item-status", (status: DownloadItemStatus) => {
const currentKey = currentDownloadingItemKeyRef.current;
const keyMap = bulkDownloadKeyMapRef.current;
let itemKey: string;
if (currentKey) {
itemKey = currentKey;
}
else if (keyMap.size > 0) {
itemKey = keyMap.get(status.index) ?? `${String(status.tweet_id)}-${status.index}`;
}
else {
itemKey = `${String(status.tweet_id)}-${status.index}`;
}
if (status.status === "success") {
setDownloadedItems((prev) => new Set(prev).add(itemKey));
if (currentKey) {
toast.success("Downloaded");
}
}
else if (status.status === "failed") {
setFailedItems((prev) => new Set(prev).add(itemKey));
if (currentKey) {
toast.error("Download failed");
}
}
else if (status.status === "skipped") {
setDownloadedItems((prev) => {
const newSet = new Set(prev);
newSet.delete(itemKey);
return newSet;
});
setSkippedItems((prev) => new Set(prev).add(itemKey));
if (currentKey) {
toast.info("Already exists");
}
}
});
return () => {
unsubscribe();
};
}, []);
const goToPrevious = () => {
if (previewIndex !== null && previewIndex > 0) {
setPreviewIndex(previewIndex - 1);
@@ -459,6 +390,73 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
}
return settings.downloadPath;
};
const createMediaItemRequest = (item: TimelineEntry) => new main.MediaItemRequest({
url: item.url,
date: item.date,
tweet_id: item.tweet_id,
type: item.type,
content: item.content || "",
original_filename: item.original_filename || "",
author_username: item.author_username || "",
account_name: item.author_name || accountInfo.nick || accountInfo.name,
});
const getItemStatusFlags = (itemKey: string) => {
const status = itemStatusByKey[itemKey];
return {
isItemDownloaded: status === "success",
isItemFailed: status === "failed",
isItemSkipped: status === "skipped",
isItemDownloading: downloadingItem === itemKey,
};
};
const handleDownloadItem = async (item: TimelineEntry, itemKey: string) => {
beginDownload({ current: 0, total: 1, percent: 0 }, { scope: "media", currentItemKey: itemKey, itemKeyByIndex: { 0: itemKey } });
try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({
items: [createMediaItemRequest(item)],
output_dir: getOutputDir(),
username: accountInfo.name,
concurrent_downloads: settings.concurrentDownloads || 10,
skip_existing: settings.skipExistingFiles,
delete_incomplete_files: settings.deleteIncompleteFiles,
retry_attempts: settings.retryAttempts,
proxy: settings.proxy || "",
filename_template: settings.filenameTemplate || "",
folder_template: settings.folderTemplate || "",
auto_convert_gifs: settings.autoConvertGifs,
gif_quality: settings.gifQuality || "fast",
gif_resolution: settings.gifResolution || "original",
});
const response = await DownloadMediaWithMetadata(request);
if (response.cancelled) {
toast.info(response.message || "Download stopped");
}
else if (response.success) {
if (response.skipped > 0) {
setDownloadItemStatus(itemKey, "skipped");
toast.info("Already exists");
}
else if (response.downloaded > 0) {
setDownloadItemStatus(itemKey, "success");
toast.success("Downloaded");
}
setHasDownloaded(true);
}
else {
setDownloadItemStatus(itemKey, "failed");
toast.error(response.message || "Download failed");
}
}
catch (error) {
setDownloadItemStatus(itemKey, "failed");
const errorMsg = error instanceof Error ? error.message : String(error);
toast.error(`Download failed: ${errorMsg}`);
}
finally {
finishDownload();
}
};
const handleDownload = async () => {
const itemsWithIndices = selectedItems.size > 0
? filteredTimeline
@@ -469,26 +467,16 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
toast.error("No media to download");
return;
}
const keyMap = new Map<number, string>();
const keyMap: Record<number, string> = {};
itemsWithIndices.forEach((entry, backendIndex) => {
keyMap.set(backendIndex, getItemKey(entry.item));
keyMap[backendIndex] = getItemKey(entry.item);
});
bulkDownloadKeyMapRef.current = keyMap;
setIsDownloading(true);
setDownloadProgress({ current: 0, total: itemsWithIndices.length, percent: 0 });
beginDownload({ current: 0, total: itemsWithIndices.length, percent: 0 }, { scope: "media", itemKeyByIndex: keyMap });
logger.info(`Starting download of ${itemsWithIndices.length} files...`);
try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({
items: itemsWithIndices.map(({ item }) => new main.MediaItemRequest({
url: item.url,
date: item.date,
tweet_id: item.tweet_id,
type: item.type,
content: item.content || "",
original_filename: item.original_filename || "",
author_username: item.author_username || "",
})),
items: itemsWithIndices.map(({ item }) => createMediaItemRequest(item)),
output_dir: getOutputDir(),
username: accountInfo.name,
concurrent_downloads: settings.concurrentDownloads || 10,
@@ -498,6 +486,9 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
proxy: settings.proxy || "",
filename_template: settings.filenameTemplate || "",
folder_template: settings.folderTemplate || "",
auto_convert_gifs: settings.autoConvertGifs,
gif_quality: settings.gifQuality || "fast",
gif_resolution: settings.gifResolution || "original",
});
const response = await DownloadMediaWithMetadata(request);
if (response.cancelled) {
@@ -528,17 +519,12 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
toast.success(message);
}
setHasDownloaded(true);
const installed = await IsFFmpegInstalled();
setCachedDependencyStatus("ffmpeg", { installed });
setFfmpegInstalled(installed);
if (settings.downloadPath) {
const hasMP4 = await CheckGifsFolderHasMP4(settings.downloadPath, folderName);
setCachedMediaFolderStatus(settings.downloadPath, folderName, {
folderExists: true,
gifsFolderHasMP4: hasMP4,
gifsFolderHasMP4: false,
});
setFolderExists(true);
setGifsFolderHasMP4(hasMP4);
}
}
else {
@@ -552,15 +538,14 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
toast.error("Download failed");
}
finally {
setIsDownloading(false);
setDownloadProgress(null);
bulkDownloadKeyMapRef.current = new Map();
finishDownload();
}
};
const handleStopDownload = async () => {
try {
const stopped = await StopDownload();
if (stopped) {
finishDownload();
logger.info("Download stopped by user");
toast.info("Stopped");
}
@@ -607,8 +592,8 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
}
else {
folderPath = settings.downloadPath
? `${settings.downloadPath}/${accountInfo.name}`
: accountInfo.name;
? `${settings.downloadPath}/${folderName}`
: folderName;
}
try {
await OpenFolder(folderPath);
@@ -625,52 +610,6 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
const handleOpenTweet = (tweetId: string) => {
openExternal(`https://x.com/${accountInfo.name}/status/${tweetId}`);
};
const handleConvertGifs = async () => {
const settings = getSettings();
const isBookmarks = accountInfo.nick === "My Bookmarks";
const isLikes = accountInfo.nick === "My Likes";
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);
logger.info("Converting GIFs...");
try {
const response = await ConvertGIFs({
folder_path: folderPath,
quality: settings.gifQuality || "fast",
resolution: settings.gifResolution || "high",
delete_original: false,
});
if (response.success) {
logger.success(`Converted ${response.converted} GIFs`);
toast.success(`${response.converted} GIFs converted`);
const hasMP4 = await CheckGifsFolderHasMP4(settings.downloadPath, folderName);
setCachedMediaFolderStatus(settings.downloadPath, folderName, {
folderExists: true,
gifsFolderHasMP4: hasMP4,
});
setGifsFolderHasMP4(hasMP4);
}
else {
logger.error(response.message);
toast.error("Convert failed");
}
}
catch (error) {
const errorMsg = error instanceof Error ? error.message : String(error);
logger.error(`Convert failed: ${errorMsg}`);
toast.error("Convert failed");
}
finally {
setIsConverting(false);
}
};
return (<div className="space-y-4">
{accountInfo.name === "bookmarks" || accountInfo.name === "likes" ? (<div className="flex items-center gap-4 p-4 bg-muted/50 rounded-lg">
@@ -819,21 +758,12 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
<FolderOpen className="h-4 w-4"/>
Open Folder
</Button>
<Button variant="outline" onClick={handleConvertGifs} disabled={isConverting || !gifsFolderHasMP4 || !ffmpegInstalled}>
{isConverting ? (<>
<Spinner />
Converting...
</>) : (<>
<Film className="h-4 w-4"/>
Convert GIFs
</>)}
</Button>
<div className="flex items-center gap-2">
{isDownloading && (<Button variant="destructive" onClick={handleStopDownload}>
<StopCircle className="h-4 w-4"/>
Stop
</Button>)}
<Button onClick={handleDownload} disabled={isDownloading}>
<Button onClick={handleDownload} disabled={anyDownloadActive}>
{isDownloading ? (<>
<Spinner />
Downloading...
@@ -870,10 +800,7 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
{filteredTimeline.slice(0, visibleCount).map((item, index) => {
const itemKey = getItemKey(item);
const isSelected = selectedItems.has(itemKey);
const isItemDownloaded = downloadedItems.has(itemKey);
const isItemFailed = failedItems.has(itemKey);
const isItemSkipped = skippedItems.has(itemKey);
const isItemDownloading = downloadingItem === itemKey;
const { isItemDownloaded, isItemFailed, isItemSkipped, isItemDownloading } = getItemStatusFlags(itemKey);
return (<div key={itemKey} onClick={() => openPreview(index)} className={`flex items-center gap-4 p-3 rounded-lg border-2 transition-all cursor-pointer ${isSelected ? "border-primary bg-primary/5" : "border-transparent hover:bg-muted/50"}`}>
<Checkbox checked={isSelected} onCheckedChange={() => toggleItem(itemKey)} onClick={(e) => e.stopPropagation()}/>
<div className="relative shrink-0">
@@ -912,53 +839,7 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
<div className="flex items-center gap-2 shrink-0">
<Tooltip>
<TooltipTrigger asChild>
<Button size="icon" variant="default" onClick={async () => {
setDownloadingItem(itemKey);
currentDownloadingItemKeyRef.current = itemKey;
try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({
items: [new main.MediaItemRequest({
url: item.url,
date: item.date,
tweet_id: item.tweet_id,
type: item.type,
content: item.content || "",
original_filename: item.original_filename || "",
author_username: item.author_username || "",
})],
output_dir: getOutputDir(),
username: accountInfo.name,
concurrent_downloads: settings.concurrentDownloads || 10,
skip_existing: settings.skipExistingFiles,
delete_incomplete_files: settings.deleteIncompleteFiles,
retry_attempts: settings.retryAttempts,
proxy: settings.proxy || "",
filename_template: settings.filenameTemplate || "",
folder_template: settings.folderTemplate || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.cancelled) {
toast.info(response.message || "Download stopped");
}
else if (response.success) {
setHasDownloaded(true);
}
else {
setFailedItems((prev) => new Set(prev).add(itemKey));
toast.error(response.message || "Download failed");
}
}
catch (error) {
setFailedItems((prev) => new Set(prev).add(itemKey));
const errorMsg = error instanceof Error ? error.message : String(error);
toast.error(`Download failed: ${errorMsg}`);
}
finally {
setDownloadingItem(null);
setTimeout(() => { currentDownloadingItemKeyRef.current = null; }, 1000);
}
}} disabled={downloadingItem !== null}>
<Button size="icon" variant="default" onClick={() => void handleDownloadItem(item, itemKey)} disabled={anyDownloadActive}>
{isItemDownloading ? (<Spinner />) : isItemSkipped ? (<FileCheck className="h-4 w-4"/>) : isItemDownloaded ? (<CheckCircle className="h-4 w-4"/>) : isItemFailed ? (<XCircle className="h-4 w-4"/>) : (<Download className="h-4 w-4"/>)}
</Button>
</TooltipTrigger>
@@ -972,14 +853,11 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
</div>
</div>);
})}
</div>) : (<div className={`grid gap-3 ${viewMode === "large" ? "grid-cols-4" : "grid-cols-6"}`}>
</div>) : (<div className={`grid gap-3 ${viewMode === "large" ? "grid-cols-[repeat(auto-fill,minmax(14rem,1fr))]" : "grid-cols-[repeat(auto-fill,minmax(10rem,1fr))]"}`}>
{filteredTimeline.slice(0, visibleCount).map((item, index) => {
const itemKey = getItemKey(item);
const isSelected = selectedItems.has(itemKey);
const isItemDownloaded = downloadedItems.has(itemKey);
const isItemFailed = failedItems.has(itemKey);
const isItemSkipped = skippedItems.has(itemKey);
const isItemDownloading = downloadingItem === itemKey;
const { isItemDownloaded, isItemFailed, isItemSkipped, isItemDownloading } = getItemStatusFlags(itemKey);
return (<div key={itemKey} className={`relative group rounded-lg overflow-hidden border-2 transition-all ${isSelected ? "border-primary" : "border-transparent hover:border-muted-foreground/30"}`}>
<div className="aspect-square bg-muted relative cursor-pointer" onClick={() => openPreview(index)}>
@@ -996,51 +874,8 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
<TooltipTrigger asChild>
<Button size="icon" variant="default" className="h-8 w-8" onClick={async (e) => {
e.stopPropagation();
setDownloadingItem(itemKey);
currentDownloadingItemKeyRef.current = itemKey;
try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({
items: [new main.MediaItemRequest({
url: item.url,
date: item.date,
tweet_id: item.tweet_id,
type: item.type,
content: item.content || "",
author_username: item.author_username || "",
})],
output_dir: getOutputDir(),
username: accountInfo.name,
concurrent_downloads: settings.concurrentDownloads || 10,
skip_existing: settings.skipExistingFiles,
delete_incomplete_files: settings.deleteIncompleteFiles,
retry_attempts: settings.retryAttempts,
proxy: settings.proxy || "",
filename_template: settings.filenameTemplate || "",
folder_template: settings.folderTemplate || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.cancelled) {
toast.info(response.message || "Download stopped");
}
else if (response.success) {
setHasDownloaded(true);
}
else {
setFailedItems((prev) => new Set(prev).add(itemKey));
toast.error(response.message || "Download failed");
}
}
catch (error) {
setFailedItems((prev) => new Set(prev).add(itemKey));
const errorMsg = error instanceof Error ? error.message : String(error);
toast.error(`Download failed: ${errorMsg}`);
}
finally {
setDownloadingItem(null);
setTimeout(() => { currentDownloadingItemKeyRef.current = null; }, 1000);
}
}} disabled={downloadingItem !== null}>
await handleDownloadItem(item, itemKey);
}} disabled={anyDownloadActive}>
{isItemDownloading ? (<Spinner />) : isItemSkipped ? (<FileCheck className="h-4 w-4"/>) : isItemDownloaded ? (<CheckCircle className="h-4 w-4"/>) : isItemFailed ? (<XCircle className="h-4 w-4"/>) : (<Download className="h-4 w-4"/>)}
</Button>
</TooltipTrigger>
@@ -1169,56 +1004,10 @@ export function MediaList({ accountInfo, timeline, totalUrls, fetchedMediaType =
{(() => {
const item = filteredTimeline[previewIndex];
const itemKey = getItemKey(item);
const isItemDownloaded = downloadedItems.has(itemKey);
const isItemFailed = failedItems.has(itemKey);
const isItemSkipped = skippedItems.has(itemKey);
const isItemDownloading = downloadingItem === itemKey;
const { isItemDownloaded, isItemFailed, isItemSkipped, isItemDownloading } = getItemStatusFlags(itemKey);
return (<Button variant="default" size="sm" className="h-9" onClick={async () => {
setDownloadingItem(itemKey);
currentDownloadingItemKeyRef.current = itemKey;
try {
const settings = getSettings();
const request = new main.DownloadMediaWithMetadataRequest({
items: [new main.MediaItemRequest({
url: item.url,
date: item.date,
tweet_id: item.tweet_id,
type: item.type,
content: item.content || "",
original_filename: item.original_filename || "",
author_username: item.author_username || "",
})],
output_dir: getOutputDir(),
username: accountInfo.name,
concurrent_downloads: settings.concurrentDownloads || 10,
skip_existing: settings.skipExistingFiles,
delete_incomplete_files: settings.deleteIncompleteFiles,
retry_attempts: settings.retryAttempts,
proxy: settings.proxy || "",
filename_template: settings.filenameTemplate || "",
folder_template: settings.folderTemplate || "",
});
const response = await DownloadMediaWithMetadata(request);
if (response.cancelled) {
toast.info(response.message || "Download stopped");
}
else if (response.success) {
setHasDownloaded(true);
}
else {
setFailedItems((prev) => new Set(prev).add(itemKey));
toast.error("Download failed");
}
}
catch {
setFailedItems((prev) => new Set(prev).add(itemKey));
toast.error("Download failed");
}
finally {
setDownloadingItem(null);
setTimeout(() => { currentDownloadingItemKeyRef.current = null; }, 1000);
}
}} disabled={downloadingItem !== null}>
await handleDownloadItem(item, itemKey);
}} disabled={anyDownloadActive}>
{isItemDownloading ? (<Spinner className="mr-1"/>) : isItemSkipped ? (<FileCheck className="h-4 w-4 mr-1"/>) : isItemDownloaded ? (<CheckCircle className="h-4 w-4 mr-1"/>) : isItemFailed ? (<XCircle className="h-4 w-4 mr-1"/>) : (<Download className="h-4 w-4 mr-1"/>)}
{isItemDownloading ? "Downloading..." : isItemSkipped ? "Already exists" : isItemDownloaded ? "Downloaded" : isItemFailed ? "Failed" : "Download"}
</Button>);
+16 -1
View File
@@ -11,7 +11,7 @@ import { toastWithSound as toast } from "@/lib/toast-with-sound";
import { cn } from "@/lib/utils";
import { getSettings, updateSettings, VIDEO_QUALITIES, IMAGE_SIZES, AVATAR_SIZES, BANNER_SIZES, type VideoQuality, type ImageSize, type AvatarSize, type BannerSize } from "@/lib/settings";
import { GetStoredAuthToken, SetStoredAuthToken } from "../../wailsjs/go/main/App";
import { AlertCircle, Bookmark, CheckCircle, CloudDownload, Clock, Database, Eye, EyeOff, Globe, Heart, Hourglass, Info, Lock, RotateCcw, SlidersHorizontal, StopCircle, Trash2, User, Users, XCircle } from "lucide-react";
import { AlertCircle, Bookmark, CheckCircle, Clipboard, CloudDownload, Clock, Database, Eye, EyeOff, Globe, Heart, Hourglass, Info, Lock, RotateCcw, SlidersHorizontal, StopCircle, Trash2, User, Users, XCircle } from "lucide-react";
import { Spinner } from "@/components/ui/spinner";
function formatNumberWithComma(num: number): string {
return num.toLocaleString();
@@ -207,6 +207,17 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
onFetch(false, undefined, undefined, undefined, retweets, mode, privateType, authToken, false);
});
};
const handleClipboardPaste = async () => {
try {
const clipboardText = (await navigator.clipboard.readText()).trim();
if (clipboardText) {
onUsernameChange(clipboardText);
}
}
catch (error) {
console.error("Failed to read clipboard:", error);
}
};
const handleResume = () => {
if (onResume) {
requireAuthToken((authToken) => {
@@ -371,6 +382,10 @@ export function SearchBar({ username, loading, onUsernameChange, onFetch, onStop
</button>)}
</div>
<Button variant="outline" size="icon" className="shrink-0" aria-label="Paste from clipboard" onClick={() => void handleClipboardPaste()}>
<Clipboard className="h-4 w-4"/>
</Button>
<div className="flex items-center gap-2">
{loading && (<Button variant="destructive" onClick={onStopFetch}>
<StopCircle className="h-4 w-4"/>
+7 -3
View File
@@ -591,14 +591,18 @@ export function SettingsPage({ onUnsavedChangesChange, onResetRequest }: Setting
</Tooltip>
</Label>
<div className="flex items-center justify-between gap-4">
<Label htmlFor="gif-quality" className={!ffmpegInstalled ? "text-muted-foreground" : undefined}>GIF Quality</Label>
<Label htmlFor="auto-convert-gifs" className={!ffmpegInstalled ? "text-muted-foreground" : undefined}>Auto Convert GIFs</Label>
<Switch id="auto-convert-gifs" checked={tempSettings.autoConvertGifs} onCheckedChange={(checked) => setTempSettings((prev) => ({ ...prev, autoConvertGifs: checked }))} disabled={!ffmpegInstalled}/>
</div>
<div className="flex items-center justify-between gap-4">
<Label htmlFor="gif-quality" className={!ffmpegInstalled || !tempSettings.autoConvertGifs ? "text-muted-foreground" : undefined}>GIF Quality</Label>
<div className="flex items-center gap-2">
<Select value={tempSettings.gifQuality} onValueChange={(value: GifQuality) => {
setTempSettings((prev) => ({
...prev,
gifQuality: value,
}));
}} disabled={!ffmpegInstalled}>
}} disabled={!ffmpegInstalled || !tempSettings.autoConvertGifs}>
<SelectTrigger id="gif-quality" className="w-fit">
<SelectValue placeholder="Select quality"/>
</SelectTrigger>
@@ -607,7 +611,7 @@ export function SettingsPage({ onUnsavedChangesChange, onResetRequest }: Setting
<SelectItem value="better">Better</SelectItem>
</SelectContent>
</Select>
<Select value={tempSettings.gifResolution} onValueChange={(value: GifResolution) => setTempSettings((prev) => ({ ...prev, gifResolution: value }))} disabled={!ffmpegInstalled}>
<Select value={tempSettings.gifResolution} onValueChange={(value: GifResolution) => setTempSettings((prev) => ({ ...prev, gifResolution: value }))} disabled={!ffmpegInstalled || !tempSettings.autoConvertGifs}>
<SelectTrigger id="gif-resolution" className="w-fit">
<SelectValue placeholder="Resolution"/>
</SelectTrigger>
+85 -20
View File
@@ -1,16 +1,57 @@
import { useState } from "react";
import { Button } from "@/components/ui/button";
import { Select, SelectContent, SelectItem, SelectTrigger, SelectValue } from "@/components/ui/select";
import { CircleCheck, Copy } from "lucide-react";
import { openExternal } from "@/lib/utils";
import KofiLogo from "@/assets/ko-fi.gif";
import KofiSvg from "@/assets/kofi_symbol.svg";
import UsdtBarcode from "@/assets/usdt.jpg";
const USDT_ADDRESS = "THnzAAwZgp2Sq5CAXLP2njQDhTvgZG9EWs";
import UsdtTronQr from "@/assets/usdt.jpg";
import UsdtEvmQr from "@/assets/usdt_evm.jpg";
import UsdcEvmQr from "@/assets/usdc.jpg";
type CryptoCoin = "usdt" | "usdc";
type CryptoNetwork = "ethereum" | "bsc" | "polygon" | "base" | "tron";
const EVM_ADDRESS = "0xB563a7F39770C151e2FacE26926081a00c5EF349";
const TRON_ADDRESS = "THnzAAwZgp2Sq5CAXLP2njQDhTvgZG9EWs";
const EVM_NETWORKS: Array<{
value: CryptoNetwork;
label: string;
shortLabel: string;
}> = [
{ value: "bsc", label: "BNB Smart Chain (BEP20)", shortLabel: "BEP20" },
{ value: "polygon", label: "Polygon", shortLabel: "Polygon" },
{ value: "ethereum", label: "Ethereum (ERC20)", shortLabel: "ERC20" },
{ value: "base", label: "Base", shortLabel: "Base" },
];
const USDT_NETWORKS: Array<{
value: CryptoNetwork;
label: string;
shortLabel: string;
}> = [
{ value: "ethereum", label: "Ethereum (ERC20)", shortLabel: "ERC20" },
{ value: "bsc", label: "BNB Smart Chain (BEP20)", shortLabel: "BEP20" },
{ value: "tron", label: "Tron (TRC20)", shortLabel: "TRC20" },
{ value: "polygon", label: "Polygon", shortLabel: "Polygon" },
];
export function SupportPage() {
const [copiedUsdt, setCopiedUsdt] = useState(false);
const [selectedCoin, setSelectedCoin] = useState<CryptoCoin>("usdt");
const [selectedNetwork, setSelectedNetwork] = useState<CryptoNetwork>("tron");
const [copiedAddress, setCopiedAddress] = useState(false);
const networkOptions = selectedCoin === "usdt" ? USDT_NETWORKS : EVM_NETWORKS;
const activeNetwork = networkOptions.find((network) => network.value === selectedNetwork) || EVM_NETWORKS[0];
const isTron = selectedNetwork === "tron";
const cryptoAddress = isTron ? TRON_ADDRESS : EVM_ADDRESS;
const cryptoQr = isTron ? UsdtTronQr : selectedCoin === "usdt" ? UsdtEvmQr : UsdcEvmQr;
const handleCoinChange = (coin: CryptoCoin) => {
setSelectedCoin(coin);
setCopiedAddress(false);
const nextNetworks = coin === "usdt" ? USDT_NETWORKS : EVM_NETWORKS;
if (!nextNetworks.some((network) => network.value === selectedNetwork)) {
setSelectedNetwork("ethereum");
}
};
return (<div className="flex min-h-[70vh] items-center justify-center p-4">
<div className="flex w-full max-w-3xl flex-col items-stretch rounded-xl border bg-card shadow-sm md:flex-row">
<div className="flex flex-1 flex-col items-center justify-between space-y-6 border-b p-6 md:border-r md:border-b-0">
<div className="flex min-w-0 flex-1 basis-0 flex-col items-center justify-between space-y-6 border-b p-6 md:border-r md:border-b-0">
<div className="flex flex-col items-center space-y-4">
<div className="relative flex h-32 w-full items-center justify-center">
<img src={KofiLogo} className="pointer-events-none absolute w-72" alt="Ko-fi"/>
@@ -20,35 +61,59 @@ export function SupportPage() {
Enjoying the project? You can support ongoing development by buying me a coffee.
</p>
</div>
<Button className="h-10 w-full gap-2 bg-[#72a4f2] text-sm font-semibold text-white hover:bg-[#5f8cd6]" onClick={() => openExternal("https://ko-fi.com/afkarxyz")}>
<img src={KofiSvg} className="h-5 w-5 shrink-0" alt="" aria-hidden="true"/>
<Button className="h-9 w-4/5 gap-2 bg-[#72a4f2] text-sm font-semibold text-white hover:bg-[#5f8cd6]" onClick={() => openExternal("https://ko-fi.com/afkarxyz")}>
<img src={KofiSvg} className="h-6 w-6 shrink-0" alt="" aria-hidden="true"/>
Support me on Ko-fi
</Button>
</div>
<div className="flex flex-1 flex-col items-center justify-between space-y-6 p-6">
<div className="flex w-full flex-col items-center space-y-4">
<div className="flex min-w-0 flex-1 basis-0 flex-col items-center justify-between space-y-4 p-6">
<div className="flex w-full flex-col items-center space-y-3">
<div className="flex h-32 items-center justify-center">
<div className="rounded-xl border bg-white p-2 shadow-sm">
<img src={UsdtBarcode} className="h-24 w-24 object-contain" alt="USDT Barcode"/>
<img src={cryptoQr} className="h-24 w-24 object-contain" alt={`${selectedCoin.toUpperCase()} ${activeNetwork.label} QR code`}/>
</div>
</div>
<h4 className="font-semibold text-foreground">USDT (TRC20)</h4>
<h4 className="font-semibold text-foreground">Support via Crypto</h4>
<p className="px-4 text-center text-sm text-muted-foreground">
Crypto donations are also accepted. Scan the QR code or copy the address.
</p>
</div>
<div className="flex h-10 w-full items-center justify-between gap-2 rounded-lg border bg-muted/50 py-1.5 pr-1.5 pl-3">
<code className="truncate text-xs font-mono text-muted-foreground" title={USDT_ADDRESS}>
{USDT_ADDRESS}
</code>
<Button variant="ghost" size="icon" className="h-7 w-7 shrink-0 hover:bg-background" onClick={() => {
navigator.clipboard.writeText(USDT_ADDRESS);
setCopiedUsdt(true);
setTimeout(() => setCopiedUsdt(false), 500);
<div className="w-full space-y-2">
<div className="grid grid-cols-2 gap-2">
<Select value={selectedCoin} onValueChange={(value: CryptoCoin) => handleCoinChange(value)}>
<SelectTrigger size="sm" className="w-full" aria-label="Coin">
<SelectValue />
</SelectTrigger>
<SelectContent>
<SelectItem value="usdt">USDT</SelectItem>
<SelectItem value="usdc">USDC</SelectItem>
</SelectContent>
</Select>
<Select value={selectedNetwork} onValueChange={(value: CryptoNetwork) => {
setSelectedNetwork(value);
setCopiedAddress(false);
}}>
{copiedUsdt ? <CircleCheck className="h-3.5 w-3.5 text-green-500"/> : <Copy className="h-3.5 w-3.5"/>}
</Button>
<SelectTrigger size="sm" className="w-full" aria-label="Network">
<SelectValue>{activeNetwork.shortLabel}</SelectValue>
</SelectTrigger>
<SelectContent>
{networkOptions.map((network) => (<SelectItem key={network.value} value={network.value}>{network.label}</SelectItem>))}
</SelectContent>
</Select>
</div>
<div className="flex h-10 w-full items-center justify-between gap-2 rounded-lg border bg-muted/50 py-1.5 pr-1.5 pl-3">
<code className="min-w-0 flex-1 truncate text-xs font-mono text-muted-foreground" title={cryptoAddress}>
{cryptoAddress}
</code>
<Button variant="ghost" size="icon" className="h-7 w-7 shrink-0 hover:bg-background" aria-label="Copy wallet address" onClick={() => {
navigator.clipboard.writeText(cryptoAddress);
setCopiedAddress(true);
setTimeout(() => setCopiedAddress(false), 500);
}}>
{copiedAddress ? <CircleCheck className="h-3.5 w-3.5 text-green-500"/> : <Copy className="h-3.5 w-3.5"/>}
</Button>
</div>
</div>
</div>
</div>
+1 -1
View File
@@ -5,7 +5,7 @@ import { openExternal } from "@/lib/utils";
const INFO_LINKS = [
{ label: "Chrome Extension", icon: Puzzle, url: "https://chromewebstore.google.com/detail/cboceolmgkoobpfjiojkigmihijfgmdo" },
{ label: "Userscript", icon: FileCode2, url: "https://greasyfork.org/en/scripts/523157" },
{ label: "Website", icon: Globe, url: "https://mediabatchdl.com" },
{ label: "Website", icon: Globe, url: "https://twitterdl.app" },
];
export function TitleBar() {
const handleMinimize = () => {
+112
View File
@@ -0,0 +1,112 @@
import { useSyncExternalStore } from "react";
import { EventsOn } from "../../wailsjs/runtime/runtime";
export interface DownloadProgress {
current: number;
total: number;
percent: number;
}
export interface DownloadItemStatus {
tweet_id: number;
index: number;
status: "success" | "failed" | "skipped" | "cancelled";
}
export type DownloadScope = "media" | "database" | "database-bulk";
export type DownloadItemResult = "success" | "failed" | "skipped";
export interface DownloadState {
active: boolean;
scope: DownloadScope | null;
accountId: number | null;
progress: DownloadProgress | null;
currentItemKey: string | null;
itemKeyByIndex: Record<number, string>;
itemStatusByKey: Record<string, DownloadItemResult>;
}
const listeners = new Set<() => void>();
let state: DownloadState = {
active: false,
scope: null,
accountId: null,
progress: null,
currentItemKey: null,
itemKeyByIndex: {},
itemStatusByKey: {},
};
let unsubscribeEvents: (() => void) | null = null;
function emit() {
for (const listener of listeners) {
listener();
}
}
function setState(next: Partial<DownloadState>) {
state = { ...state, ...next };
emit();
}
export function initDownloadProgressEvents() {
if (unsubscribeEvents) {
return unsubscribeEvents;
}
const unsubscribeProgress = EventsOn("download-progress", (progress: DownloadProgress) => {
if (!state.scope) {
return;
}
setState({ progress });
});
const unsubscribeItemStatus = EventsOn("download-item-status", (status: DownloadItemStatus) => {
if (status.status === "cancelled") {
return;
}
const itemKey = state.currentItemKey || state.itemKeyByIndex[status.index] || `${String(status.tweet_id)}-${status.index}`;
setState({
itemStatusByKey: {
...state.itemStatusByKey,
[itemKey]: status.status,
},
});
});
unsubscribeEvents = () => {
unsubscribeProgress();
unsubscribeItemStatus();
unsubscribeEvents = null;
};
return unsubscribeEvents;
}
export function beginDownload(progress: DownloadProgress, meta: Pick<DownloadState, "scope"> & Partial<Pick<DownloadState, "accountId" | "currentItemKey" | "itemKeyByIndex">>) {
setState({
active: true,
scope: meta.scope,
accountId: meta.accountId ?? null,
progress,
currentItemKey: meta.currentItemKey ?? null,
itemKeyByIndex: meta.itemKeyByIndex ?? {},
});
}
export function finishDownload() {
setState({
active: false,
scope: null,
accountId: null,
progress: null,
currentItemKey: null,
itemKeyByIndex: {},
});
}
export function setDownloadItemStatus(itemKey: string, status: DownloadItemResult) {
setState({
itemStatusByKey: {
...state.itemStatusByKey,
[itemKey]: status,
},
});
}
export function subscribeDownloadState(listener: () => void) {
listeners.add(listener);
return () => {
listeners.delete(listener);
};
}
export function getDownloadState() {
return state;
}
export function useDownloadState() {
return useSyncExternalStore(subscribeDownloadState, getDownloadState, getDownloadState);
}
+58 -19
View File
@@ -58,67 +58,86 @@ export const BANNER_SIZES: {
{ value: "600x200", label: "600×200" },
{ value: "300x100", label: "300×100" },
];
export const DEFAULT_FILENAME_TEMPLATE = "{username}_{date}_{tweet_id}_{index}";
export const DEFAULT_FILENAME_TEMPLATE = "{handle}_{date}_{tweet_id}";
export interface TemplateToken {
key: string;
description: string;
example: string;
}
export const FILENAME_TEMPLATE_VARIABLES: TemplateToken[] = [
{ key: "{username}", description: "Author handle", example: "NASA" },
{ key: "{handle}", description: "Author handle", example: "elonmusk" },
{ key: "{name}", description: "Author display name", example: "Elon Musk" },
{ key: "{date}", description: "Tweet date & time", example: "20250620_104556" },
{ key: "{tweet_id}", description: "Tweet ID", example: "1989033613824815258" },
{ key: "{index}", description: "Media position in tweet", example: "01" },
{ key: "{media_id}", description: "Unique media ID (prevents overwrites)", example: "Gx1aB2cXkAA7Yz9" },
{ key: "{type}", description: "Media type", example: "photo" },
];
export interface FilenameTemplateData {
username?: string;
accountName?: string;
date?: string;
tweetId?: string;
index?: number;
mediaID?: string;
type?: string;
}
export const SAMPLE_FILENAME_DATA: FilenameTemplateData = {
username: "NASA",
username: "elonmusk",
accountName: "Elon Musk",
date: "20250620_104556",
tweetId: "1989033613824815258",
index: 1,
mediaID: "Gx1aB2cXkAA7Yz9",
type: "photo",
};
function sanitizeTemplatePart(input: string): string {
const cleaned = input
.replace(/[\u0000-\u001f\\/:*?"<>|]/g, "")
.trim()
.replace(/[. ]+$/g, "");
return /^(con|prn|aux|nul|com[1-9]|lpt[1-9])(?:\..*)?$/i.test(cleaned) ? `${cleaned}_` : cleaned;
}
export function renderFilenameTemplate(template: string, data: FilenameTemplateData): string {
if (!template)
return "";
const safe = (s: string) => s.replace(/[\\/:*?"<>|]/g, "").trim();
return template
.replace(/\{username\}/g, safe(data.username ?? ""))
.replace(/\{date\}/g, safe(data.date ?? ""))
.replace(/\{tweet_id\}/g, safe(data.tweetId ?? ""))
return sanitizeTemplatePart(template
.replace(/\{handle\}/g, sanitizeTemplatePart(data.username ?? ""))
.replace(/\{name\}/g, sanitizeTemplatePart(data.accountName ?? ""))
.replace(/\{username\}/g, sanitizeTemplatePart(data.username ?? ""))
.replace(/\{account_name\}/g, sanitizeTemplatePart(data.accountName ?? ""))
.replace(/\{date\}/g, sanitizeTemplatePart(data.date ?? ""))
.replace(/\{tweet_id\}/g, sanitizeTemplatePart(data.tweetId ?? ""))
.replace(/\{index\}/g, String(data.index ?? 1).padStart(2, "0"))
.replace(/\{type\}/g, safe(data.type ?? ""))
.trim();
.replace(/\{media_id\}/g, sanitizeTemplatePart(data.mediaID ?? ""))
.replace(/\{type\}/g, sanitizeTemplatePart(data.type ?? ""))
.trim());
}
export const DEFAULT_FOLDER_TEMPLATE = "{username}";
export const DEFAULT_FOLDER_TEMPLATE = "{handle}";
export const FOLDER_TEMPLATE_VARIABLES: TemplateToken[] = [
{ key: "{username}", description: "Author handle", example: "NASA" },
{ key: "{handle}", description: "Author handle", example: "elonmusk" },
{ key: "{name}", description: "Author display name", example: "Elon Musk" },
{ key: "{date}", description: "Download date", example: "20250620" },
];
export interface FolderTemplateData {
username?: string;
accountName?: string;
date?: string;
}
export const SAMPLE_FOLDER_DATA: FolderTemplateData = {
username: "NASA",
username: "elonmusk",
accountName: "Elon Musk",
date: "20250620",
};
export function renderFolderTemplate(template: string, data: FolderTemplateData): string {
if (!template)
return "";
const safe = (s: string) => s.replace(/[\\/:*?"<>|]/g, "").trim();
return template
.replace(/\{username\}/g, safe(data.username ?? ""))
.replace(/\{date\}/g, safe(data.date ?? ""))
.trim();
return sanitizeTemplatePart(template
.replace(/\{handle\}/g, sanitizeTemplatePart(data.username ?? ""))
.replace(/\{name\}/g, sanitizeTemplatePart(data.accountName ?? ""))
.replace(/\{username\}/g, sanitizeTemplatePart(data.username ?? ""))
.replace(/\{account_name\}/g, sanitizeTemplatePart(data.accountName ?? ""))
.replace(/\{date\}/g, sanitizeTemplatePart(data.date ?? ""))
.trim());
}
const DEFAULT_CONCURRENT_DOWNLOADS = 10;
const MIN_CONCURRENT_DOWNLOADS = 1;
@@ -137,6 +156,7 @@ export interface Settings {
fontFamily: FontFamily;
customFonts: CustomFontOption[];
sfxEnabled: boolean;
autoConvertGifs: boolean;
gifQuality: GifQuality;
gifResolution: GifResolution;
proxy: string;
@@ -164,6 +184,7 @@ export const DEFAULT_SETTINGS: Settings = {
fontFamily: "google-sans",
customFonts: [],
sfxEnabled: true,
autoConvertGifs: false,
gifQuality: "fast",
gifResolution: "original",
proxy: "",
@@ -428,6 +449,21 @@ function normalizeRetryAttempts(value: unknown): number {
}
return rounded;
}
function normalizeTemplateTokens(value: unknown, fallback: string): string {
if (typeof value !== "string") {
return fallback;
}
return value
.replace(/\{username\}/g, "{handle}")
.replace(/\{account_name\}/g, "{name}");
}
function normalizeFilenameTemplate(value: unknown): string {
const template = normalizeTemplateTokens(value, DEFAULT_FILENAME_TEMPLATE);
return template === "{handle}_{date}_{tweet_id}_{index}" ? DEFAULT_FILENAME_TEMPLATE : template;
}
function normalizeFolderTemplate(value: unknown): string {
return normalizeTemplateTokens(value, DEFAULT_FOLDER_TEMPLATE);
}
export function getFontOptions(customFonts: CustomFontOption[] = []): FontOption[] {
return [...FONT_OPTIONS, ...normalizeCustomFonts(customFonts)];
}
@@ -480,6 +516,9 @@ function toNormalizedSettings(settings: Partial<Settings>): Settings {
skipExistingFiles: normalizeBoolean(settings.skipExistingFiles, DEFAULT_SETTINGS.skipExistingFiles),
deleteIncompleteFiles: normalizeBoolean(settings.deleteIncompleteFiles, DEFAULT_SETTINGS.deleteIncompleteFiles),
retryAttempts: normalizeRetryAttempts(settings.retryAttempts),
autoConvertGifs: normalizeBoolean(settings.autoConvertGifs, DEFAULT_SETTINGS.autoConvertGifs),
filenameTemplate: normalizeFilenameTemplate(settings.filenameTemplate),
folderTemplate: normalizeFolderTemplate(settings.folderTemplate),
customFonts,
fontFamily: normalizeFontFamily(settings.fontFamily, customFonts),
};
+1
View File
@@ -44,6 +44,7 @@ export interface TimelineEntry {
verified?: boolean;
original_filename?: string;
author_username?: string;
author_name?: string;
}
export interface ExtractMetadata {
new_entries: number;
+8
View File
@@ -187,6 +187,7 @@ export namespace main {
content?: string;
original_filename?: string;
author_username?: string;
account_name?: string;
static createFrom(source: any = {}) {
return new MediaItemRequest(source);
@@ -201,6 +202,7 @@ export namespace main {
this.content = source["content"];
this.original_filename = source["original_filename"];
this.author_username = source["author_username"];
this.account_name = source["account_name"];
}
}
export class DownloadMediaWithMetadataRequest {
@@ -214,6 +216,9 @@ export namespace main {
proxy?: string;
filename_template?: string;
folder_template?: string;
auto_convert_gifs?: boolean;
gif_quality?: string;
gif_resolution?: string;
static createFrom(source: any = {}) {
return new DownloadMediaWithMetadataRequest(source);
@@ -231,6 +236,9 @@ export namespace main {
this.proxy = source["proxy"];
this.filename_template = source["filename_template"];
this.folder_template = source["folder_template"];
this.auto_convert_gifs = source["auto_convert_gifs"];
this.gif_quality = source["gif_quality"];
this.gif_resolution = source["gif_resolution"];
}
convertValues(a: any, classs: any, asMap: boolean = false): any {
+1 -1
View File
@@ -11,7 +11,7 @@
},
"info": {
"productName": "Twitter/X Media Batch Downloader",
"productVersion": "4.7"
"productVersion": "5.0.0"
},
"wailsjsdir": "./frontend",
"assetdir": "./frontend/dist",