pub_meta.go 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566
  1. package main
  2. import (
  3. "encoding/xml"
  4. "log"
  5. "os"
  6. "github.com/fatih/structs"
  7. "github.com/shurcooL/go-goon"
  8. "gopkg.in/errgo.v1"
  9. "gopkg.in/urfave/cli.v2"
  10. )
  11. type Metadata struct {
  12. Identifier string `xml:"identifier"`
  13. Title string `xml:"title"`
  14. Creator string `xml:"creator"`
  15. Mediatype string `xml:"mediatype"`
  16. Collection string `xml:"collection"`
  17. Description string `xml:"description"`
  18. Date string `xml:"date"`
  19. Year string `xml:"year"`
  20. Subject string `xml:"subject"`
  21. Licenseurl string `xml:"licenseurl"`
  22. Publicdate string `xml:"publicdate"`
  23. Addeddate string `xml:"addeddate"`
  24. Uploader string `xml:"uploader"`
  25. Taper string `xml:"taper"`
  26. Source string `xml:"source"`
  27. Runtime string `xml:"runtime"`
  28. Updatedate string `xml:"updatedate"`
  29. Updater string `xml:"updater"`
  30. Curation string `xml:"curation"`
  31. Filesxml string `xml:"filesxml"`
  32. Boxid string `xml:"boxid"`
  33. BackupLocation string `xml:"backup_location"`
  34. }
  35. func metaCmd(ctx *cli.Context) error {
  36. meta, err := os.Open(ctx.Args().First())
  37. if err != nil {
  38. return err
  39. }
  40. defer meta.Close()
  41. dec := xml.NewDecoder(meta)
  42. var data Metadata
  43. err = dec.Decode(&data)
  44. if err != nil {
  45. return err
  46. }
  47. m := structs.Map(data)
  48. m["type"] = "music-release"
  49. var reply map[string]interface{}
  50. err = client.Call("publish", m, &reply)
  51. if err != nil {
  52. return errgo.Notef(err, "publish call failed.")
  53. }
  54. log.Println("published..!")
  55. goon.Dump(reply)
  56. return nil
  57. }