1 // meta4ra -- Metalink 4.0 utilities
2 // Copyright (C) 2021-2024 Sergey Matveev <stargrave@stargrave.org>
4 // This program is free software: you can redistribute it and/or modify
5 // it under the terms of the GNU General Public License as published by
6 // the Free Software Foundation, version 3 of the License.
8 // This program is distributed in the hope that it will be useful,
9 // but WITHOUT ANY WARRANTY; without even the implied warranty of
10 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 // GNU General Public License for more details.
13 // You should have received a copy of the GNU General Public License
14 // along with this program. If not, see <http://www.gnu.org/licenses/>.
16 // Metalink 4.0 creator
30 "go.stargrave.org/meta4ra"
34 fn := flag.String("fn", "", "Filename")
35 mtime := flag.String("mtime", "", "Take that file's mtime as a Published date")
36 desc := flag.String("desc", "", "Description")
37 sigPGP := flag.String("sig-pgp", "", "Path to OpenPGP .asc signature file")
38 sigSSH := flag.String("sig-ssh", "", "Path to OpenSSH .sig signature file")
39 hashes := flag.String("hashes", strings.Join(meta4ra.HashesDefault, ","), "hash-name:command-s")
40 torrent := flag.String("torrent", "", "Torrent URL")
41 log.SetFlags(log.Lshortfile)
44 log.Fatalln("empty -fn")
46 urls := make([]meta4ra.URL, 0, len(flag.Args()))
47 for _, u := range flag.Args() {
48 urls = append(urls, meta4ra.URL{URL: u})
50 h := meta4ra.NewHasher(*hashes)
52 br := bufio.NewReaderSize(os.Stdin, 1<<20)
53 buf := make([]byte, 1<<20)
54 size, err := io.CopyBuffer(h, br, buf)
66 sigData, err := os.ReadFile(*sigPGP)
70 f.Signature = append(f.Signature, meta4ra.Signature{
71 MediaType: meta4ra.SigMediaTypePGP,
72 Signature: "\n" + string(sigData),
76 sigData, err := os.ReadFile(*sigSSH)
80 f.Signature = append(f.Signature, meta4ra.Signature{
81 MediaType: meta4ra.SigMediaTypeSSH,
82 Signature: "\n" + string(sigData),
86 f.MetaURLs = []meta4ra.MetaURL{{MediaType: "torrent", URL: *torrent}}
88 var published time.Time
90 published = time.Now()
92 fi, err := os.Stat(*mtime)
96 published = fi.ModTime()
98 published = published.UTC().Truncate(time.Second)
99 m := meta4ra.Metalink{
100 Files: []meta4ra.File{f},
101 Generator: meta4ra.Generator,
102 Published: published,
104 out, err := xml.MarshalIndent(&m, "", " ")
108 os.Stdout.Write([]byte(xml.Header))
110 os.Stdout.Write([]byte("\n"))