From: Sergey Matveev Date: Fri, 6 Mar 2026 13:17:17 +0000 (+0300) Subject: Remove -sort X-Git-Tag: v1.6.0^0 X-Git-Url: http://www.git.stargrave.org/?a=commitdiff_plain;h=e5d082df487369366816905d81a8da7a86e8df0f;p=meta4ra.git Remove -sort BASS project contains similar one written on Perl. --- diff --git a/README b/README index 1985451..43b8645 100644 --- a/README +++ b/README @@ -9,9 +9,6 @@ list its URLs in "pri|cc|URL" format, extract signatures. meta4ra-check utility is used verify corresponding files integrity. -meta4ra-url-sort utility is used to sort "pri|cc|URL" lines by specified -country codes, continents, priority. - meta4ra-dl utility can be used to download specified URL. meta4ra-hash utility can be used to hash the data with a single hash @@ -25,7 +22,7 @@ next, randomising remaining: fn=$(meta4ra-list .meta4 | head -1) size=$(meta4ra-list -size .meta4 $fn) meta4ra-list .meta4 $fn | - meta4ra-url-sort ru c:eu "" rand | + urls-sort ru c:eu "" rand | while read url ; do meta4ra-dl -size $size -progress "$url" | meta4ra-check -pipe .meta4 $fn >$fn || { @@ -36,6 +33,8 @@ next, randomising remaining: done [ -s $fn ] +urls-sort is taken from BASS project (http://www.bass.cypherpunks.su/). + meta4ra is copylefted free software: see the file COPYING for copying conditions. It should work on all POSIX-compatible systems. diff --git a/bin/meta4ra-url-sort b/bin/meta4ra-url-sort deleted file mode 120000 index ebcf0ba..0000000 --- a/bin/meta4ra-url-sort +++ /dev/null @@ -1 +0,0 @@ -meta4ra \ No newline at end of file diff --git a/cmd/main.go b/cmd/main.go index 9224025..39a4c98 100644 --- a/cmd/main.go +++ b/cmd/main.go @@ -25,8 +25,6 @@ func main() { runHash() case "meta4ra-list": runList() - case "meta4ra-url-sort": - runURLSort() default: log.Fatal("unknown command linked") } diff --git a/cmd/sort.go b/cmd/sort.go deleted file mode 100644 index a98287c..0000000 --- a/cmd/sort.go +++ /dev/null @@ -1,169 +0,0 @@ -// meta4ra -- Metalink 4.0 utilities -// Copyright (C) 2021-2026 Sergey Matveev -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 3 of the License. -// -// This program is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -// GNU General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see . - -package main - -import ( - "bufio" - "flag" - "fmt" - "log" - "math/rand/v2" - "net" - "net/url" - "os" - "slices" - "sort" - "strings" - - meta4ra "go.stargrave.org/meta4ra/internal" -) - -type ByPriority []*meta4ra.URL - -func (urls ByPriority) Len() int { - return len(urls) -} - -func (urls ByPriority) Less(i, j int) bool { - return urls[i].Priority < urls[j].Priority -} - -func (urls ByPriority) Swap(i, j int) { - urls[i], urls[j] = urls[j], urls[i] -} - -// https://datahub.io/core/continent-codes/_r/-/data/continent-codes.csv -// https://datahub.io/core/country-codes/_r/-/data/country-codes.csv - -var Continents = map[string]string{ - "af": "ao bf bi bj bw cd cf cg ci cm cv dj dz eg eh er et ga gh gm gn gq gw ke km lr ls ly ma mg ml mr mu mw mz na ne ng re rw sc sd sh sl sn so ss st sz td tg tn tz ug yt za zm zw", - "an": "aq bv gs hm tf", - "as": "ae af am az bd bh bn bt cc cn ge hk id il in io iq ir jo jp kg kh kp kr kw kz la lb lk mm mn mo mv my np om ph pk ps qa sa sg sy th tj tm tr tw uz vn ye", - "eu": "ad al at ax ba be bg by ch cy cz de dk ee es eu fi fo fr gb gg gi gr hr hu ie im is it je li lt lu lv mc md me mk mt nl no pl pt ro rs ru se si sj sk sm ua va", - "na": "ag ai aw bb bl bm bq bs bz ca cr cu cw dm do gd gl gp gt hn ht jm kn ky lc mf mq ms mx ni pa pm pr sv sx tc tt us vc vg vi", - "oc": "as au ck cx fj fm gu ki mh mp nc nf nr nu nz pf pg pn pw sb tk tl to tv um vu wf ws", - "sa": "ar bo br cl co ec fk gf gy pe py sr uy ve", -} - -type ByCC struct { - cc string - urls []*meta4ra.URL -} - -func (by ByCC) Len() int { - return len(by.urls) -} - -func (by ByCC) Less(i, j int) bool { - return strings.Contains(by.cc, by.urls[i].Location) -} - -func (by ByCC) Swap(i, j int) { - by.urls[i], by.urls[j] = by.urls[j], by.urls[i] -} - -func runURLSort() { - ipv6 := flag.Bool("6", false, "Only IPv6-capable hostnames") - flag.Usage = func() { - fmt.Fprintf(flag.CommandLine.Output(), - "Usage: %s [options] [cc ...] = 0; i-- { - cc := flag.Args()[i] - if cc == "rand" { - rand.Shuffle(len(urls), func(i, j int) { - urls[i], urls[j] = urls[j], urls[i] - }) - continue - } - reverse := false - if len(cc) > 0 && cc[0] == '!' { - reverse = true - cc = cc[1:] - slices.Reverse(urls) - } - if strings.HasPrefix(cc, "c:") { - cc = Continents[cc[2:]] - } - sort.Stable(ByCC{cc: cc, urls: urls}) - if reverse { - slices.Reverse(urls) - } - } - sort.Stable(ByPriority(urls)) - for _, u := range urls { - if u.Priority == 999999 { - u.Priority = 0 - } - if *ipv6 { - parsed, err := url.Parse(u.URL) - if err != nil { - continue - } - _, err = net.ResolveIPAddr("ip6", parsed.Hostname()) - if err != nil { - continue - } - } - fmt.Println(u) - } -}