当前位置: 首页>>代码示例>>Python>>正文


Python Playlist.add_song方法代码示例

本文整理汇总了Python中playlist.Playlist.add_song方法的典型用法代码示例。如果您正苦于以下问题:Python Playlist.add_song方法的具体用法?Python Playlist.add_song怎么用?Python Playlist.add_song使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在playlist.Playlist的用法示例。


在下文中一共展示了Playlist.add_song方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: test_remove_song

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
 def test_remove_song(self):
      song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="1:30:44")
      code_songs = Playlist(name="Code", repeat=False, shuffle=False)
      code_songs.add_song(song)
      self.assertTrue(song in code_songs.song_list)
      code_songs.remove_song(song)
      self.assertTrue(song not in code_songs.song_list)
开发者ID:pgenev,项目名称:HackBG-Programing-101-v3,代码行数:9,代码来源:test_Songs_and_playlist.py

示例2: test_next_song_repeat_is_true

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
    def test_next_song_repeat_is_true(self):
        song = Song(title="Odin", artist="Manowar", album="The Sons of Odin", length="1:30:44")
        song2 = Song(title="Panda", artist="Grizli", album="Panda Dog", length="30:44")
        song3 = Song(title="Panda2", artist="Grizli2", album="Panda Dog2", length="44")
        song4 = Song(title="Thor", artist="Thor", album="The sons of Odin", length="44")
        code_songs = Playlist(name="Code", repeat=False, shuffle=False)
        code2_songs = Playlist(name="Code", repeat=True, shuffle=False)
        code_songs.add_song(song)
        code_songs.add_song(song2)
        code_songs.add_song(song3)
        code2_songs.add_songs(song4)
        code2_songs.add_songs(code_songs.song_list)

        result = code2_songs.next_song()
        result2 = code2_songs.next_song()
        result3 = code2_songs.next_song()
        result4 = code2_songs.next_song()
        result5 = code2_songs.next_song()
        code2_songs.next_song()
        result7 = code2_songs.next_song()
        self.assertEqual(code2_songs.list_of_songs[0], result)
        self.assertEqual(code2_songs.list_of_songs[1], result2)
        self.assertEqual(code2_songs.list_of_songs[2], result3)
        self.assertEqual(code2_songs.list_of_songs[3], result4)
        self.assertEqual(code2_songs.list_of_songs[0], result5)
        self.assertEqual(code2_songs.list_of_songs[2], result7)
开发者ID:pgenev,项目名称:HackBG-Programing-101-v3,代码行数:28,代码来源:test_Songs_and_playlist.py

示例3: test_total_length

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
    def test_total_length(self):
        playlist = Playlist("TestPlaylist")
        song1 = Song("Thunderstruck", "ACDC", "The Razors Edge", 5, 271.8, 320)
        song2 = Song("Thunderstruck", "ACDC", "The Razors Edge", 5, 200, 320)

        playlist.add_song(song1)
        playlist.add_song(song2)
        self.assertEqual(playlist.total_length(), 471.8)
开发者ID:JusttRelaxx,项目名称:HackBulgaria,代码行数:10,代码来源:playlist_tests.py

示例4: generate_playlist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
 def generate_playlist(self):
     playlist = Playlist("myPlaylist")
     files = get_files(self.path)
     for each_file in files:
         audio = MP3('music/' + str(each_file))
         song = Song(str(audio['TIT2']), str(audio['TPE1']), str(
             audio['TALB']), 5, int(audio.info.length), audio.info.bitrate)
         playlist.add_song(song)
     return playlist
开发者ID:dsspasov,项目名称:HackBulgaria,代码行数:11,代码来源:MusicCrawler.py

示例5: generate_playlist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
 def generate_playlist(self):
     result = Playlist("Rock'n'roll")
     music_files = [f for f in os.listdir(self.path) if f.endswith('.mp3') or f.endswith('.MP3')]
     for song in music_files:
         audio = MP3(self.path + "/" + song)
         print(audio)
         my_new_song = Song(audio["TIT2"], audio["TPE1"], audio["TALB"], 0, int(audio.info.length), audio.info.bitrate)
         result.add_song(my_new_song)
     return result
开发者ID:AlexanderTankov,项目名称:HackBulgaria-Programming-101,代码行数:11,代码来源:music_crawler.py

示例6: test_save

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
    def test_save(self):
        playlist = Playlist("TestPlaylist")
        song1 = Song("Thunderstruck", "ACDC", "The Razors Edge", 5, 271.8, 320)
        song2 = Song("Thunderstruck", "ACDC", "The Razors Edge", 5, 200, 320)

        playlist.add_song(song1)
        playlist.add_song(song2)

        self.playlist.save("json.txt")
开发者ID:JusttRelaxx,项目名称:HackBulgaria,代码行数:11,代码来源:playlist_tests.py

示例7: 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
开发者ID:kazuohirai,项目名称:HackBulgaria,代码行数:11,代码来源:musicCrawler.py

示例8: test_total_length

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
 def test_total_length(self):
      song = Song(title="Loki", artist="Manowar", album="The Sons of Odin", length="1:30:44")
      song2 = Song(title="Panda", artist="Grizli", album="Panda Dog", length="30:44")
      song3 = Song(title="Panda2", artist="Grizli2", album="Panda Dog2", length="44")
      code_songs = Playlist(name="Code", repeat=False, shuffle=False)
      code_songs.add_song(song)
      code_songs.add_song(song2)
      code_songs.add_song(song3)
      length_str = code_songs.total_length()
      self.assertEqual(code_songs.total_length(), length_str)
开发者ID:pgenev,项目名称:HackBG-Programing-101-v3,代码行数:12,代码来源:test_Songs_and_playlist.py

示例9: PlaylistTest

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
class PlaylistTest(unittest.TestCase):

    def setUp(self):
        self.song1 = Song("Title1", "Artist1", "Album1", 2, 192, 128)
        self.song2 = Song("Title2", "Artist2", "Album2", 2, 183, 1024)
        self.playlist = Playlist("PlaylistTitle")
        self.playlist.songs.append(self.song1)
        self.playlist.songs.append(self.song2)

    def test_init(self):
        self.assertEqual(self.playlist.name, "PlaylistTitle")
        self.assertEqual(self.playlist.songs, [self.song1, self.song2])

    def test_add_song(self):
        self.song3 = Song("Title3", "Artist3", "Album3", 2, 201, 128)
        self.playlist.add_song(self.song3)
        self.assertEqual(
            self.playlist.songs, [self.song1, self.song2, self.song3])

    def test_remove_song(self):
        self.song3 = Song("Title3", "Artist3", "Album3", 4, 194, 1024)
        self.playlist.add_song(self.song3)
        self.playlist.remove_song("Title3")
        self.assertEqual(self.playlist.songs, [self.song1, self.song2])

    def test_total_length(self):
        self.assertEqual(self.playlist.total_length(), 375)

    def test_remove_disrated(self):
        self.song3 = Song("Title3", "Artist3", "Album3", 4, 206, 1024)
        self.playlist.add_song(self.song3)
        self.playlist.remove_disrated(3)
        self.assertEqual(self.playlist.songs, [self.song3])

    def test_remove_bad_quality(self):
        self.song3 = Song("Title3", "Artist3", "Album3", 4, 206, 1024)
        self.playlist.add_song(self.song3)
        self.playlist.remove_bad_quality(1000)
        self.assertEqual(self.playlist.songs, [self.song2, self.song3])

    def test_show_artists(self):
        self.song3 = Song("Title3", "Artist2", "Album3", 4, 206, 1024)
        self.playlist.add_song(self.song3)
        self.assertEqual(self.playlist.show_artists(), ["Artist1", "Artist2"])

    # def test_str(self):
    #     test = self.playlist.str()
    #     self.assertEqual(
    #         "Artist1 Title1 - 3:12\nArtist2 Title2 - 3:03\n", test)

    def test_save(self):
        self.playlist.save("pesho.txt")

    def test_load(self):
        self.playlist.load("pesho.txt")
开发者ID:kal0ian,项目名称:HackBulgaria,代码行数:57,代码来源:playlist-test.py

示例10: test_addsong

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
 def test_addsong(self):
     song1 = Song("Punta", "Upsurt", "Pop Folk", 5, 3.45, 192)
     #song2 = Song("Still waiting", "Sum 41", "Qkoruda", 5, 3.20, 200)
     playlist1 = Playlist()
     playlist1.add_song(song1)
     self.assertTrue(playlist1.playlist[0].title, "Punta")
     self.assertTrue(playlist1.playlist[0].artist, "Uspurt")
     self.assertTrue(playlist1.playlist[0].album, "Pop Folk")
     self.assertTrue(playlist1.playlist[0].rating, 1)
     self.assertTrue(playlist1.playlist[0].length, 3.45)
     self.assertTrue(playlist1.playlist[0].bitrate, 192)
开发者ID:Hristiyan-Andreev,项目名称:HackBuglaria,代码行数:13,代码来源:playlistTest.py

示例11: generate_playlist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
 def generate_playlist(self, filepath):
     os.chdir(filepath)
     songs = glob.glob('*.mp3')
     playlist = Playlist("new")
     for song in songs:
         audio = MP3(song)
         song_to_add = Song(audio["TIT2"].text, audio["TPE1"].text,
         audio["TALB"].text, 0, round(audio.info.length),
         audio.info.bitrate // 1000)
         playlist.add_song(song_to_add)
     self.songs = playlist
开发者ID:Legena,项目名称:HackBulgaria,代码行数:13,代码来源:music_crawler.py

示例12: TestPlaylist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
class TestPlaylist(unittest.TestCase):
    def setUp(self):
        self.plist = Playlist("plist out")
        self.ruby = Song(
            "Ruby",
            "Kaiser Chiefs",
            "Unknown",
            1,
            300,
            320

        )
        self.rubyDNB = Song(
            "Ruby DNB",
            "Kaiser Chiefs",
            "Unknown",
            4,
            300,
            120

        )
        self.plist.add_song(self.ruby)
        self.plist.add_song(self.ruby)
        self.plist.add_song(self.rubyDNB)

    def test_init(self):
        self.assertEqual(self.plist.name, "plist out")

    def test_add_song(self):
        self.assertIn(self.ruby, self.plist.songs)

    def test_remove_song(self):
        self.plist.remove_song("Ruby")
        self.assertNotIn(self.ruby, self.plist.songs)

    def test_total_length(self):
        self.assertEqual(self.plist.total_length(), 900)

    def test_rating_out_of_range(self):
        for item in self.plist.songs:
            self.assertIn(item.rating, [1, 2, 3, 4, 5])

    def test_remove_disrated(self):
        self.plist.remove_disrated(3)
        self.assertIn(self.rubyDNB, self.plist.songs)
        self.assertNotIn(self.ruby, self.plist.songs)

    def test_remove_bad_quality(self):
        self.plist.remove_bad_quality()
        self.assertNotIn(self.rubyDNB, self.plist.songs)

    def test_show_artists(self):
        self.assertEqual(self.plist.show_artists(), ["Kaiser Chiefs"])
开发者ID:stanislavBozhanov,项目名称:HackBulgaria,代码行数:55,代码来源:playlist_test.py

示例13: generate_playlist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
 def generate_playlist(self):
     playlist = Playlist("newList")
     os.chdir(self.path)
     for songa in glob.glob("*.mp3"):
         song = MP3(songa, ID3=EasyID3)
         try:
             playlist.add_song(Song(song.tags["title"][0], song.tags["artist"][0], "", 0, song.info.length, song.info.bitrate))
         except TypeError:
             pass
         except KeyError:
             pass
     print (playlist)
开发者ID:svetlio2,项目名称:hackbg,代码行数:14,代码来源:MusicCrawler.py

示例14: test_prepare_to_json

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
 def test_prepare_to_json(self):
     song = Song(title="Numb", artist="Linkin Park", album="Meteora", length="3:06")
     song2 = Song(title="Leave Out All the Rest", artist="Linkin Park", album=" Minutes to Midnight", length="3:24")
     song3 = Song(title="Californication", artist="Red Hot Chili Peppers", album="Californication", length="5:21")
     song4 = Song(title="It's My Life", artist="Bon Jovi", album="Crush", length="4:27")
     code_songs = Playlist(name="Code", repeat=False, shuffle=False)
     code2_songs = Playlist(name="Best Songs Ever", repeat=False, shuffle=False)
     code_songs.add_song(song)
     code_songs.add_song(song2)
     code_songs.add_song(song3)
     code2_songs.add_songs(song4)
     code2_songs.add_songs(code_songs.song_list)
     result = code2_songs.prepare_to_json()
     self.assertEqual(code2_songs.prepare_to_json(), result)
开发者ID:pgenev,项目名称:HackBG-Programing-101-v3,代码行数:16,代码来源:test_Songs_and_playlist.py

示例15: TestPlaylist

# 需要导入模块: from playlist import Playlist [as 别名]
# 或者: from playlist.Playlist import add_song [as 别名]
class TestPlaylist(unittest.TestCase):

    def setUp(self):

        self.song1 = Song("Title1", "Artist","Album", 5.0, 4, 320)
        self.song2 = Song("Title2", "Artist","Album", 2.0, 2, 320)
        self.song3 = Song("Title3", "Artist2","Album", 5.0, 4, 128)
        self.my_playlist = Playlist("Playlist")
        self.my_playlist.songs.append(self.song1)
        self.my_playlist.songs.append(self.song2)
        self.my_playlist.songs.append(self.song3)

    def test_init(self):

        self.assertEqual(self.my_playlist.songs, [self.song1, self.song2, self.song3])
        self.assertEqual(self.my_playlist.name, "Playlist")

    def test_add_song(self):

        self.song4 = Song("Title", "Artist","Album", 5.0, 4.22, 320)
        self.my_playlist.add_song(self.song4)
        self.assertEqual(self.my_playlist.songs, [self.song1, self.song2, self.song3, self.song4])

    def test_remove_song(self):

        self.my_playlist.remove_song("Title2")
        self.assertEqual(self.my_playlist.songs, [self.song1, self.song3])

    def test_total_lenght(self):

        self.assertEqual(self.my_playlist.total_lenght(), 10)

    def test_remove_disrated(self):

        self.my_playlist.remove_disrated(3)
        self.assertEqual(self.my_playlist.songs, [self.song1, self.song3])

    def test_remove_bad_quality(self):

        self.my_playlist.remove_bad_quality(320)
        self.assertEqual(self.my_playlist.songs, [self.song1, self.song2])

    def test_show_artists(self):

        self.assertEqual(self.my_playlist.show_artits(), ["Artist", "Artist2"])

    def test_str(self):

        print(self.my_playlist.str()) 
开发者ID:skdls-,项目名称:Python,代码行数:51,代码来源:test_playlist.py


注:本文中的playlist.Playlist.add_song方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。