Esempio n. 1
0
 def save(self, **kwargs):
     if kwargs.pop('check_relations', True):
         if self.artist_name:
             self.artist, created = Artist.objects.get_or_create(slug=slugify(self.artist_name), defaults={'name': self.artist_name})
             if created:
                 logger.debug('Created new Artist: %s', self.artist)
         else:
             self.artist = None
         if self.artist and self.album_name:
             self.album, created = Album.objects.get_or_create(artist=self.artist, slug=slugify(self.album_name), defaults={'name': self.album_name})
             if created:
                 logger.debug('Created new Album: %s', self.album)
         else:
             self.album = None
         if self.genre_name:
             self.genre, created = Genre.objects.get_or_create(slug=slugify(self.genre_name), defaults={'name': self.genre_name})
             if created:
                 logger.debug('Created new Genre: %s', self.genre)
         else:
             self.genre = None
     self.date_modified = timezone.now()
     super(Track, self).save(**kwargs)
Esempio n. 2
0
 def handle(self, *args, **options):
     pl = plistlib.readPlist(args[0])
     updated = 0
     tz = pytz.timezone(settings.TIME_ZONE)
     for track_id, info in pl['Tracks'].items():
         name_match = slugify(info['Name'], strip_words=True)
         artist_match = slugify(info['Artist'], strip_words=True)
         track = None
         try:
             album_match = slugify(info['Album'], strip_words=True)
             track = Track.objects.get(match_name=name_match, artist__match_name=artist_match, album__match_name=album_match)
         except:
             try:
                 track = Track.objects.get(match_name=name_match, artist__match_name=artist_match)
             except:
                 pass
         if track:
             track.play_count = info.get('Play Count', track.play_count)
             track.date_added = info.get('Date Added', track.date_added)
             track.save()
             logger.info('Updated %s, play count = %s, date added = %s', track, track.play_count, track.date_added)
             updated += 1
     print '%s tracks updated.' % updated
Esempio n. 3
0
 def save(self, **kwargs):
     self.slug = slugify(self.name)
     self.match_name = slugify(self.name, strip_words=True)
     super(MatchModel, self).save(**kwargs)