本文整理匯總了Python中Playlist.Playlist.add_song方法的典型用法代碼示例。如果您正苦於以下問題:Python Playlist.add_song方法的具體用法?Python Playlist.add_song怎麽用?Python Playlist.add_song使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類Playlist.Playlist
的用法示例。
在下文中一共展示了Playlist.add_song方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。
示例1: generate_playlist
# 需要導入模塊: from Playlist import Playlist [as 別名]
# 或者: from Playlist.Playlist import add_song [as 別名]
def generate_playlist(self):
returnPl = Playlist()
for file in os.listdir(self._dirpath):
if file.endswith(".mp3"):
song = MP3(file, ID3=EasyID3)
#print(song["title"][0].decode("utf-8"))
returnPl.add_song(Song(song["title"][0], song["artist"][0], song["album"][0], str(datetime.timedelta(seconds=int(song.info.length)))))
return returnPl
示例2: generate_playlist
# 需要導入模塊: from Playlist import Playlist [as 別名]
# 或者: from Playlist.Playlist import add_song [as 別名]
def generate_playlist(self, name):
output_playlist = Playlist(name)
files = self._get_mp3_files(self.__crawlDir)
for filename in files:
filename = self.__crawlDir + filename
audio_obj = MP3(filename)
song = self._create_song(audio_obj)
output_playlist.add_song(song)
return output_playlist
示例3: TestPlayList
# 需要導入模塊: from Playlist import Playlist [as 別名]
# 或者: from Playlist.Playlist import add_song [as 別名]
class TestPlayList(unittest.TestCase):
def setUp(self):
self.song1 = Song("a", "b", "ab", "2:00")
self.song2 = Song("aa", "b", "ab", "3:00")
self.song3 = Song("aa", "bb", "aabb", "2:00")
self.pl = Playlist("Mine")
def test_equal_song(self):
self.assertNotEqual(self.song1, self.song2)
def test_add_song(self):
self.pl.add_song(self.song1)
self.assertEqual(len(self.pl.songs), 1)
#self.assertEqual(self.pl.add_song(self.song2), "Fail !")
self.assertEqual(self.song1._length,self.song3._length)
示例4: Test_playlist
# 需要導入模塊: from Playlist import Playlist [as 別名]
# 或者: from Playlist.Playlist import add_song [as 別名]
class Test_playlist(unittest.TestCase):
def setUp(self):
self.testplaylist = Playlist("Test Playlist")
self.song = Song("Title", "Artist", "Album", 5, 20, 120)
self.song1 = Song("Title1", "Artist", "Album1", 1, 20, 50)
self.song2 = Song("Title2", "Artist1", "Album1", 1, 20, 100)
self.testplaylist.add_song(self.song)
self.testplaylist.add_song(self.song1)
self.testplaylist.add_song(self.song2)
def test_playlist_init(self):
self.assertEqual(self.testplaylist.name, "Test Playlist")
def test_playlist(self):
self.assertEqual(self.testplaylist.songs[0], self.song)
def test_remove_song(self):
self.testplaylist.remove_song("Title1")
self.assertEqual(self.testplaylist.songs[0], self.song)
self.assertEqual(self.testplaylist.songs[1], self.song2)
def test_total_length(self):
self.assertEqual(self.testplaylist.total_length(), 60)
def test_remove_disrated(self):
self.testplaylist.remove_disrated(4)
self.assertEqual(self.testplaylist.songs[0], self.song)
def test_remove_bad_quality(self):
self.testplaylist.remove_bad_quality()
self.assertEqual(self.testplaylist.songs[0], self.song)
self.assertEqual(self.testplaylist.songs[1], self.song2)
def test_show_artists(self):
artists = ["Artist", "Artist1"]
self.assertSetEqual(self.testplaylist.show_artists(), set(artists))
示例5: PlaylistTest
# 需要導入模塊: from Playlist import Playlist [as 別名]
# 或者: from Playlist.Playlist import add_song [as 別名]
class PlaylistTest(unittest.TestCase):
def setUp(self):
self.playlist = Playlist("MyPlaylist")
self.song1 = Song("TestTitle", "TestArtist",
"TestAlbum", 3, 200, 128, "")
self.playlist.add_song(self.song1)
def test_init(self):
self.assertEqual(self.playlist.name, "MyPlaylist")
def test_get_all_songs(self):
self.assertEqual(self.playlist.get_all_songs(), [self.song1])
def test_get_first_song(self):
self.assertEqual(self.playlist.get_first_song(), self.song1)
def test_add_song(self):
self.song2 = Song("It's My Life", "Bon Jovi",
"Unknown Album", 5, 200, 192, "")
self.playlist.add_song(self.song2)
self.assertEqual(
[self.song1, self.song2], self.playlist.get_all_songs())
def test_remove_song(self):
with mock.patch('builtins.input', return_value=1):
self.assertEqual(
self.playlist.get_first_song().title, 'TestTitle')
def test_rate_songs(self):
with mock.patch('builtins.input', return_value=3):
self.assertEqual(
self.playlist.get_first_song().rating, 3)
def test_remove_disrated(self):
with mock.patch('builtins.input', return_value=4):
self.assertEqual(self.playlist.get_all_songs(), [self.song1])
示例6: jdefaultplaylist
# 需要導入模塊: from Playlist import Playlist [as 別名]
# 或者: from Playlist.Playlist import add_song [as 別名]
import json
from Playlist import Playlist
from Song import Song
def jdefaultplaylist(o):
if isinstance(o, Playlist):
return str(o.str())
return o.__dict__
def jdefaultsong(o):
if isinstance(o, Song):
return str(o.str())
return o.__dict__
new = Playlist("Test Playlist")
song = Song("Title", "Artist", "Album", 5, 20, 120)
song1 = Song("Title1", "Artist1", "Album", 5, 25, 120)
song2 = Song("Title2", "Artist2", "Album", 5, 40, 120)
new.add_song(song)
new.add_song(song1)
new.add_song(song2)
with open('playlist.json', mode='w', encoding='utf-8') as f:
for each in new.songs:
json.dump(each, f, default=jdefaultsong)
f.write('\n')