예제 #1
0
    def __init__(self, path, db_path="db/Katun.db", startfresh=False):
        '''Accept a path to the music directory and (optionally) the database.
          Unless otherwise specified in another document, the database should exist in the ../db folder.'''
        self.buf = [
        ]  # Establish a commit buffer, so we can read the file structure efficiently and commit once.
        self.db = DatabaseInterface(db_path)

        if startfresh or not os.path.exists(path):
            self.db.reset_database()
        self.walk(path)
예제 #2
0
    def __init__(self, path, db_path="db/Katun.db", startfresh=False):
        '''Accept a path to the music directory and (optionally) the database.
          Unless otherwise specified in another document, the database should exist in the ../db folder.'''
        self.buf = [] # Establish a commit buffer, so we can read the file structure efficiently and commit once.
        self.db = DatabaseInterface(db_path)

        if startfresh or not os.path.exists(path):
            self.db.reset_database()
        self.walk(path)
예제 #3
0
class Parser:
    '''Parse an entire directory of files in order to gain the tags.
     Per the specifications, we will only be paying attention to the following tags:
     location, artist, filetype, title, genre, track, album, bitrate, year, and month.

     Location, Artist, Filetype, and Title are keys, and must be non-empty.  We can retrieve
     the location and filetype of the song trivially; however, if artist and title do not exist, then we
     cannot parse the song.'''
    def __init__(self, path, db_path="db/Katun.db", startfresh=False):
        '''Accept a path to the music directory and (optionally) the database.
          Unless otherwise specified in another document, the database should exist in the ../db folder.'''
        self.buf = [
        ]  # Establish a commit buffer, so we can read the file structure efficiently and commit once.
        self.db = DatabaseInterface(db_path)

        if startfresh or not os.path.exists(path):
            self.db.reset_database()
        self.walk(path)

    def walk(self, d):
        '''Walk down the file structure iteratively, gathering file names to be read in.'''
        d = os.path.abspath(d)
        dirpath = os.walk(d)
        for folder in dirpath:
            for f in folder[2]:  # for each file in the folder...
                supported = 'mp3', 'ogg', 'flac'
                if f.split('.')[-1] in supported:
                    try:
                        self.parse(os.path.join(folder[0], f))
                    except Exception, e:
                        print e.__unicode__()
        try:
            self.db.execute_batch_insert_statement(
                u"INSERT INTO song VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)",
                self.buf)
        except Exception, e:
            print e.__unicode__()
예제 #4
0
class Parser:
    '''Parse an entire directory of files in order to gain the tags.
     Per the specifications, we will only be paying attention to the following tags:
     location, artist, filetype, title, genre, track, album, bitrate, year, and month.

     Location, Artist, Filetype, and Title are keys, and must be non-empty.  We can retrieve
     the location and filetype of the song trivially; however, if artist and title do not exist, then we
     cannot parse the song.'''

    def __init__(self, path, db_path="db/Katun.db", startfresh=False):
        '''Accept a path to the music directory and (optionally) the database.
          Unless otherwise specified in another document, the database should exist in the ../db folder.'''
        self.buf = [] # Establish a commit buffer, so we can read the file structure efficiently and commit once.
        self.db = DatabaseInterface(db_path)

        if startfresh or not os.path.exists(path):
            self.db.reset_database()
        self.walk(path)


    def walk(self, d):
        '''Walk down the file structure iteratively, gathering file names to be read in.'''
        d = os.path.abspath(d)
        dirpath = os.walk(d)
        for folder in dirpath:
            for f in folder[2]: # for each file in the folder...
                supported = 'mp3', 'ogg', 'flac'
                if f.split('.')[-1] in supported:
                    try:
                        self.parse(os.path.join(folder[0], f))
                    except Exception, e:
                        print e.__unicode__()
        try:
            self.db.execute_batch_insert_statement(u"INSERT INTO song VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?)", self.buf)
        except Exception, e:
            print e.__unicode__()