예제 #1
0
    def register_tracks(self):
        """Retrieves json metadata, including filenames, from
        archive.org for a concert (one which is already registered
        with our database) and inserts the concert's tracks (files)
        with our db.

        >>> from api.music import Concert
        >>> a = Artist.get(tag="ExplosionsintheSky")
        >>> [c.register_tracks() for c in a.concerts]
        """
        for track in Crawler.tracks(self.tag):
            print(track['name'])
            try:
                t = Track(
                    artist_id=self.artist_id,
                    concert_id=self.id,
                    item_id=self.tag,
                    file_id=track['name'],
                    number=track['track'],
                    name=track['title'],
                    length=time2sec(track['length'])
                    )
                t.create()
                self.tracks.append(t)
                self.save()
            except (IntegrityError, InvalidRequestError) as e:
                print(e)