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