Esempio n. 1
0
def main():
    """
    Main function
    """
    nbt = Song()
    for fpath in nbt.userpl():
        sys.stdout.write("%s\n" % (fpath))
Esempio n. 2
0
 def get_song_by_track(self, track_num):
     tracks = self._get_track_list()
     song_num = tracks[track_num]
     song_id = 'song_{:02x}'.format(song_num)
     song = Song(song_id)
     song.set_controller(self._controller)
     return song
Esempio n. 3
0
 def __init__(self, *args, **kwargs):
     # set addon object
     self.m_addon = kwargs["addon"]
     # passing "<windowId>" from RunScript() means run in background
     self.use_gui = kwargs["gui"]
     # initialize our super classes
     XBMCPlayer.__init__(self)
     Properties.__init__(self)
     # initialize timers
     self._lyric_timer = None
     self._fetch_timer = None
     # log started action
     self._log_addon_action("started")
     # initialize our Song class
     self.song = Song(addon=self.m_addon)
     # initialize our prefetched Song class
     # TODO: remove the self.isPlayingAudio() check when/if XBMC supports offset for player
     self.prefetched_song = None
     if (self.m_addon.getSetting("prefetch_lyrics") and self.isPlayingAudio()):
         self.prefetched_song = Song(addon=self.m_addon, prefetch=True)
     # start
     if (self.use_gui):
         self._start_gui()
     else:
         self._start_background()
Esempio n. 4
0
class SongTests(unittest.TestCase):
    def setUp(self):
        self.test_song = Song(
            "Hells Bells",
            "ACDC",
            "Back in Black",
            5,
            312,
            320
            )

    def test_song_init(self):
        self.assertEqual(self.test_song.title, "Hells Bells")
        self.assertEqual(self.test_song.artist, "ACDC")
        self.assertEqual(self.test_song.album, "Back in Black")
        self.assertEqual(self.test_song.rating, 5)
        self.assertEqual(self.test_song.length, 312)
        self.assertEqual(self.test_song.bitrate, 320)

    def test_song_rate(self):
        self.test_song.rate(3)
        self.assertEqual(self.test_song.rating, 3)

    def test_song_rate_out_of_range(self):
        with self.assertRaises(ValueError):
            self.test_song.rate(8)
Esempio n. 5
0
class SongTests(unittest.TestCase):

    def setUp(self):
        self.song = Song("The Jack", "ACDC", "T.N.T.", 4, 240, 320)

    def test_init(self):
        song = Song("The Jack", "ACDC", "T.N.T.", 4, 240, 320)
        self.assertEqual(song.title, "The Jack")
        self.assertEqual(song.artist, "ACDC")
        self.assertEqual(song.album, "T.N.T.")
        self.assertEqual(song.rating, 4)
        self.assertEqual(song.length, 240)
        self.assertEqual(song.bitrate, 320)

    def test_rate_value_error(self):
        with self.assertRaises(ValueError):
            self.song.rate(6)

    def test_rate_success(self):
        self.song.rate(3)
        self.assertEqual(self.song.rating, 3)

    def test_str(self):
        expected = "ACDC The Jack - 0:04:00"
        self.assertEqual(str(self.song), expected)
class TestSong(unittest.TestCase):

    def setUp(self):
        self.test_song = Song(
            'Hells Bells',
            'AC/DC',
            'rough and though',
            5,
            520,
            256)

    def test_song_init(self):
        self.assertEqual(self.test_song.title, 'Hells Bells')
        self.assertEqual(self.test_song.artist, 'AC/DC')
        self.assertEqual(self.test_song.album, 'rough and though')
        self.assertEqual(self.test_song.rating, 5)
        self.assertEqual(self.test_song.lenght, 520)
        self.assertEqual(self.test_song.bitrate, 256)

    def test_rating(self):
        self.test_song.set_rating(4)
        self.assertEqual(self.test_song.rating, 4)

    def test_rating_out_of_range(self):
        with self.assertRaises(ValueError):
            self.test_song.set_rating(8)
Esempio n. 7
0
def search(query):

    result = api.search_all_access('lil dicky')['song_hits'][0]['track']
    s = Song(result['title'], result['artist'], result['album'])
    s.add_gmusic_id(result['nid'])
    s.add_gmusic_video_id(result['primaryVideo']['id'])
    return s
Esempio n. 8
0
class TestSong(unittest.TestCase):

    def setUp(self):
        self.song = Song(
            "Whole Lotta Love",
            "Led Zeppelin",
            "Led Zeppelin II",
            5,
            334,
            320000
        )

    def test_song_init(self):
        self.assertEqual(self.song.title, "Whole Lotta Love")
        self.assertEqual(self.song.artist, "Led Zeppelin")
        self.assertEqual(self.song.album, "Led Zeppelin II")
        self.assertEqual(self.song.rating, 5)
        self.assertEqual(self.song.length, 334)
        self.assertEqual(self.song.bitrate, 320000)

    def test_rate(self):
        self.song.rate(4)
        self.assertEqual(self.song.rating, 4)

    def test_rate_error(self):
        with self.assertRaises(ValueError):
            self.song.rate(200000)
Esempio n. 9
0
def main():
    """
    Main function
    """
    nbt = Song()
    fname = nbt.next()
    #trigger(fname, "/tmp/calorine.socket")
    return fname
Esempio n. 10
0
 def choose_file_and_convert(self):
     filename = WinFile(False).run()
     if filename and common.file_is_supported(filename):
         tags = {"uri" : utils.get_uri_from_path(filename)}
         s = Song()
         s.init_from_dict(tags)
         s.read_from_file()
         AttributesUI([s]).show_window()
 def test_eq(self):
     playlist_2 = Playlist("2016", repeat=False, shuffle=False)
     self.assertEqual(self.playlist, playlist_2)
     song_1 = Song("Cheap Thrills", "Sia", "This Is Acting", "03:31")
     song_2 = Song("Never Give Up", "Sia", "This Is Acting", "03:42")
     song_3 = Song("Alone", "Alan Walker", "Alan Walker", "02:43")
     self.playlist.add_songs([song_1, song_2, song_3])
     playlist_2.add_songs([song_1, song_2, song_3])
     self.assertEqual(self.playlist, playlist_2)
Esempio n. 12
0
 def test_show_artists(self):
     song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
     song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
     song3 = Song('title3', 'artist2', 'album3', 5, 88, 148)
     self.playlist.add_song(song1)
     self.playlist.add_song(song2)
     self.playlist.add_song(song3)
     artists = ['artist1', 'artist2']
     self.assertEqual(artists, self.playlist.show_artists())
Esempio n. 13
0
 def test_remove_bad_quality(self):
     song1 = Song('title1', 'artist1', 'album1', 5, 93, 256)
     song2 = Song('title2', 'artist2', 'album2', 3, 87, 126)
     song3 = Song('title3', 'artist3', 'album3', 5, 88, 148)
     self.playlist.add_song(song1)
     self.playlist.add_song(song2)
     self.playlist.add_song(song3)
     self.playlist.remove_bad_quality(126)
     self.assertEqual(self.playlist.total_length(), 181)
 def test_load(self):
     song_1 = Song("Cheap Thrills", "Sia", "This Is Acting", "03:31")
     song_2 = Song("Never Give Up", "Sia", "This Is Acting", "03:42")
     song_3 = Song("Alone", "Alan Walker", "Alan Walker", "02:43")
     p_list = Playlist("New playlist", repeat=True, shuffle=True)
     p_list.add_songs([song_1, song_2, song_3])
     p_list.save()
     p = Playlist.load("New-playlist.json")
     self.assertEqual(p, p_list)
Esempio n. 15
0
    def test_tune_notation(self):
        song = Song(lyrics="hi")

        notation = song.tune_notation()

        self.assertRegexpMatches(notation, "[[inpt TUNE]]")
        self.assertRegexpMatches(notation, "1AY {D 435; P")
        self.assertRegexpMatches(notation, "hh {D 65; P")
        self.assertRegexpMatches(notation, "[[inpt TEXT]]")
Esempio n. 16
0
def main():
    song = Song(name='demo')

    # It needs at least one sample. I'll just make a simple one
    sample = Sample(name='sine')

    # I think the samples are supposed to have a power of 2 length
    sample.wave = [100 * sin(2 * pi * n / 32) for n in range(32)]
    song.samples.append(sample)

    # I didn't really think all the way through ex nihilo generation,
    # so this is a little clunky. Make some note objects...
    note_c = Note()
    note_c.sample = 1  # Sample numbers start at 1, 0 is empty
    note_c.pitch = 'C-2'

    note_d = Note()
    note_d.sample = 1
    note_d.pitch = 'D-2'

    note_e = Note()
    note_e.sample = 1
    note_e.pitch = 'E-2'
    # I'm not sure if there will be side-effects of using a note
    # object in multiple places. I should look into making them
    # behave more like primitves. It will be ok for now.

    # Make a new pattern to go in our song
    pattern0 = Pattern()

    # Channels are made automatically and can't be moved or replaced,
    # but we'll grab one so we don't have to type pattern0[0] everywhere
    channel = pattern0[0]

    # Write our song
    channel[0] = note_e
    channel[4] = note_d
    channel[8] = note_c

    channel[16] = note_e
    channel[20] = note_d
    channel[24] = note_c

    channel[32:40:2] = note_c
    channel[40:48:2] = note_d

    channel[48] = note_e
    channel[52] = note_d
    channel[56] = note_c

    # Adding a pattern takes two steps
    song.patterns.append(pattern0)  # Store the pattern
    song.positions = [0]  # Give it a position

    # Write out the file
    song.write_file('~/Desktop/hot_cross_sines.mod')
Esempio n. 17
0
 def test_add_search_results(self):
     print "testing if chosen search result is added correctly"
     text = "wonderwall"
     results = spotify.search(text, limit=10, type='track')
     title = results['tracks']['items'][0]['name']
     artist = results['tracks']['items'][0]['artists'][0]['name']
     uri = results['tracks']['items'][0]['uri']
     song1 = Song(1, title, artist, uri)
     assert 'Wonderwall' in song1.getTitle()
     assert 'Oasis' in song1.getArtist()
Esempio n. 18
0
 def test_get_json_songs(self):
     song_1 = Song("Cheap Thrills", "Sia", "This Is Acting", "03:31")
     song_2 = Song("Never Give Up", "Sia", "This Is Acting", "03:42")
     song_3 = Song("Alone", "Alan Walker", "Alan Walker", "02:43")
     s_list = [song_1, song_2, song_3]
     self.song_list.add_songs(s_list)
     expect = [{"title": "Cheap Thrills", "artist": "Sia", "album": "This Is Acting", "length": "03:31" },\
             {"title": "Never Give Up", "artist": "Sia", "album": "This Is Acting", "length": "03:42"},\
             {"title": "Alone", "artist": "Alan Walker", "album": "Alan Walker", "length": "02:43"}]
     self.assertEqual(self.song_list.get_json_songs(), expect)
Esempio n. 19
0
 def test_artists(self):
     song_1 = Song("Cheap Thrills", "Sia", "This Is Acting", "03:31")
     song_2 = Song("Never Give Up", "Sia", "This Is Acting", "03:42")
     song_3 = Song("Alone", "Alan Walker", "Alan Walker", "02:43")
     s_list = [song_1, song_2, song_3]
     self.song_list.add_songs(s_list)
     self.assertEqual(self.song_list.artists(), {
         "Alan Walker": 1,
         "Sia": 2
     })
 def test_artists(self):
     new_pl = Playlist(name="Code.json", repeat=True, shuffle=True)
     new_pl.add_songs([
         Song('Its my life', 'Bon Jovi', 'Album', '0:0:33'),
         Song('Title', 'Bon Jovi', 'Album', '10:0:33'),
         Song('Lelee', 'Azis', 'Album', '0:3:1')
     ])
     artists_histogram = new_pl.get_artists()
     self.assertEqual(len(artists_histogram.keys()), 2)
     self.assertEqual(artists_histogram, {'Azis': 1, 'Bon Jovi': 2})
Esempio n. 21
0
 def test_song_eq_if_equal(self):
     s1 = Song(title="Odin",
               artist="Manowar",
               album="The Sons of Odin",
               length="3:44")
     s2 = Song(title="Odin",
               artist="Manowar",
               album="The Sons of Odin",
               length="3:44")
     self.assertTrue(s1 == s2)
Esempio n. 22
0
 def test_song_eq_if_not_equal(self):
     s1 = Song(title="Odin",
               artist="Manowar",
               album="The Sons of Odin",
               length="3:44")
     s2 = Song(title="Kingdom Come",
               artist="Manowar",
               album="Kings of Metal",
               length="3:59")
     self.assertFalse(s1 == s2)
 def test_next_song(self):
     first_song = Song('Its my life', 'Bon Jovi', 'Album', '0:0:33')
     second_song = Song('Title', 'Bon Jovi', 'Album', '10:0:33')
     third_song = Song('Lelee', 'Azis', 'Album', '0:3:1')
     new_pl = Playlist(name="Code.json", repeat=True, shuffle=False)
     new_pl.add_songs([first_song, second_song, third_song])
     self.assertEqual(first_song, new_pl.next_song())
     self.assertEqual(second_song, new_pl.next_song())
     self.assertEqual(third_song, new_pl.next_song())
     self.assertEqual(first_song, new_pl.next_song())
Esempio n. 24
0
    def setUp(self):
        self.song = Song(title="Odin",
                         artist="Manowar",
                         album="The Sons of Odin",
                         length="3:44")

        self.song1 = Song(title="title",
                          artist="artist",
                          album="album",
                          length="1:23:45")
Esempio n. 25
0
 def test_equality_for_different_albums_with_songs(self):
     first_album = Album('album title', 2020)
     second_album = Album('album title', 2020)
     third_album = Album('album title', 2020)
     first_album.add(Song('same song'))
     second_album.add(Song('other song'))
     third_album.add(Song('same song'))
     third_album.add(Song('other song'))
     assert first_album != second_album
     assert first_album != third_album
Esempio n. 26
0
 def setUp(self):
     self.my_playlist = Playlist("myList")
     self.song = Song("Desert rose", "Sting", "Brand New Day", 4.0, "4:45",
                      8)
     self.song1 = Song("Hells Bells", "ACDC", "Brand New Day", 5.0, "05:09",
                       8)
     self.song2 = Song("Baby, Please Don't Go", "ACDC", "Brand New Day",
                       1.0, "03:51", 8)
     self.song3 = Song("I Want It That Way", "Backstreet Boys",
                       "Brand New Day", 3.0, "05:00", 8)
Esempio n. 27
0
 def load(self):    
     objs = utils.load_db(self.db_file)
     songs = []
     if objs:
         for obj in objs:
             s = Song()
             s.init_from_dict(obj, cmp_key="sid")
             songs.append(s)
     if songs:        
         self.add_songs(songs)
Esempio n. 28
0
	def test_add_search_results(self):
		print "testing if chosen search result is added correctly"
		text = "wonderwall"
		results = spotify.search(text, limit = 10, type = 'track')
		title = results['tracks']['items'][0]['name']
		artist = results['tracks']['items'][0]['artists'][0]['name']
		uri = results['tracks']['items'][0]['uri']
		song1 = Song(1, title, artist, uri)
		assert 'Wonderwall' in song1.getTitle()
		assert 'Oasis' in song1.getArtist()
Esempio n. 29
0
 def load(self, root):
     for dirpath, dirnames, filenames in os.walk(root, followlinks=True):
         for name in filenames:
             if not name.endswith(".txt"):
                 continue
             path = os.path.join(dirpath, name)
             print path
             song = Song(path)
             song.id = len(self.songs)
             self.songs.append(song)
Esempio n. 30
0
 def test_if_two_song_are_equal(self):
     song1 = Song(title="Odin",
                  artist="Manowar",
                  album="The Sons of Odin",
                  length="04:44")
     song2 = Song(title="Odin",
                  artist="Manowar",
                  album="The Sons of Odin",
                  length="04:44")
     self.assertEqual(song1, song2)
Esempio n. 31
0
class TestSong(unittest.TestCase):

    def setUp(self):
        self.song = Song("Sweet Child O'mine", "Guns N' Roses", "Appetite for Destruction", 5, 356, 320 )

    def test_rate_0(self):
        self.song.rate(5)
        self.assertEqual(5,self.song.rating)
    def test_rate_error(self):
        self.assertRaises(ValueError, lambda:self.song.rate(6))
Esempio n. 32
0
 def test_remove_bad_quality(self):
     new_playlist = Playlist("my_playlist")
     enter_song = Song("Enter sandman", "Metallica", "Balck album", 2, 300,
                       192000)
     harvester_song = Song("Harvester of sorrow", "Metallica",
                           "...And justice for all", 3, 300, 150000)
     new_playlist.songs.append(harvester_song)
     new_playlist.songs.append(enter_song)
     new_playlist.remove_bad_quality()
     self.assertEqual(len(new_playlist.songs), 1)
Esempio n. 33
0
	def test_add_new_songs_consecutively_to_playlist(self):
		song1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
		song2 = Song(title="Hail and Kill", artist="Manowar", album="Kings of Metal", length="5:50")
		playlist = Playlist('my playlist')
		expected_songs_in_playlist = [song1, song2]

		playlist.add_song(song1)
		playlist.add_song(song2)
		
		self.assertEqual(playlist.get_songs(), expected_songs_in_playlist)	
def main():
    #write your code below this line
  jack_sparrow = Song("The Lonely Island", "Jack Sparrow", 196)
  another_sparrow = Song("The Lonely Island", "Jack Sparrow", 196)

  if (jack_sparrow == another_sparrow):
      print("Songs are equal.")

  if (jack_sparrow == "Another object"):
      print("Strange things are afoot.")
Esempio n. 35
0
 def load(self, root):
     for dirpath, dirnames, filenames in os.walk(root, followlinks=True):
         for name in filenames:
             if not name.endswith(".txt"):
                 continue
             path = os.path.join(dirpath, name)
             print path
             song = Song(path)
             song.id = len(self.songs)
             self.songs.append(song)
Esempio n. 36
0
	def test_when_remove_song_not_in_playlist_then_return_message(self):
		song1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
		song2 = Song(title="Hail and Kill", artist="Manowar", album="Kings of Metal", length="5:50")
		playlist = Playlist('my playlist')
		playlist.add_song(song1)
	
		message = playlist.remove_song(song2)
		
		self.assertEqual(message, 'This song is not in the playlist')
		self.assertEqual(playlist.get_songs(), [song1])	
Esempio n. 37
0
	def test_when_add_one_song_two_times_then_add_it_just_once(self):
		song1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
		song2 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
		playlist = Playlist('my playlist')
		expected_songs_in_playlist = [song1]

		playlist.add_song(song1)
		playlist.add_song(song2)
		
		self.assertEqual(playlist.get_songs(), expected_songs_in_playlist)		
Esempio n. 38
0
	def test_when_artists_appear_once_return_histogram(self):
		song1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
		song2 = Song(title="Hail and Kill", artist="Pesho", album="Kings of Metal", length="5:50")
		playlist = Playlist('my playlist')
		playlist.add_songs([song1, song2])
		expected_result = {'Manowar': 1, 'Pesho': 1}

		result = playlist.artists()

		self.assertEqual(result, expected_result)	
Esempio n. 39
0
	def test_when_playlist_has_no_requirements_and_no_init(self):
		song1 = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="3:44")
		song2 = Song(title="Hail and Kill", artist="Manowar", album="Kings of Metal", length="5:50")
		playlist = Playlist('my playlist')
		playlist.add_songs([song1, song2])

		song = playlist.next_song()
		
		self.assertEqual(playlist.get_index_of_last_played_song(), 0)
		self.assertEqual(song, song1)		
    def test_with_valid_song_when_already_in_dict_should_replace_the_value(
            self):
        song_one = Song('Song', 'Artist', 'Album 1', '3:30')
        song_two = Song('Song', 'Artist', 'Album 2', '5:00')
        songs_dictionary = {song_one: 1}

        songs_dictionary[song_two] = 2
        expected = {Song('Song', 'Artist', 'Album 1', '3:20'): 2}

        self.assertEqual(songs_dictionary, expected)
Esempio n. 41
0
 def post_mount_cb(self, track_infos, device_path, udi):
     track_tags, cd_label = track_infos
     if len(track_tags) > 0:
         songs = []
         for tag in track_tags:
             cd_song = Song()
             cd_song.init_from_dict(tag)
             cd_song.set_type("cdda")
             songs.append(cd_song)
         Dispatcher.new_audiocd_playlist(cd_label, songs, udi)
         self.audiocd_items[udi] = songs
 def test_eq(self):
     song2 = Song(title="Odin",
                  artist="Manowar",
                  album="The Sons of Odin",
                  length="3:44")
     song3 = Song(title="Odin1",
                  artist="Manowar",
                  album="The Sons of Odin",
                  length="3:44")
     self.assertTrue(song2 == self.song)
     self.assertFalse(song3 == self.song)
Esempio n. 43
0
 def test_str(self):
     new_playlist = Playlist("my_playlist")
     enter_song = Song("Enter sandman", "Metallica", "Balck album", 2, 300,
                       192)
     harvester_song = Song("Harvester of sorrow", "Metallica",
                           "...And justice for all", 3, 300, 150)
     new_playlist = Playlist("my_playlist")
     new_playlist.songs.append(harvester_song)
     new_playlist.songs.append(enter_song)
     expected_string = "Metallica - Harvester of sorrow 300\nMetallica - Enter sandman 300\n"
     self.assertEqual(expected_string, new_playlist.str_func())
Esempio n. 44
0
def compose():
    s = Song()

    # choose a style
    s.style = Song.styles[randint(0, len(Song.styles)-1)]

    # choose a mood
    s.mood = Song.moods[randint(0, len(Song.moods)-1)]

    # generate a song arrangement
    s.arrangement = genArrangement()
Esempio n. 45
0
def search(query):
	escaped_query = urllib.quote(query)
	base_url = "https://www.googleapis.com/youtube/v3/search?type=video&order=relevance&part=snippet&key=" + youtube_api_key + "&q="
	search_string = base_url + escaped_query
	r = requests.get(search_string)
	first_result = r.json()['items'][0]
	title = first_result['snippet']['title']
	song_id = first_result['id']['videoId']
	s = Song(title,None, None)
	s.add_youtube_id(song_id)
	return s
Esempio n. 46
0
 def test_add_songs(self):
     song_1 = Song("Cheap Thrills", "Sia", "This Is Acting", "03:31")
     song_2 = Song("Never Give Up", "Sia", "This Is Acting", "03:42")
     song_3 = Song("Alone", "Alan Walker", "Alan Walker", "02:43")
     s_list = [song_1, song_2, song_3]
     self.song_list.add_songs(s_list)
     self.assertIn(song_1, self.song_list.songs)
     self.assertIn(song_2, self.song_list.songs)
     self.assertIn(song_3, self.song_list.songs)
     self.assertEqual(self.song_list.artists_hist["Sia"], 2)
     self.assertEqual(self.song_list.artists_hist["Alan Walker"], 1)
 def create_song(self, tags):    
     
     # Set dirty flag.
     self.set_dirty()
     
     s = Song()
     s.init_from_dict(tags)
     s.set_type(self.__type)
     self.add(s)
     
     return s
Esempio n. 48
0
 def decode_song(self, one_song):
     title = one_song["title"]
     artist = one_song["artist"]
     album = one_song["album"]
     rating = one_song["rating"]
     length = one_song["length"]
     bitrate = one_song["bitrate"]
     file_path = one_song["file_path"]
     created_song = Song(title, artist, album, rating, length, bitrate)
     created_song.file_path = file_path
     return created_song
    def load_status(self):
        obj = utils.load_db(self.status_db_file)
        if obj:
            index, d = obj
            song = Song()
            song.init_from_dict(d, cmp_key="sid")
        else:
            index = 0
            song = None

        self.playlist_index = index
        self.last_song = song
Esempio n. 50
0
	def test_sort_songlist(self):
		print "testing if songlist sorts songs properly"
		songList = SongList()
		song1 = Song(1, "TestSong1", "TestArtist", 0)
		song2 = Song(2, "TestSong2", "TestArtist", 0)
		song2.incrementScore() 			#song2 should end up in index 0 after sort
		songList.add(song1)
		songList.add(song2)
		songList.sortList()
		songtest = songList.getSongAt(0)
		assert 'TestSong2' in songtest.getTitle()
		assert 2 == songtest.getId()
    def test_with_equal_songs_should_return_true(self):
        title = 'Song'
        artist = 'Artist'
        album_one = 'First album'
        length_one = '3:20'
        album_two = 'Second album'
        length_two = '3:50'

        song_one = Song(title, artist, album_one, length_one)
        song_two = Song(title, artist, album_two, length_two)

        self.assertEqual(song_one, song_two)
Esempio n. 52
0
	def test_song_score(self):
		print "testing if song score is modified correctly"
		song = Song(1, "TestSong", "TestArtist", 0)
		assert 'TestSong' in song.getTitle()
		assert 1 == song.getScore()
		song.incrementScore()
		assert 2 == song.getScore()
		song.decrementScore()
		assert 1 == song.getScore()
 def load(self):
     objs = utils.load_db(self.listen_db_file)
     if objs:
         items = []
         for title, bsongs in objs:
             item = MusicListItem(title, list_type=MusicListItem.LOCAL_TYPE)
             songs = []
             for d in bsongs:
                 s = Song()
                 s.init_from_dict(d, cmp_key="sid")
                 songs.append(s)
             item.add_songs(songs)
             items.append(item)
         self.category_list.add_items(items, insert_pos=1)
Esempio n. 54
0
 def parser_song(self, douban_song):    
     for douban_tag , tag in TAGS_DOUBAN_KEYS.iteritems():
         if douban_song.has_key(douban_tag):
             douban_song[tag] = douban_song[douban_tag]
             del douban_song[douban_tag]
     for key, value in douban_song.iteritems():        
         if key == "album_url":
             douban_song[key] = urlparse.urljoin("http://music.douban.com", value)
         if key in "album title company".split():    
             douban_song[key] = value.encode("utf-8", "ignore")
     song = Song()        
     song.init_from_dict(douban_song)
     song.set_type("douban")
     return song     
Esempio n. 55
0
def search(query):
	escaped_query = urllib.quote(query)
	search_string = "https://api.spotify.com/v1/search?q=%s&type=track&market=us" % (escaped_query)
	r = requests.get(search_string)
	first_result = r.json()['tracks']['items'][0]
	title = first_result['name']
	artist = first_result['artists'][0]['name']
	album = first_result['album']['name']
	id = first_result['id']
	url = first_result['external_urls']['spotify']
	s = Song(title,artist,album)
	s.add_spotify_id(id)
	s.add_spotify_url(url)
	return s
Esempio n. 56
0
def listen():
	# Plays a song generated by the master vector
	print
	print "---Listening---"
	print
	queryUser()
	master = Vector("master")
	s = Song(root,mode,title)
	for i in range(num_measures):
		s.addMeasure(master)
	s.playSong()
	print
	print "This is the best song I know how to play!\n"	
	raw_input("Press any key to return to the main menu: ")	
Esempio n. 57
0
def listen():
	print
	print "---Listening---"
	print
	queryUser()
	master = Vector("master")
	s = Song(root,mode,title)

	# Build and play a song based on the master vector
	for i in range(num_measures):
		s.addMeasure(master)
	print
	print "This is the best song I know how to play!\n"	
	s.playSong()
	raw_input("Press any key to return to the main menu: ")	
Esempio n. 58
0
 def load(self):        
     '''load songs and playlists from db file'''
     self.logdebug("Loading library...")
     
     # Load songs
     try:
         db_objs = utils.load_db(get_config_file("songs.db"))
     except:    
         self.logexception("Failed to load library")
         db_objs = []
         
     # Load playlists    
     try:    
         pls_objs = utils.load_db(get_config_file("playlists.db"))
     except:    
         self.logexception("Failed load playlists")
         pls_objs = []
         
         
     if db_objs:    
         for obj in db_objs:
             try:
                 song_type = obj["song_type"]
             except KeyError:    
                 self.logerror("Song with no type found, %s", obj.get("uri"))
                 
             if song_type not in self.__song_types:    
                 self.logwarn("Song type %s not exist, for registration", song_type)
                 self.register_type(song_type)
                 
             if self.__force_check:    
                 s = Song()
                 s.init_from_dict(obj)
                 s["uri"] = utils.realuri(s.get("uri"))
             else:    
                 s = Song(obj)
             s.set_type(song_type)    
             if not self.__force_check or not self.__songs.has_key(s.get("uri")):
                 self.add(s)
                 
     if pls_objs:            
         for pl_obj in pls_objs:            
             name, infos = pl_obj
             if self.__force_check:
                 infos = map(utils.realuri, infos)
             self.create_playlist("local", name, infos)    
     if self.__force_check:        
         self.save()
     self.__dirty = False    
     
     # fire signal
     self.__reset_queued_signal()
     gobject.timeout_add(AUTOSAVE_TIMEOUT, self.interval_async_save)
     gobject.timeout_add(SIGNAL_DB_QUERY_FIRED * 20, self.__fire_queued_signal)
     
     self.logdebug("%s songs loaded in %s types", len(self.__songs), len(self.__song_types))
     self.logdebug("Finish loading library")
     gobject.idle_add(self.__delay_post_load)
 def setUp(self):
     self.song = Song(
         'Clarity',
         "Zedd",
         'Clarity',
         456,
         64)