github.com/boki/go-xmp@v1.0.1/models/mp4/model.go (about)

     1  // Copyright (c) 2017-2018 Alexander Eichhorn
     2  //
     3  // Licensed under the Apache License, Version 2.0 (the "License"): you may
     4  // not use this file except in compliance with the License. You may obtain
     5  // a copy of the License at
     6  //
     7  //     http://www.apache.org/licenses/LICENSE-2.0
     8  //
     9  // Unless required by applicable law or agreed to in writing, software
    10  // distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
    11  // WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
    12  // License for the specific language governing permissions and limitations
    13  // under the License.
    14  
    15  // Package mp4 implements metadata found in ISO/IEC 14496-14:2003 (3GPP/ISO MP4) files.
    16  package mp4
    17  
    18  import (
    19  	"fmt"
    20  	"trimmer.io/go-xmp/models/qt"
    21  	"trimmer.io/go-xmp/xmp"
    22  )
    23  
    24  var (
    25  	NsMP4 = xmp.NewNamespace("mp4", "http://ns.apple.com/quicktime/mp4/1.0/", NewModel)
    26  )
    27  
    28  func init() {
    29  	xmp.Register(NsMP4, xmp.MovieMetadata)
    30  }
    31  
    32  func NewModel(name string) xmp.Model {
    33  	return &MP4Info{}
    34  }
    35  
    36  // Note: all tags are single-language versions
    37  type MP4Info struct {
    38  	AlbumAndTrack        string         `mp4:"albm" xmp:"mp4:AlbumAndTrack"`
    39  	Author               string         `mp4:"auth" xmp:"mp4:Author"`
    40  	Classification       string         `mp4:"clsf" xmp:"mp4:Classification"`
    41  	CollectionName       string         `mp4:"coll" xmp:"mp4:CollectionName"`
    42  	Copyright            string         `mp4:"cprt" xmp:"mp4:Copyright"`
    43  	CreationDate         xmp.Date       `mp4:"date" xmp:"mp4:CreationDate"`
    44  	Description          string         `mp4:"dscp" xmp:"mp4:Description"`
    45  	GenreName            string         `mp4:"gnre" xmp:"mp4:GenreName"`
    46  	KeywordList          xmp.StringList `mp4:"kywd" xmp:"mp4:KeywordList"`
    47  	Location             *qt.Location   `mp4:"loci" xmp:"mp4:Location"`
    48  	MediaRatingText      string         `mp4:"rtng" xmp:"mp4:MediaRatingText"`
    49  	Performer            string         `mp4:"perf" xmp:"mp4:Performer"`
    50  	RecordingYear        int            `mp4:"yrrc" xmp:"mp4:RecordingYear"`
    51  	TaggedCharacteristic string         `mp4:"tagc" xmp:"mp4:TaggedCharacteristic"`
    52  	Thumbnail            []byte         `mp4:"thmb" xmp:"mp4:Thumbnail"`
    53  	Title                string         `mp4:"titl" xmp:"mp4:Title"`
    54  	UserRating           int            `mp4:"urat" xmp:"mp4:UserRating"`
    55  }
    56  
    57  func (m *MP4Info) Namespaces() xmp.NamespaceList {
    58  	return xmp.NamespaceList{NsMP4}
    59  }
    60  
    61  func (m *MP4Info) Can(nsName string) bool {
    62  	return nsName == NsMP4.GetName()
    63  }
    64  
    65  func (x *MP4Info) SyncModel(d *xmp.Document) error {
    66  	return nil
    67  }
    68  
    69  func (x *MP4Info) SyncFromXMP(d *xmp.Document) error {
    70  	return nil
    71  }
    72  
    73  func (x MP4Info) SyncToXMP(d *xmp.Document) error {
    74  	return nil
    75  }
    76  
    77  func (x *MP4Info) CanTag(tag string) bool {
    78  	_, err := xmp.GetNativeField(x, tag)
    79  	return err == nil
    80  }
    81  
    82  func (x *MP4Info) GetTag(tag string) (string, error) {
    83  	if v, err := xmp.GetNativeField(x, tag); err != nil {
    84  		return "", fmt.Errorf("%s: %v", NsMP4.GetName(), err)
    85  	} else {
    86  		return v, nil
    87  	}
    88  }
    89  
    90  func (x *MP4Info) SetTag(tag, value string) error {
    91  	if err := xmp.SetNativeField(x, tag, value); err != nil {
    92  		return fmt.Errorf("%s: %v", NsMP4.GetName(), err)
    93  	}
    94  	return nil
    95  }
    96  
    97  func (x *MP4Info) ListTags() (xmp.TagList, error) {
    98  	if l, err := xmp.ListNativeFields(x); err != nil {
    99  		return nil, fmt.Errorf("%s: %v", NsMP4.GetName(), err)
   100  	} else {
   101  		return l, nil
   102  	}
   103  }