Example #1
0
def download_album(request, pk):
    album = Album.objects.get(pk=pk)
    if album.song_set.count() == 0:
        messages.add_message(
            request, messages.INFO, _('The album does not have any song'))
        return redirect(album.get_absolute_url())
    else:
        sync_song_files(Song.objects.filter(album=album))
        sync_cover_images([album])
        remove_empty_directories(album.filepath)
        return _download(album)
Example #2
0
def download_artist(request, pk):
    artist = Artist.objects.get(pk=pk)
    num_songs = Song.objects.filter(album__artist=artist).count()
    if num_songs == 0:
        messages.add_message(
            request, messages.INFO, _('The artist does not have any song'))
        return redirect(artist.get_absolute_url())
    else:
        sync_song_files(Song.objects.filter(album__artist=artist))
        sync_cover_images(Album.objects.filter(artist=artist))
        remove_empty_directories(artist.filepath)
        return _download(artist)
Example #3
0
    def test_remove_empty_directories(self):
        artist = Artist.objects.get(pk=1)
        original_path = artist.filepath

        artist.name = "Brian"
        artist.save()
        sync_song_files()
        sync_cover_images()

        self.assertTrue(os.path.exists(full_path(original_path)))
        self.assertTrue(os.path.exists(full_path(artist.filepath)))

        remove_empty_directories()

        self.assertFalse(os.path.exists(full_path(original_path)))
        self.assertTrue(os.path.exists(full_path(artist.filepath)))
Example #4
0
    def test_sync_song_files(self):
        song = Song.objects.get(pk=1)
        original_filepath = song.filepath
        self.assertEqual(song.filepath, "T/The Artist/The Album/04 - The Fourth Song.ogg")
        self.assertTrue(os.path.exists(full_path(song.filepath)))

        song.title = "Spam"
        song.save()

        self.assertEqual(song.filepath, "T/The Artist/The Album/04 - Spam.ogg")
        self.assertTrue(os.path.exists(full_path(original_filepath)))
        self.assertFalse(os.path.exists(full_path(song.filepath)))

        sync_song_files()

        self.assertFalse(os.path.exists(full_path(original_filepath)))
        self.assertTrue(os.path.exists(full_path(song.filepath)))
Example #5
0
    def test_sync_songs_and_cover(self):
        artist = Artist.objects.get(pk=1)
        original_path = artist.filepath
        self.assertEqual(artist.filepath, "T/The Artist")
        self.assertTrue(os.path.exists(full_path(artist.filepath)))
        self.assertTrue(os.path.exists(os.path.join(full_path(artist.filepath), "The Album", "cover.jpg")))

        artist.name = "Brian"
        artist.save()

        self.assertEqual(artist.filepath, "B/Brian")
        self.assertTrue(os.path.exists(full_path(original_path)))
        self.assertFalse(os.path.exists(full_path(artist.filepath)))
        self.assertTrue(os.path.exists(os.path.join(full_path(original_path), "The Album", "cover.jpg")))

        sync_song_files()
        sync_cover_images()

        self.assertTrue(os.path.exists(full_path(artist.filepath)))
        self.assertTrue(os.path.exists(os.path.join(full_path(artist.filepath), "The Album", "cover.jpg")))
Example #6
0
 def handle_noargs(self, **options):
     delete_empty_instances()
     sync_song_files()
     sync_cover_images()
     remove_empty_directories()
Example #7
0
 def get_object(self, queryset=None):
     obj = super(SongDetailView, self).get_object(queryset)
     sync_song_files([obj])
     return obj