Ejemplo n.º 1
0
    def get_playlist_information(self, playlist_id, ordered_by, ascending):
        cursor = self.con.cursor()
        query = '''SELECT playlistName, playlistDescription FROM Playlist WHERE playlistID = ?'''
        cursor.execute(query, (playlist_id, ))
        self.con.commit()

        playlist_info = cursor.fetchall()
        playlist = Playlist(*playlist_info[0])

        query = '''SELECT PlaylistContainsSong.songURL, albumTitle, Song.bandName, featured_artist, songName, songRelease, songLyrics, songLength, songGenre
                    FROM PlaylistContainsSong
                    INNER JOIN Song ON Song.songURL = PlaylistContainsSong.songURL
                    INNER JOIN Album ON Album.albumID = Song.albumID
                    INNER JOIN SongGenres ON SongGenres.songURL = Song.songURL
                    WHERE playlistID = ?
                    ORDER BY ''' + ordered_by + ''' ''' + ascending

        cursor.execute(query, (playlist_id, ))
        old_songs_list = cursor.fetchall()

        for item in old_songs_list:
            song = Song(*item)
            playlist.add_song(song)

        return playlist
Ejemplo n.º 2
0
 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
Ejemplo n.º 3
0
 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
Ejemplo n.º 4
0
 def generate_playlist(self):
     code_songs = Playlist(name="Code", repeat=True, shuffle=False)
     for music_file in self.files_in_dir:
         audio = MP3(self.path + music_file, ID3=EasyID3)
         artist = audio['artist'][0]
         title = audio['title'][0]
         album = audio['album'][0]
         length = str(datetime.timedelta(seconds=int(audio.info.length)))
         new_song = Song(
             title=title, artist=artist, album=album, length=length)
         new_song.path = self.path + music_file
         code_songs.add_song(new_song)
     return code_songs
class Playlisttest(unittest.TestCase):

    def setUp(self):
        self.playlist = Playlist("random")
        song1 = Song(
            "We Are!", "Hiroshi Kitadani", "One Piece OST", 5, 240, 512)
        song2 = Song(
            "We Are!", "Hiroshi Kitadani", "One Piece OST", 5, 240, 512)
        self.playlist.add_song(song1)
        self.playlist.add_song(song2)

    def test_save(self):
        #self.playlist.save("jason.txt")
        print(self.playlist.__dict__)
Ejemplo n.º 6
0
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)
Ejemplo n.º 7
0
class MusicPlayer:
    def __init__(self):
        self.process = Popen(["mpg123", ''], stdout=PIPE, stderr=PIPE)
        self.main_playlist = Playlist(name="Code", repeat=True, shuffle=True)

    def __play(self, mp3Path):
        process = Popen(["mpg123", mp3Path], stdout=PIPE, stderr=PIPE)
        return process

    def __stop(self):
        self.process.kill()

    def add_songs_from_dir(self, another_dir):
        crawler = MusicCrawler(another_dir)
        another_playlist = crawler.generate_playlist()
        for song in another_playlist.playlist:
            self.main_playlist.add_song(song)
        self.main_playlist.songs_to_be_played = [
            x for x in range(len(self.main_playlist.playlist))
        ]

    def change_shuffle_mode(self, shuffle):
        self.main_playlist.change_shuffle_mode(shuffle)

    def change_repeat_mode(self, repeat):
        self.main_playlist.change_repeat_mode(repeat)

    def play_next_song(self):
        current_song = self.main_playlist.next_song()
        self.process = self.__play(current_song.path)
        print('Now playing: ' + str(current_song))

    def stop_playing_all(self):
        self.__stop()

    def show_playlist(self):
        self.main_playlist.pprint_playlist()
Ejemplo n.º 8
0
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))
Ejemplo n.º 9
0
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])
Ejemplo n.º 10
0
  6: Shuffle playlist
  =====================================

  ''')

    # Prints welcome message and options menu
    user_selection = int(input('Enter one of the 5 options:  '))

    # Option 1: View playlist
    if user_selection == 1:
        playlist.print_songs()

    # Option 2: To add a new song to playlist
    elif user_selection == 2:
        song_title = input('What song do you want to add? ')
        playlist.add_song(song_title)

    # Option 3: To remove a song from playlist
    elif user_selection == 3:
        song_title = input('What song do you want to remove? ')
        playlist.remove_song(song_title)

    # Option 4: To search for song in playlist
    elif user_selection == 4:

        song_title = input('Which song do you want to find? ')
        index = playlist.find_song(song_title)

        if index == -1:
            print(f"The song {song_title} is not in the set list.")
        else:
Ejemplo n.º 11
0
class Test_Playlist(unittest.TestCase):
    def setUp(self):
        self.code_songs = Playlist(name="Code", repeat=True, shuffle=True)
        self.song = Song(title="Odin",
                         artist="Manowar",
                         album="The Sons of Odin",
                         length="3:44")
        self.code_songs.add_song(self.song)

    def test_init(self):
        self.assertEqual(self.code_songs.name, "Code")
        self.assertEqual(self.code_songs.repeat, True)
        self.assertEqual(self.code_songs.shuffle, True)

    def test_add_song(self):
        self.assertTrue(self.song in self.code_songs.playlist)

    def test_remove_song(self):
        self.code_songs.remove_song(self.song)
        self.assertFalse(self.song in self.code_songs.playlist)

    def test_add_songs(self):
        song1 = Song(title="Odin1",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        song2 = Song(title="Odin2",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        song3 = Song(title="Odin3",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        songs = [song1, song2, song3]
        self.code_songs.add_songs(songs)
        self.assertTrue(song1 in self.code_songs.playlist)
        self.assertTrue(song2 in self.code_songs.playlist)
        self.assertTrue(song3 in self.code_songs.playlist)

    def test_total_length(self):
        song1 = Song(title="Odin1",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        song2 = Song(title="Odin2",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        songs = [song1, song2]
        self.code_songs.add_songs(songs)

        self.assertEqual(self.code_songs.total_length(), '00:11:12')

    def test_artists(self):

        # Adding songs
        song1 = Song(title="Odin1",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        song2 = Song(title="Odin2",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        songs = [song1, song2]
        self.code_songs.add_songs(songs)

        # Testing Print here:
        # out = StringIO()
        # self.code_songs.get_artists()
        # sys.stdout = out
        # output = out.getvalue()

        self.assertTrue(self.code_songs.get_artists(), 'Manowar -> 2')

    def test_next_song(self):
        song1 = Song(title="Odin1",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        song2 = Song(title="Odin2",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:44")
        songs = [song1, song2]
        self.code_songs.add_songs(songs)
        self.assertIsInstance(self.code_songs.next_song(), Song)

        # I don't know how to test random :( :D
        # and that's why I make a new playlist
        not_shuffled_playlist = Playlist(name="Code1",
                                         repeat=True,
                                         shuffle=False)
        not_shuffled_playlist.add_songs(songs)
        self.assertEqual(not_shuffled_playlist.next_song(), song1)
        self.assertEqual(not_shuffled_playlist.next_song(), song2)
        self.assertEqual(not_shuffled_playlist.next_song(), song1)

    def test_pprint(self):
        song1 = Song(title="Oleeeee",
                     artist="Uhuuuuuuuu",
                     album="The Sons of Odin",
                     length="3:10")
        song2 = Song(title="Odin2",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:24")
        songs = [song1, song2]
        self.code_songs.add_songs(songs)
        print()
        self.assertEqual(
            '''| Artist     || Song    || Length |
|------------||---------||--------|
| Manowar    || Odin    || 3:44   |
| Uhuuuuuuuu || Oleeeee || 3:10   |
| Manowar    || Odin2   || 3:24   |
''', self.code_songs.pprint_playlist())

    def test_save(self):
        song1 = Song(title="Oleeeee",
                     artist="Uhuuuuuuuu",
                     album="The Sons of Odin",
                     length="3:10")
        song2 = Song(title="Odin2",
                     artist="Manowar",
                     album="The Sons of Odin",
                     length="3:24")
        songs = [song1, song2]
        self.code_songs.add_songs(songs)
        self.code_songs.save()
        with open('./playlist-data/Code.json', "r") as f:
            contents = f.read()
            print(contents)
Ejemplo n.º 12
0
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')
Ejemplo n.º 13
0
            print("Add song (as)")
            print("Remove song (rs)")
            print("Change name (cn)")

            userChoice = input()

    elif userChoice == "rp":
        print("Choose playlist to remove")
        playlist_to_remove = input("")

        user_playlist.remove(playlist_to_remove)

    elif userChoice == "rs":
        pass
    elif userChoice == "sf":
        try:
            os.chdir("songs")

            # iterate through the folder
            for song in os.listdir():
                # if it is an mp3 file
                if song.endswith(".mp3"):
                    user_library.add_song(Song(get_song_metadata(song)[0], get_song_metadata(song)[1], get_song_metadata(song)[2], get_song_metadata(song)[3], get_song_metadata(song)[4], get_song_metadata(song)[5]))
        except:
            print("Unaviable to open folder")
            print("Please restart program")
    elif userChoice == "q":
        break
    else:
        print("Invalid Input")