Example #1
0
 def tearDownClass(self):
     # Delete Songs Data
     for each_record in range(self.records):
         record = each_record+1
         Song.objects(song_id=record).first().delete()
         Podcast.objects(podcast_id=record).first().delete()
         Audiobook.objects(audiobook_id=record).first().delete()
     # End-For
     self.app_context.pop()
Example #2
0
    def add_song(self, **kwargs):
        artist_name = kwargs.get('title')[0]
        artist = Artist.objects(name=artist_name)

        song_name = kwargs.get('title')[-1]
        if not artist or Song.objects(name=song_name):
            self.add_artist(**kwargs)

        if self.is_song_exist(song_name):
            Log(type_added='song', name_added=song_name).save()
            return False

        self.download(kwargs.get('download_url'))
        size = kwargs.get('duration_size')
        size = ' '.join((size[2], size[3]))
        song = Song(artist=artist.get(),
                    name=song_name,
                    duration=kwargs.get('duration_size')[0],
                    download_url=kwargs.get('download_url'),
                    size=size)
        with open(TEMP_FILE, 'rb') as binary_file:
            song.audio_file.put(binary_file)
        shutil.rmtree(TEMP)
        if song:
            song.save()
            Log(type_added='song', name_added=song_name, added=True).save()
            return True

        Log(type_added='song', name_added=song_name).save()
        return False
Example #3
0
 def get_artist_by_song(song_name):
     song = Song.objects(name=song_name)
     if not song:
         return False
     artist = Artist.objects(_id=song.get().artist)
     if not artist:
         return False
     return artist
Example #4
0
 def get_artist_tracklist(artist_name):
     artist = Artist.objects(name=artist_name)
     if not artist:
         return False
     artist_id = artist.get().id
     tracklist = Song.objects(artist=artist_id)
     if not tracklist:
         raise False
     return tracklist
Example #5
0
 def tearDownClass(self):
     _song = Song.objects(song_id=self.record).first()
     _podcast = Podcast.objects(podcast_id=self.record).first()
     _audiobook = Audiobook.objects(audiobook_id=self.record).first()
     if _song:
         _song.delete()
     if _podcast:
         _podcast.delete()
     if _audiobook:
         _audiobook.delete()
     self.app_context.pop()
Example #6
0
 def tearDownClass(self):
     for each_record in [self.record, self.record_update]:
         _song = Song.objects(song_id=each_record).first()
         _podcast = Podcast.objects(podcast_id=each_record).first()
         _audiobook = Audiobook.objects(audiobook_id=each_record).first()
         if _song:
             _song.delete()
         if _podcast:
             _podcast.delete()
         if _audiobook:
             _audiobook.delete()
         # End-If
     # End-For
     self.app_context.pop()
Example #7
0
 def to_json_song(media=False):
     song = Song.objects()
     if not song:
         return False
     return song.to_json(indent=4, ensure_ascii=False, media=media)
Example #8
0
 def is_song_exist(song_name):
     return Song.objects(name=song_name).count()