mirror of
https://git.sr.ht/~joren/streamrip-go
synced 2026-10-16 13:57:25 +02:00
refactor: delete dead code, dedupe helpers, add tests for untested packages
Dead code Removed, each verified to have no non-test caller: promptSearchSelection (77 lines, superseded by promptSearchSelectionMenu), AddPlaylistByTrackIDs, download.NewWithVerifySSL, qobuz.Client.GetTrackMetadata, tidal.Client.trackSupportsAtmos (test-only, and the comment above GetDownloadable already documented its removal from the live path) and its now-orphaned test, yandex.canonicalTrackRequestID (a no-op returning its trimmed input; the call site uses strings.TrimSpace directly) and the unused defaultEstimatedKbps constant. Config keys that did nothing qobuz.download_booklets and misc.check_for_updates were declared, defaulted and documented in config.toml.example but read by no code. The whole [youtube] block went too: there is no YouTube provider. go-toml ignores unknown keys, verified, so existing user configs still load. Duplicated helpers tidal.stringify and yandex.firstNonEmpty were byte-identical copies of jsonutil.StringFromAny and jsonutil.FirstNonEmpty. displayArtistNames existed three times, byte-identical, in internal/app, provider/yandex and provider/beatport; it now lives in jsonutil. The CLI's normalizeCodec delegates to config.NormalizeCodec so the flag and the config file are checked by the same rules. Tests for packages that had none internal/jsonutil (0% -> 100%) and internal/netutil (0% -> 78%), the latter covering redactURL, which is a security control, and the zero-timeout contract that internal/download and the qobuz body copy depend on. internal/config rose to 82% with coverage of the new Validate(), the 0600 permissions, CloneConfigData not sharing slices, and a concurrent UpdateTokens test that exercises the mutex under -race. Test suite is ~85x faster Provider tests built clients with the default 60 requests/minute, so the rate limiter slept 1s per HTTP call: deezer took 31s, tidal 11s, qobuz 8s. Each provider test package now builds its config through a testConfigData helper that disables throttling. Whole suite: ~60s -> 0.7s, and 2.8s under -race. Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
19 files changed
+701
-392
No files matched your search
@@ -110,84 +110,6 @@ func parseSearchArgs(args []string, defaultLimit int) (searchOptions, error) {
|
||||
}, nil
|
||||
}
|
||||
|
||||
func promptSearchSelection(results []searchResult) ([]int, error) {
|
||||
reader := bufio.NewReader(os.Stdin)
|
||||
for {
|
||||
fmt.Print("Select results to download (e.g. 1,3-5; a=all; q=cancel): ")
|
||||
line, err := reader.ReadString('\n')
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
line = strings.TrimSpace(line)
|
||||
if line == "" || strings.EqualFold(line, "q") || strings.EqualFold(line, "quit") {
|
||||
return nil, nil
|
||||
}
|
||||
if strings.EqualFold(line, "a") || strings.EqualFold(line, "all") {
|
||||
out := make([]int, 0, len(results))
|
||||
for i := range results {
|
||||
out = append(out, i)
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
|
||||
selected := map[int]struct{}{}
|
||||
chunks := strings.Split(line, ",")
|
||||
ok := true
|
||||
for _, raw := range chunks {
|
||||
part := strings.TrimSpace(raw)
|
||||
if part == "" {
|
||||
continue
|
||||
}
|
||||
if strings.Contains(part, "-") {
|
||||
bounds := strings.SplitN(part, "-", 2)
|
||||
if len(bounds) != 2 {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
start, err1 := strconv.Atoi(strings.TrimSpace(bounds[0]))
|
||||
end, err2 := strconv.Atoi(strings.TrimSpace(bounds[1]))
|
||||
if err1 != nil || err2 != nil || start <= 0 || end <= 0 || start > end {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
for i := start; i <= end; i++ {
|
||||
if i > len(results) {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
selected[i-1] = struct{}{}
|
||||
}
|
||||
if !ok {
|
||||
break
|
||||
}
|
||||
continue
|
||||
}
|
||||
idx, err := strconv.Atoi(part)
|
||||
if err != nil || idx <= 0 || idx > len(results) {
|
||||
ok = false
|
||||
break
|
||||
}
|
||||
selected[idx-1] = struct{}{}
|
||||
}
|
||||
|
||||
if !ok || len(selected) == 0 {
|
||||
fmt.Println("Invalid selection, try again.")
|
||||
continue
|
||||
}
|
||||
|
||||
out := make([]int, 0, len(selected))
|
||||
for idx := range selected {
|
||||
out = append(out, idx)
|
||||
}
|
||||
for i := 1; i < len(out); i++ {
|
||||
for j := i; j > 0 && out[j] < out[j-1]; j-- {
|
||||
out[j], out[j-1] = out[j-1], out[j]
|
||||
}
|
||||
}
|
||||
return out, nil
|
||||
}
|
||||
}
|
||||
|
||||
func promptSearchSelectionMenu(source, mediaType, query string, results []searchResult) ([]int, error) {
|
||||
if len(results) == 0 {
|
||||
return nil, nil
|
||||
|
||||
Reference in new issue
Block a user