1
from tests.base import BaseTestCase
2
import unittest, time, shutil, sys
3
from xl.lyrics import LyricsManager
4
from xl.lyrics import LyricsNotFoundException
5
from xl.track import Track
9
class LyricsBaseTestCase(BaseTestCase):
11
Test loading lyrics from various plugins and saving
12
embedded lyrics to supported formats
16
BaseTestCase.setUp(self)
17
self.plugindirs = 'plugins'
18
self.lyrics = LyricsManager()
19
# Create a track object
20
# (copying the file here so that it doesn't keep updating in bzr when
21
# the lyrics manager finds the lyrics and changes the file)
22
shutil.copyfile('tests/data/music/delerium/chimera/05 - Truly.mp3',
23
'.testtemp/truly.mp3')
24
self.track = Track(".testtemp/truly.mp3")
25
self.fail_track = Track("tests/data/music/testartist/first/1-black.ogg")
27
self.lyricsfly_plugin = self.load_plugin("lyricsfly")
28
self.lyricsfly_plugin.enable(self)
29
# Remove all existing methods from lyrics manager
30
for method in self.lyrics.get_providers():
31
self.lyrics.remove_search_method(method)
34
class LyricsTestCase(LyricsBaseTestCase):
36
LyricsBaseTestCase.setUp(self)
39
def testFetchLyricsMp3(self):
41
Test fetching lyrics from the file itself
43
#Local searching is added by default
44
self.lyrics.add_defaults()
45
(lyrics, source, url) = self.lyrics.find_lyrics(self.track)
46
assert(len(lyrics) > 0), "Lyrics search failed"
47
assert(source == "file"), "Lyrics came from wrong source"
49
def testFetchLyricsFail(self):
51
Test the failing when not finding lyrics works
54
#Local searching is added by default
55
self.lyrics.add_defaults()
56
self.failUnlessRaises(LyricsNotFoundException, self.lyrics.find_lyrics,self.fail_track)
58
def testSaveLyricsMp3(self):
60
Test saving lyrics to an mp3 file (ID3 tags)
62
# Enable plugins to get the track data
63
self.lyrics.add_defaults()
64
self.lyricsfly_plugin = self.load_plugin('lyricsfly')
65
self.lyricsfly_plugin.enable(self)
66
# Update the track with new lyrics
67
# Get the lyrics from online by forcing, and update the track
68
(lyrics, source, url) = self.lyrics.find_lyrics(self.track, True)
69
# Load the track to see if it saved
70
track = Track("tests/data/music/delerium/chimera/05 - Truly.mp3")
72
assert(track["lyrics"][0] == self.track["lyrics"][0]), "Lyrics not saved to track"
74
def testSaveLyricsOgg(self):
76
Test saving lyrics to an ogg file
78
# TODO find out how ogg/vorbis do their lyrics