def startElement(self, name, attrs):
        if name not in self.knownTags:
            if not self.ignore_missing_tags:
                print("Error: Unknown Release element '%s'." % name)
                sys.exit()
            elif name not in self.unknown_tags:
                self.unknown_tags.append(name)
        self.stack.append(name)

        if name == 'release':
            self.release = model.Release()
            self.release.id = int(attrs['id'].replace(
                " ", ""))  # omit whitespaces in id to avoid conversion errors
            self.release.status = attrs['status']

        elif name == 'track' and self.stack[-2] == 'tracklist':
            self.release.tracklist.append(model.Track())

        elif name == "image":
            img = model.ImageInfo()
            img.height = attrs["height"]
            img.imageType = attrs["type"]
            img.uri = attrs["uri"]
            img.uri150 = attrs["uri150"]
            img.width = attrs["width"]
            self.release.images.append(img)
            if len(attrs) != 5:
                print("ATTR ERROR")
                print(attrs)
                sys.exit()

        elif name == 'format':
            fmt = model.Format()
            fmt.name = attrs['name']
            fmt.qty = attrs['qty']
            fmt.text = attrs['text']
            self.release.formats.append(fmt)

        elif name == 'label':
            lbl = model.ReleaseLabel()
            lbl.name = attrs['name']
            lbl.catno = attrs['catno']
            self.release.labels.append(lbl)

        elif name == 'company' and 'companies' in self.stack:
            self.release.companies.append(model.Company())

        # Barcode
        elif name == 'identifier' and attrs['type'] == 'Barcode':
            self.release.barcode = attrs['value']
    def startElement(self, name, attrs):
        if not name in self.knownTags:
            if not self.ignore_missing_tags:
                print "Error: Unknown Release element '%s'." % name
                sys.exit()
            elif not name in self.unknown_tags:
                self.unknown_tags.append(name)
        self.stack.append(name)

        if name == 'release':
            self.release = model.Release()
            self.release.id = int(attrs['id'])

        elif name == 'track' and self.stack[-2] == 'tracklist':
            self.release.tracklist.append(model.Track())

        elif name == 'format':
            fmt = model.Format()
            fmt.name = attrs['name']
            self.release.formats.append(fmt)

        elif name == 'label':
            lbl = model.ReleaseLabel()
            lbl.name = attrs['name']
            lbl.catno = attrs['catno']
            self.release.labels.append(lbl)

        elif name == 'company':
            cmp = model.ReleaseCompany()
            self.release.companies.append(cmp)

        elif name == 'artist' and 'track' not in self.stack and 'extraartists' not in self.stack:
            aj = model.ReleaseArtist()
            self.release.artists.append(aj)

        elif name == 'artist' and 'track' in self.stack and 'sub_track' not in self.stack and 'extraartists' not in self.stack:
            taj = model.ReleaseArtist()
            self.release.tracklist[-1].artists.append(taj)

        elif name == 'artist' and 'track' not in self.stack and 'extraartists' in self.stack:
            eaj = model.ExtraArtist()
            self.release.extraartists.append(eaj)

        elif name == 'artist' and 'track' in self.stack and 'sub_track' not in self.stack and 'extraartists' in self.stack:
            teaj = model.ExtraArtist()
            self.release.tracklist[-1].extraartists.append(teaj)
    def startElement(self, name, attrs):
        if not name in self.knownTags:
            if not self.ignore_missing_tags:
                print "Error: Unknown Release element '%s'." % name
                sys.exit()
            elif not name in self.unknown_tags:
                self.unknown_tags.append(name)
        self.stack.append(name)

        if name == 'release':
            self.release = model.Release()
            self.release.id = int(attrs['id'])
            self.release.status = attrs['status']

        elif name == 'track' and self.stack[-2] == 'tracklist':
            self.release.tracklist.append(model.Track())

        elif name == "image":
            img = model.ImageInfo()
            img.height = attrs["height"]
            img.imageType = attrs["type"]
            img.uri = attrs["uri"]
            img.uri150 = attrs["uri150"]
            img.width = attrs["width"]
            self.release.images.append(img)
            if len(attrs) != 5:
                print "ATTR ERROR"
                print attrs
                sys.exit()

        elif name == 'format':
            fmt = model.Format()
            fmt.name = attrs['name']
            fmt.qty = attrs['qty']
            self.release.formats.append(fmt)

        elif name == 'label':
            lbl = model.ReleaseLabel()
            lbl.name = attrs['name']
            lbl.catno = attrs['catno']
            self.release.labels.append(lbl)

        # Barcode
        elif name == 'identifier' and attrs['type'] == 'Barcode':
            self.release.barcode = attrs['value']
示例#4
0
 def startElement(self, name, attrs):
     if not name in self.knownTags:
         if not self.ignore_missing_tags:
             print "Error: Unknown Release element '%s'." % name
             sys.exit()
         elif not name in self.unknown_tags:
             self.unknown_tags.append(name)
     self.stack.append(name)
     if name == 'release':
         self.release = model.Release()
         self.release.id = int(attrs['id'])
         self.release.status = attrs['status']
     elif name == 'track':
         self.release.tracklist.append(model.Track())
     elif name == "image":
         img = model.ImageInfo()
         img.height = attrs["height"]
         img.imageType = attrs["type"]
         img.uri = attrs["uri"]
         img.uri150 = attrs["uri150"]
         img.width = attrs["width"]
         self.release.images.append(img)
         if len(attrs) != 5:
             print "ATTR ERROR"
             print attrs
             sys.exit()
     elif name == 'format':
         fmt = model.Format()
         fmt.name = attrs['name']
         if attrs.has_key('text'):
             fmt.text = attrs['text']
         fmt.qty = attrs['qty']
         if not fmt.qty: fmt.qty = 0
         self.release.formats.append(fmt)
         #global formats
         #if not formats.has_key(attrs["name"]):
         #  formats[attrs["name"]] = True
     elif name == 'label':
         lbl = model.ReleaseLabel()
         lbl.name = attrs['name']
         lbl.catno = attrs['catno']
         self.release.labels.append(lbl)
     elif name == 'identifier':
         identifier = model.Identifier()
         identifier.type = attrs['type']
         identifier.value = attrs['value']
         if attrs.has_key('description'):
             identifier.description = attrs['description']
         self.release.identifiers.append(identifier)
     elif name == "video":
         vid = model.Video()
         vid.duration = attrs["duration"]
         vid.embed = attrs["embed"]
         vid.uri = attrs["src"]
         self.release.videos.append(vid)
     elif name == "artist":
         if 'track' in self.stack:
             if 'extraartists' in self.stack:
                 self.release.tracklist[-1].extraartists.append(
                     model.ArtistCredit())
             else:
                 self.release.tracklist[-1].artists.append(
                     model.ArtistCredit())
         else:
             if 'extraartists' in self.stack:
                 self.release.extraartists.append(model.ArtistCredit())
             else:
                 self.release.artists.append(model.ArtistCredit())
    def startElement(self, name, attrs):
        if not name in self.knownTags:
            if not self.ignore_missing_tags:
                print "Error: Unknown Release element '%s'." % name
                sys.exit()
            elif not name in self.unknown_tags:
                self.unknown_tags.append(name)
        self.stack.append(name)

        if name == 'release':
            self.release = model.Release()
            self.release.id = int(attrs['id'])
            self.release.status = attrs['status']

        elif name == 'track' and self.stack[-2] == 'tracklist':
            self.release.tracklist.append(model.Track())

        elif name == "image":
            img = model.ImageInfo()
            img.height = attrs["height"]
            img.imageType = attrs["type"]
            img.uri = attrs["uri"]
            img.uri150 = attrs["uri150"]
            img.width = attrs["width"]
            self.release.images.append(img)
            if len(attrs) != 5:
                print "ATTR ERROR"
                print attrs
                sys.exit()

        elif name == 'format':
            fmt = model.Format()
            fmt.name = attrs['name']
            fmt.qty = attrs['qty']
            self.release.formats.append(fmt)

        elif name == 'label':
            lbl = model.ReleaseLabel()
            lbl.name = attrs['name']
            lbl.catno = attrs['catno']
            self.release.labels.append(lbl)

        # Barcode
        elif name == 'identifier' and attrs['type'] == 'Barcode':
            self.release.barcode = attrs['value']

        elif name == 'company':
            comp = model.Company()
            self.release.companies.append(comp)

        elif name == 'video':
            vid = model.Video()
            vid.duration = attrs['duration']
            vid.embed = attrs['embed']
            vid.src = attrs['src']
            self.release.videos.append(vid)

        ## not in the elif, will lose the barcode
        if name == 'identifier':
            ident = model.Identifier()
            if 'description' in attrs:
                ident.description = attrs['description']
            ident.type = attrs['type']
            ident.value = attrs['value']
            self.release.identifiers.append(ident)