Ejemplo n.º 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)
Ejemplo n.º 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)
Ejemplo n.º 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)))
Ejemplo n.º 4
0
    def test_sync_cover_images(self):
        album = Album.objects.get(pk=1)
        original_coverpath = album.cover_filepath
        self.assertEqual(album.cover_filepath, "T/The Artist/The Album/cover.jpg")
        self.assertTrue(os.path.exists(full_path(album.cover_filepath)))

        album.title = "Egg"
        album.save()

        self.assertEqual(album.cover_filepath, "T/The Artist/Egg/cover.jpg")
        self.assertTrue(os.path.exists(full_path(original_coverpath)))
        self.assertFalse(os.path.exists(full_path(album.cover_filepath)))

        sync_cover_images()

        self.assertFalse(os.path.exists(full_path(original_coverpath)))
        self.assertTrue(os.path.exists(full_path(album.cover_filepath)))
Ejemplo n.º 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")))
Ejemplo n.º 6
0
 def handle_noargs(self, **options):
     delete_empty_instances()
     sync_song_files()
     sync_cover_images()
     remove_empty_directories()