refactor: remove container selection, extract helpers, add logging and tests
All checks were successful
CI / build (push) Successful in 51s
All checks were successful
CI / build (push) Successful in 51s
- Remove container picker UI, keyboard, settings, and ContainerOptions entirely — yt-dlp handles container format automatically - Remove Container field from DownloadJob struct and related references - Extract buildFormatList helper to deduplicate format list building between handleURLInput and handleBackStep - Break runDownload into trackDownloadProgress + handleDownloadCompletion - Add HTTP timeout (30s) to downloadFile helper - Log applyQuota and AddHistory errors instead of discarding - Log nil stepState warnings in all handler entry points - Include job.StderrLog in download failure messages - Add tests for buildFormatList, findFormatByID, determineMediaType, and buildFormatString - Update README with search, DRM fallback, and quota feature docs - Remove unused strings import from keyboard.go
This commit is contained in:
@@ -20,14 +20,6 @@ func (h *Handler) buildSettingsKeyboard(userID int64, prefs *domain.UserPreferen
|
||||
if videoFmt == "" {
|
||||
videoFmt = "best"
|
||||
}
|
||||
audioCont := prefs.DefaultAudioContainer
|
||||
if audioCont == "" {
|
||||
audioCont = "mp3"
|
||||
}
|
||||
videoCont := prefs.DefaultVideoContainer
|
||||
if videoCont == "" {
|
||||
videoCont = "mp4"
|
||||
}
|
||||
langLabel := prefs.DefaultLanguage
|
||||
if langLabel == "" {
|
||||
langLabel = "Default"
|
||||
@@ -36,9 +28,6 @@ func (h *Handler) buildSettingsKeyboard(userID int64, prefs *domain.UserPreferen
|
||||
rows := [][]models.InlineKeyboardButton{
|
||||
{
|
||||
{Text: fmt.Sprintf("Quality: %s/%s", audioFmt, videoFmt), CallbackData: "settings_quality"},
|
||||
},
|
||||
{
|
||||
{Text: fmt.Sprintf("Container: %s/%s", audioCont, videoCont), CallbackData: "settings_container"},
|
||||
{Text: fmt.Sprintf("Language: %s", langLabel), CallbackData: "settings_language"},
|
||||
},
|
||||
{{Text: "Delete all data", CallbackData: "deleteaccount", Style: "danger"}},
|
||||
@@ -82,15 +71,6 @@ func (h *Handler) handleSettingsSelection(ctx context.Context, chatID int64, msg
|
||||
case "quality_video":
|
||||
text, kb := h.buildVideoQualityPicker(prefs)
|
||||
h.editText(ctx, chatID, msgID, text, &kb)
|
||||
case "container":
|
||||
text, kb := h.buildContainerAudioVideoPicker(prefs)
|
||||
h.editText(ctx, chatID, msgID, text, &kb)
|
||||
case "container_audio":
|
||||
text, kb := h.buildAudioContainerPicker(prefs)
|
||||
h.editText(ctx, chatID, msgID, text, &kb)
|
||||
case "container_video":
|
||||
text, kb := h.buildVideoContainerPicker(prefs)
|
||||
h.editText(ctx, chatID, msgID, text, &kb)
|
||||
case "language":
|
||||
text, kb := h.buildLanguagePicker(prefs)
|
||||
h.editText(ctx, chatID, msgID, text, &kb)
|
||||
@@ -147,56 +127,6 @@ func (h *Handler) buildVideoQualityPicker(prefs *domain.UserPreferences) (string
|
||||
return "Select default video quality:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
}
|
||||
|
||||
func (h *Handler) buildContainerAudioVideoPicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
rows := [][]models.InlineKeyboardButton{
|
||||
{{Text: "Audio", CallbackData: "settings_container_audio"}},
|
||||
{{Text: "Video", CallbackData: "settings_container_video"}},
|
||||
{{Text: "Back to Settings", CallbackData: "back_settings"}},
|
||||
}
|
||||
return "Choose container type to set default:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
}
|
||||
|
||||
func (h *Handler) buildAudioContainerPicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
containers := []string{"mp3", "m4a", "opus"}
|
||||
rows := [][]models.InlineKeyboardButton{}
|
||||
for _, c := range containers {
|
||||
label := c
|
||||
if c == prefs.DefaultAudioContainer {
|
||||
label = "> " + label
|
||||
}
|
||||
rows = append(rows, []models.InlineKeyboardButton{
|
||||
{Text: label, CallbackData: "settings_set_audiocontainer_" + c},
|
||||
})
|
||||
}
|
||||
rows = append(rows, []models.InlineKeyboardButton{
|
||||
{Text: "Back", CallbackData: "back_container"},
|
||||
})
|
||||
return "Select default audio container:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
}
|
||||
|
||||
func (h *Handler) buildVideoContainerPicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
containers := []string{"mp4", "mkv", "webm"}
|
||||
rows := [][]models.InlineKeyboardButton{}
|
||||
row := []models.InlineKeyboardButton{}
|
||||
for i, c := range containers {
|
||||
label := c
|
||||
if c == prefs.DefaultVideoContainer {
|
||||
label = "> " + label
|
||||
}
|
||||
row = append(row, models.InlineKeyboardButton{
|
||||
Text: label, CallbackData: "settings_set_videocontainer_" + c,
|
||||
})
|
||||
if len(row) == 3 || i == len(containers)-1 {
|
||||
rows = append(rows, row)
|
||||
row = nil
|
||||
}
|
||||
}
|
||||
rows = append(rows, []models.InlineKeyboardButton{
|
||||
{Text: "Back", CallbackData: "back_container"},
|
||||
})
|
||||
return "Select default video container:", models.InlineKeyboardMarkup{InlineKeyboard: rows}
|
||||
}
|
||||
|
||||
func (h *Handler) buildLanguagePicker(prefs *domain.UserPreferences) (string, models.InlineKeyboardMarkup) {
|
||||
languages := []string{"", "en", "es", "ja", "ko", "fr", "de", "zh", "ar", "pt", "ru"}
|
||||
langLabels := map[string]string{
|
||||
@@ -246,12 +176,6 @@ func (h *Handler) handleSettingsSet(ctx context.Context, chatID int64, msgID int
|
||||
case "videoquality":
|
||||
prefs.DefaultVideoFormat = value
|
||||
changed = true
|
||||
case "audiocontainer":
|
||||
prefs.DefaultAudioContainer = value
|
||||
changed = true
|
||||
case "videocontainer":
|
||||
prefs.DefaultVideoContainer = value
|
||||
changed = true
|
||||
case "language":
|
||||
prefs.DefaultLanguage = value
|
||||
changed = true
|
||||
|
||||
Reference in New Issue
Block a user