"net"
"net/url"
"os"
+ "slices"
"sort"
"strings"
flag.PrintDefaults()
fmt.Fprint(flag.CommandLine.Output(), `
By default all URLs are sorted by priority. If "cc"s are specified, then
-sort by them with descending order. If "cc" is "rand", then shuffle URLs.
+sort by them with descending order. By specifying "!" before "cc", you
+inverse the order. If "cc" is "rand", then shuffle URLs.
For specifying the region/continent use:
c:af -- Africa
c:an -- Antarctica
c:oc -- Oceania
c:sa -- South America
For example to set Russia first, then Germany and France of same order,
-then Europe, then North America, then location-less, randomise remaining:
- ru "de fr" c:eu c:na "" rand
+then Europe, then North America, least priority Ukraine, then location-less,
+randomise remaining:
+ ru "de fr" "!ua" c:eu c:na "" rand
`)
}
flag.Parse()
rand.Shuffle(len(urls), func(i, j int) {
urls[i], urls[j] = urls[j], urls[i]
})
+ continue
+ }
+ invert := false
+ if len(cc) > 0 && cc[0] == '!' {
+ invert = true
+ cc = cc[1:]
+ slices.Reverse(urls)
}
if strings.HasPrefix(cc, "c:") {
cc = Continents[cc[2:]]
}
- sort.Stable(ByCC{
- cc: cc,
- urls: urls,
- })
+ sort.Stable(ByCC{cc: cc, urls: urls})
+ if invert {
+ slices.Reverse(urls)
+ }
}
sort.Stable(ByPriority(urls))
for _, u := range urls {