mirror of
https://github.com/bspeice/Melodia
synced 2024-12-25 08:08:13 -05:00
Test playlist importing, bugfixes for import
NOTE: This reverts songs to use the ID as PK - breaks IntegerListField if not done this way.
This commit is contained in:
parent
8125942901
commit
d8b7453260
@ -179,6 +179,7 @@ class Playlist (models.Model):
|
|||||||
#Figure out what format we're in
|
#Figure out what format we're in
|
||||||
if playlist_string[0:7] == "#EXTM3U":
|
if playlist_string[0:7] == "#EXTM3U":
|
||||||
#Import m3u format playlist
|
#Import m3u format playlist
|
||||||
|
print playlist_string
|
||||||
|
|
||||||
#Expected format is "#EXTINF:" followed by the song url on the next line.
|
#Expected format is "#EXTINF:" followed by the song url on the next line.
|
||||||
line_iterator = playlist_string.split("\n").__iter__()
|
line_iterator = playlist_string.split("\n").__iter__()
|
||||||
@ -186,16 +187,18 @@ class Playlist (models.Model):
|
|||||||
#In case we end iteration early
|
#In case we end iteration early
|
||||||
try:
|
try:
|
||||||
for line in line_iterator:
|
for line in line_iterator:
|
||||||
if line[0:8] != "#EXTINF:":
|
|
||||||
song_url = line.next() #Consume the next line
|
if line[0:8] == "#EXTINF:":
|
||||||
|
song_url = line_iterator.next() #Consume the next line
|
||||||
|
|
||||||
try:
|
try:
|
||||||
song = Song.objects.get(url = song_url)
|
song = Song.objects.get(url = song_url)
|
||||||
self.song_list.append(song.id)
|
self.append(song)
|
||||||
|
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
#The URL of our song could not be found
|
#The URL of our song could not be found
|
||||||
warn("The playlist entry: " + song_url + " could not be found, and has not been added to your playlist."
|
warn("The playlist entry: " + song_url + " could not be found, and has not been added to your playlist.")
|
||||||
|
continue
|
||||||
|
|
||||||
#Silently end processing
|
#Silently end processing
|
||||||
except StopIteration:
|
except StopIteration:
|
||||||
@ -212,11 +215,12 @@ class Playlist (models.Model):
|
|||||||
song_url = file_line[5:]
|
song_url = file_line[5:]
|
||||||
try:
|
try:
|
||||||
song = Song.objects.get(url = song_url)
|
song = Song.objects.get(url = song_url)
|
||||||
self.song_list.append(song.id)
|
self.append(song)
|
||||||
|
|
||||||
except ObjectDoesNotExist:
|
except ObjectDoesNotExist:
|
||||||
#The URL of our song could not be found
|
#The URL of our song could not be found
|
||||||
warn("The playlist entry: " + song_url + " could not be found, and has not been added to your playlist."
|
warn("The playlist entry: " + song_url + " could not be found, and has not been added to your playlist.")
|
||||||
|
continue
|
||||||
|
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
@ -47,7 +47,7 @@ class Song (models.Model):
|
|||||||
bit_rate = models.IntegerField(default = _default_bit_rate)
|
bit_rate = models.IntegerField(default = _default_bit_rate)
|
||||||
duration = models.IntegerField(default = _default_bit_rate)
|
duration = models.IntegerField(default = _default_bit_rate)
|
||||||
echonest_song_id = models.CharField(max_length = 64, default = _default_echonest_song_id)
|
echonest_song_id = models.CharField(max_length = 64, default = _default_echonest_song_id)
|
||||||
url = models.CharField(max_length = 255, primary_key = True)
|
url = models.CharField(max_length = 255)
|
||||||
file_hash = melodia_settings.HASH_RESULT_DB_TYPE
|
file_hash = melodia_settings.HASH_RESULT_DB_TYPE
|
||||||
|
|
||||||
def populate_metadata(self, use_echonest = False):
|
def populate_metadata(self, use_echonest = False):
|
||||||
|
@ -81,8 +81,50 @@ class PlaylistExportTest(TestCase):
|
|||||||
a_playlist.save()
|
a_playlist.save()
|
||||||
|
|
||||||
for song in new_archive.songs.all():
|
for song in new_archive.songs.all():
|
||||||
|
song.save()
|
||||||
a_playlist.append(song)
|
a_playlist.append(song)
|
||||||
|
|
||||||
a_playlist.save()
|
a_playlist.save()
|
||||||
|
|
||||||
playlist_string = a_playlist.export()
|
playlist_string = a_playlist.export()
|
||||||
|
|
||||||
|
class PlaylistImportTest(TestCase):
|
||||||
|
def test_playlist_import(self):
|
||||||
|
"Test that we can import a playlist."
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
#- Re-using code from scanning and export
|
||||||
|
from archiver.archive import Archive
|
||||||
|
from archiver.playlist import Playlist
|
||||||
|
|
||||||
|
import os
|
||||||
|
from archiver.archive import Archive
|
||||||
|
from Melodia.settings import PROJECT_FOLDER
|
||||||
|
|
||||||
|
TEST_DATA_FOLDER = os.path.join(PROJECT_FOLDER, "test_data")
|
||||||
|
new_archive = Archive(root_folder = TEST_DATA_FOLDER)
|
||||||
|
|
||||||
|
#We must save the archive before we can start adding songs to it
|
||||||
|
new_archive.save()
|
||||||
|
new_archive.scan()
|
||||||
|
new_archive.save()
|
||||||
|
|
||||||
|
#Resume playlist testing code
|
||||||
|
a_playlist = Playlist()
|
||||||
|
a_playlist.name = "Testing..."
|
||||||
|
a_playlist.save()
|
||||||
|
|
||||||
|
for song in new_archive.songs.all():
|
||||||
|
song.save()
|
||||||
|
a_playlist.append(song)
|
||||||
|
|
||||||
|
a_playlist.save()
|
||||||
|
|
||||||
|
playlist_string = a_playlist.export()
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
another_playlist = Playlist()
|
||||||
|
another_playlist.name = "Testing 2..."
|
||||||
|
another_playlist.save()
|
||||||
|
|
||||||
|
another_playlist._import(playlist_string)
|
||||||
|
print len(another_playlist.song_list)
|
||||||
|
Loading…
Reference in New Issue
Block a user