コード例 #1
0
ファイル: music_datastore.py プロジェクト: DrewWeth/Etsy_Proj
 def list_tracks(self, track_values):
     if track_values[2] not in self.artists:
         raise InputError('Artist not found. Please add artist')
     artist = self.artists[track_values[2]]  # Find instance of artist
     if track_values[1] not in artist.albums:
         raise InputError("Album does not exist")
     album = artist.albums[track_values[1]]
     for idx, track in enumerate(album.tracks):
         print(idx + 1, track)
コード例 #2
0
ファイル: music_datastore.py プロジェクト: DrewWeth/Etsy_Proj
 def locate_track(self, track_values):
     if track_values[2] not in self.artists:
         raise InputError('Artist not found. Check spelling or add artist')
     artist = self.artists[track_values[2]]  # Find instance of artist
     if track_values[1] not in artist.albums:
         raise InputError("Album does not exist. Check spelling.")
     album = artist.albums[track_values[1]]
     if track_values[0] not in album.tracks:
         raise InputError("Track does not exist. Check spelling.")
     return album.tracks[track_values[0]]
コード例 #3
0
ファイル: extractor.py プロジェクト: DrewWeth/Etsy_Proj
def get_album_info(raw_commands, subcommand_index):
    album_name, count = next_input(raw_commands, subcommand_index)
    if count < 0:
        raise InputError("Need more info. Please include album name")
    by_index = subcommand_index + count
    artist_name, count = next_input(raw_commands, by_index + 1)
    if count < 0:
        raise InputError(
            "Need more info. Please include 'by' and the 'artists name' after the album name"
        )
    return [album_name, artist_name]
コード例 #4
0
ファイル: main.py プロジェクト: DrewWeth/Etsy_Proj
def decipher_command(line):
    raw_commands = line.split(" ") # Main data structure used to interpret user data.
    if len(raw_commands) < 1:
        raise InputError('Incorrect usage. Need more info. Type help for examples.')

    # Process main commands
    primary_commands = ['add', 'list', 'listen']
    if sanitize_command(raw_commands, primary_commands, 0) == True:
        funcdict[raw_commands[0]](raw_commands)
    else:
        raise InputError("First argument is invalid. Use one of these", primary_commands)
コード例 #5
0
ファイル: music_datastore.py プロジェクト: DrewWeth/Etsy_Proj
 def add_track(self, track_name, album_name, artist_name):
     if artist_name not in self.artists:
         raise InputError('Artist not found. Please add artist')
     artist = self.artists[artist_name]
     new_track = track.Track(track_name, album_name, artist_name)
     self.tracks.append(new_track)
     if album_name not in artist.albums:
         raise InputError('Album not found. Please add album.')
     album = artist.albums[album_name]
     album.tracks[track_name] = new_track  # Connection from album to track
     new_track.album = album  # Connection from track to album
     new_track.artist = artist  # Connection from track to artist. Maybe unecessary
     return new_track
コード例 #6
0
ファイル: extractor.py プロジェクト: DrewWeth/Etsy_Proj
def get_track_info(raw_commands, subcommand_index):
    track_name, count = next_input(raw_commands, subcommand_index)
    if count < 0:
        raise InputError("Need more info. Please include track name")
    on_index = subcommand_index + count
    album_name, count = next_input(raw_commands, on_index + 1)
    if count < 0:
        raise InputError(
            "Need more info. Please include 'on' and 'album name' after the track name"
        )
    by_index = on_index + count + 1
    artist_name, count = next_input(raw_commands, by_index + 1)
    if count < 0:
        raise InputError(
            "Need more info. Please include 'by' and 'artist name' after the album name"
        )
    return [track_name, album_name, artist_name]
コード例 #7
0
ファイル: music_datastore.py プロジェクト: DrewWeth/Etsy_Proj
 def add_album(self, album_name, artist_name):
     if artist_name not in self.artists:
         raise InputError('Artist not found. Please add artist')
     artist = self.artists[artist_name]  # Find instance of artist
     new_album = album.Album(album_name)
     self.albums.append(new_album)
     new_album.artist = artist  # Album to artist connection
     artist.albums[album_name] = new_album  # Artist to album connection
     return new_album
コード例 #8
0
ファイル: main.py プロジェクト: DrewWeth/Etsy_Proj
def command_list(raw_commands):
    valid_commands = ['top', 'albums', 'tracks', 'artists']
    if sanitize_command(raw_commands, valid_commands, 1) == False:
        raise InputError("Sub argument is invalid. Use valid arguments: ", valid_commands, "after list")

    if raw_commands[1] == 'top':
        value, count = next_input(raw_commands, 2)
        if count < 0:
            raise InputError("Please enter how many to print. To print all value input 'q'")
        if not value.isdigit() and value != 'q':
            raise InputError("Sub argument is invalid. Use a number or letter 'q'")
        if value == 'q':
            desired_count = -1
        else:
            desired_count = int(value)

        valid_commands = ['artists','tracks', 'albums']
        if sanitize_command(raw_commands, valid_commands, 3) == False:
            raise InputError("Sub argument is invalid. Use valid commands: ", valid_commands)
        desired_category = raw_commands[3]

        if desired_category == 'artists':
            get_music_datastore().list_top_artists(desired_count)
        elif desired_category == 'tracks':
            get_music_datastore().list_top_tracks(desired_count)
        elif desired_category == 'albums':
            get_music_datastore().list_top_albums(desired_count)
        else:
            print("ERR: command_list top")
    else:
        valid_commands = ['albums', 'tracks', 'artists']
        if sanitize_command(raw_commands, valid_commands, 1) == False:
            raise InputError("Sub argument (", raw_commands[1], ") is invalid. Use valid argument: ", valid_commands)
        desired_category = raw_commands[1]
        if desired_category == 'albums':
            result = get_album_info(raw_commands, 1)
            get_music_datastore().list_albums(result)
        elif desired_category == 'tracks':
            result = get_track_info(raw_commands, 1)
            get_music_datastore().list_tracks(result)
        elif desired_category == 'artists':
            get_music_datastore().list_artists()
        else:
            print("ERR: command_list normal", raw_commands)
コード例 #9
0
ファイル: main.py プロジェクト: DrewWeth/Etsy_Proj
def command_add(raw_commands):
    valid_commands = ['artist', 'album', 'track']
    if sanitize_command(raw_commands, valid_commands, 1) == False:
        raise InputError("Sub command is invalid. Use valid arguments: ", valid_commands, "after add")
        return
    subcommand_index = 2
    if raw_commands[1] == 'artist': # check to lower
        artist_name, count = get_artist_info(raw_commands, subcommand_index)
        get_music_datastore().add_artist(artist_name)
    elif raw_commands[1] == 'album':
        album_name, artist_name = get_album_info(raw_commands, subcommand_index)
        get_music_datastore().add_album(album_name, artist_name)
    elif raw_commands[1] == 'track':
        track_name, album_name, artist_name = get_track_info(raw_commands, subcommand_index)
        get_music_datastore().add_track(track_name, album_name, artist_name)
    else:
        print("ERR: command_add")
コード例 #10
0
ファイル: extractor.py プロジェクト: DrewWeth/Etsy_Proj
def get_artist_info(raw_commands, subcommand_index):
    artist_name, count = next_input(raw_commands, subcommand_index)
    if count < 0:
        raise InputError("Need more info. Please include artist name")
    return artist_name, count
コード例 #11
0
ファイル: music_datastore.py プロジェクト: DrewWeth/Etsy_Proj
 def list_albums(self, album_values):
     if album_values[1] not in self.artists:
         raise InputError('Artist not found. Please add artist')
     artist = self.artists[album_values[1]]  # Find instance of artist
     for idx, album in enumerate(artist.albums):
         print(idx + 1, album)
コード例 #12
0
ファイル: main.py プロジェクト: DrewWeth/Etsy_Proj
def command_listen(raw_commands):
    if len(raw_commands) < 4:
        raise InputError("Command usage: listen to \"song\" on \"album\" by \"artist\"")
    track_values = get_track_info(raw_commands, 2)
    get_music_datastore().listen_to(track_values)