]> Sergey Matveev's repositories - meta4ra.git/commitdiff
Ability to skip Published/Generator fields inclusion
authorSergey Matveev <stargrave@stargrave.org>
Tue, 13 Feb 2024 20:42:46 +0000 (23:42 +0300)
committerSergey Matveev <stargrave@stargrave.org>
Wed, 14 Feb 2024 07:37:55 +0000 (10:37 +0300)
cmd/meta4-create/main.go
scheme.go

index 1df7143258c9b1766d8b52c25a0d9f78f3e1d065..1e8b69eaf4307bbe6c11530a8ac212f940f06dd7 100644 (file)
@@ -20,6 +20,7 @@ import (
        "bufio"
        "encoding/xml"
        "flag"
+       "fmt"
        "io"
        "log"
        "os"
@@ -34,12 +35,24 @@ func main() {
        fn := flag.String("fn", "", "Filename")
        mtime := flag.String("mtime", "", "Take that file's mtime as a Published date")
        desc := flag.String("desc", "", "Description")
-       sigPGP := flag.String("sig-pgp", "", "Path to OpenPGP .asc signature file")
-       sigSSH := flag.String("sig-ssh", "", "Path to OpenSSH .sig signature file")
-       hashes := flag.String("hashes", strings.Join(meta4ra.HashesDefault, ","), "hash-name:command-s")
+       sigPGP := flag.String("sig-pgp", "",
+               "Path to OpenPGP .asc signature file for inclusion")
+       sigSSH := flag.String("sig-ssh", "",
+               "Path to OpenSSH .sig signature file for inclusion")
+       hashes := flag.String("hashes",
+               strings.Join(meta4ra.HashesDefault, ","), "hash-name:command-s")
+       noPublished := flag.Bool("no-published", false,
+               "Do not include Published field")
+       noGenerator := flag.Bool("no-generator", false,
+               "Do not include Generator field")
        torrent := flag.String("torrent", "", "Torrent URL")
-       log.SetFlags(log.Lshortfile)
+       flag.Usage = func() {
+               fmt.Fprintf(flag.CommandLine.Output(),
+                       "Usage: %s [options] [URL ...] < DATA > XXX.meta4\n", os.Args[0])
+               flag.PrintDefaults()
+       }
        flag.Parse()
+       log.SetFlags(log.Lshortfile)
        if *fn == "" {
                log.Fatalln("empty -fn")
        }
@@ -95,11 +108,13 @@ func main() {
                }
                published = fi.ModTime()
        }
-       published = published.UTC().Truncate(time.Second)
-       m := meta4ra.Metalink{
-               Files:     []meta4ra.File{f},
-               Generator: meta4ra.Generator,
-               Published: published,
+       m := meta4ra.Metalink{Files: []meta4ra.File{f}}
+       if !*noPublished {
+               t := published.UTC().Truncate(time.Second)
+               m.Published = &t
+       }
+       if !*noGenerator {
+               m.Generator = meta4ra.Generator
        }
        out, err := xml.MarshalIndent(&m, "", "  ")
        if err != nil {
index e790884ad0b77c5f92a588951cf901b09e46eb75..a1cbec378881d69424bb1cb5592112749db18eef 100644 (file)
--- a/scheme.go
+++ b/scheme.go
@@ -21,21 +21,21 @@ import (
 )
 
 type Metalink struct {
-       XMLName   xml.Name  `xml:"urn:ietf:params:xml:ns:metalink metalink"`
-       Files     []File    `xml:"file"`
-       Generator string    `xml:"generator,,omitempty"`
-       Published time.Time `xml:"published,,omitempty"`
+       XMLName   xml.Name   `xml:"urn:ietf:params:xml:ns:metalink metalink"`
+       Files     []File     `xml:"file"`
+       Generator string     `xml:"generator,,omitempty"`
+       Published *time.Time `xml:"published,,omitempty"`
 }
 
 type File struct {
-       XMLName     xml.Name   `xml:"file"`
-       Name        string     `xml:"name,attr"`
-       Description string     `xml:"description,,omitempty"`
-       Hashes      []Hash     `xml:"hash,,omitempty"`
-       MetaURLs    []MetaURL  `xml:"metaurl,,omitempty"`
+       XMLName     xml.Name    `xml:"file"`
+       Name        string      `xml:"name,attr"`
+       Description string      `xml:"description,,omitempty"`
+       Hashes      []Hash      `xml:"hash,,omitempty"`
+       MetaURLs    []MetaURL   `xml:"metaurl,,omitempty"`
        Signature   []Signature `xml:"signature"`
-       Size        uint64     `xml:"size,,omitempty"`
-       URLs        []URL      `xml:"url,,omitempty"`
+       Size        uint64      `xml:"size,,omitempty"`
+       URLs        []URL       `xml:"url,,omitempty"`
 }
 
 type URL struct {