コード例 #1
0
ファイル: splitflac.py プロジェクト: jacron/music_a
def split_flac(cuepath, album_id):
    cuesheet = get_full_cuesheet(cuepath, 0)
    basedir = os.path.dirname(cuepath)
    nr = get_max_nr(basedir)
    nr = incr_nr(nr)

    ColorPrint.print_c(basedir, ColorPrint.GREEN)
    for cfile in cuesheet['cue']['files']:
        filepath = os.path.join(basedir, cfile['name'])
        file_duration = get_duration(filepath)
        if not file_duration:
            ColorPrint.print_c('unknown duration for: ' + filepath,
                               ColorPrint.RED)
            socket_log('ERR:unknown duration for: ' + filepath, 'error',
                       album_id)
            continue
        flacs = []
        tracks = cfile['tracks']
        # use index to keep track of when the last track is being processed
        for index, track in enumerate(tracks):
            strnr = tidy_nr(nr)
            flacs.append(
                get_flac(strnr, index, track, basedir, tracks, file_duration))
            nr += 1
        for flac in flacs:
            split_file(flac, filepath)
    socket_log('split finished', 'info')
    socket_log('>>> ' + filename(basedir), 'info')
    print('split finished')
コード例 #2
0
def save_cb_image(cover):
    img = ImageGrab.grabclipboard()
    if img:
        img.save(COVER_PATH.format(cover))
        openpath(TMP_PATH)
    else:
        ColorPrint.print_c('no valid image on clipboard', ColorPrint.RED)
コード例 #3
0
def main():
    # Init
    componist_id = None
    mother_id = None
    path = None
    album_id = None

    # open_finder_album(album_id=4286)
    # open_finder_componist(ComponistID)
    # return
    # path = get_path_of_componist(ComponistID)
    # album_id = 674
    # path = get_path_of_album(album_id)
    mother_id = 2194
    componist_id = 9
    # componist = from_path(path)
    # ComponistID = componist_from_album(album_id)
    path = '/Volumes/Media/Audio/Klassiek/Collecties/Wanda Landowska - The complete european recordings (1928-1940)'
    ColorPrint.print_c(path, ColorPrint.LIGHTCYAN)
    if path is None:
        print('No path')
        return
    # process_pieces(path, album_id=album_id)
    # return

    # sanatize_haakjes(path, True)
    # restore_cover(path=path, step_in=True)
    # rename_cover(path=path, step_in=True)
    # rename_titles(path)
    # rename_to_back(path)
    process_a(p=path, mother_id=None, iscollectie=1, step_in=1)
コード例 #4
0
def get_path_of_componist(componist_id):
    if componist_id is None:
        ColorPrint.print_c('No componist ID given, so quitting',
                           ColorPrint.RED)
        return
    conn, c = connect()
    return get_componist_path_c(componist_id, c)
コード例 #5
0
def rename_back_one(path, name):
    src = '{}/{}.jpg'.format(path, name)
    if os.path.exists(src):
        trg = '{}/{}'.format(path, back_nice)
        if not os.path.exists(trg):
            os.rename(src, trg)
            ColorPrint.print_c('renamed to:{}'.format(trg), ColorPrint.GREEN)
コード例 #6
0
def clipboard_save(path, file):
    img = ImageGrab.grabclipboard()
    if img:
        img.save(os.path.join(path, file))
        ColorPrint.print_c(file + ' saved!', ColorPrint.LIGHTCYAN)
    else:
        ColorPrint.print_c('No image on clipboard!', ColorPrint.RED)
コード例 #7
0
def clipboard_save_path(path):
    img = ImageGrab.grabclipboard()
    if img:
        img.save(path)
        ColorPrint.print_c(path + ' saved!', ColorPrint.LIGHTCYAN)
    else:
        ColorPrint.print_c('No image on clipboard!', ColorPrint.RED)
コード例 #8
0
ファイル: splitflac.py プロジェクト: jacron/music_a
def get_flac(strnr, index, track, basedir, tracks, file_duration):
    # track_title = track['title'].replace('/', '_')
    try:
        fname = '{} {}.flac'.format(strnr, track['title'])
    except ValueError as v:
        ColorPrint.print_c(str(v) + ',' + track['title'], ColorPrint.RED)
        return None
    except KeyError as k:
        ColorPrint.print_c(str(k), ColorPrint.RED)
        return None
    fname = fname.replace('/', '_')
    outfile = os.path.join(basedir, fname)
    time = track['index']['time']
    if index < len(tracks) - 1:
        time2 = tracks[index + 1]['index']['time']
        duration = timedif(time2, time)
    else:
        if file_duration:
            duration = timedif(file_duration, time)
        else:
            duration = None
    return {
        'path': outfile,
        'fname': fname,
        'time': time,
        'duration': duration,
    }
コード例 #9
0
ファイル: clipboard-save.py プロジェクト: jacron/music_a
def save_cb_image():
    img = ImageGrab.grabclipboard()
    if img:
        img.save(folderpath)
        ColorPrint.print_c('front saved!', ColorPrint.LIGHTCYAN)
        openpath(path)
    else:
        ColorPrint.print_c('No image on clipboard!', ColorPrint.RED)
コード例 #10
0
ファイル: tag.py プロジェクト: jacron/music_a
def title2tag(p, title):
    import mutagen
    song = mutagen.File(p)
    try:
        song.tags['ALBUM'] = [title]
        song.save()
    except TypeError as t:
        ColorPrint.print_c(str(t), ColorPrint.CYAN)
コード例 #11
0
def save_cb_images(cover, nback):
    img = ImageGrab.grabclipboard()
    if img:
        front = crop_front(img)
        back = crop_back(img)
        front.save(COVER_PATH.format(cover))
        back.save(COVER_PATH.format(nback))
        openpath(TMP_PATH)
    else:
        ColorPrint.print_c('no valid image on clipboard', ColorPrint.RED)
コード例 #12
0
ファイル: tag.py プロジェクト: jacron/music_a
def all2tag(p, title, album_id):
    import mutagen
    song = mutagen.File(p)
    try:
        song.tags['ALBUM'] = [title]
        song.tags['ARTIST'] = performers(album_id)
        song.tags['COMPOSER'] = composers(album_id)
        song.save()
    except TypeError as t:
        ColorPrint.print_c(str(t), ColorPrint.CYAN)
コード例 #13
0
def restore_cover_one(path, fro, to):
    src = u'{}/{}.jpg'.format(path, fro)
    # print(src)
    if os.path.exists(src):
        trg = u'{}/{}.jpg'.format(path, to)
        # print(trg)
        if os.path.exists(trg):
            os.unlink(trg)
            os.rename(src, trg)
            ColorPrint.print_c('renamed to:{}'.format(trg), ColorPrint.GREEN)
コード例 #14
0
ファイル: update.py プロジェクト: jacron/music_a
def remove_piece(album_id, piece_name):
    album = get_album(album_id)
    p = os.path.join(album['Path'], piece_name)
    try:
        os.remove(p)
    except FileNotFoundError as ex:
        ColorPrint.print_c(str(ex), ColorPrint.CYAN)
        socket_log(str(ex), 'error', album_id)
    except PermissionError as p:
        ColorPrint.print_c(str(p), ColorPrint.CYAN)
        socket_log(str(p), 'error', album_id)
コード例 #15
0
def rename_cover_one(path, name):
    if '.' not in name:
        name += '.jpg'
    src = u'{}/{}'.format(path, name)
    # print(src)
    if os.path.exists(src):
        # print(src)
        trg = u'{}/{}'.format(path, cover_nice)
        if not os.path.exists(trg):
            os.rename(src, trg)
            ColorPrint.print_c('renamed to:{}'.format(trg), ColorPrint.GREEN)
コード例 #16
0
ファイル: check.py プロジェクト: jacron/music_a
def create(path, album_title, cid):
    conn = sqlite3.connect(db_path)
    c = conn.cursor()
    album_id = insert_album(
        title=album_title,
        path=path,
        album_id=None,
        is_collectie=0,
        c=c,
        conn=conn,
    )[0]
    ColorPrint.print_c("album_id={}".format(album_id), ColorPrint.LIGHTCYAN)
    # cid = get_componist_by_lastname(componist_name, c)[0]
    insert_componist_by_id(cid, c, conn, album_id)
    insert_pieces(path, album_id, conn, c)
    conn.close()
コード例 #17
0
def update_path_person(table, c, con, item_id, item_path, first_name,
                       last_name):
    if not item_path:
        ColorPrint.print_c('no path for: ' + first_name + ' ' + last_name,
                           ColorPrint.RED)
        return
    # take string after last slash and use that for new path
    sl = item_path.rfind('/') + 1
    p = item_path[sl:]
    print(item_id, item_path)
    sql = 'UPDATE ' + table + ' SET Path=? WHERE ID=?'
    c.execute(sql, (
        p,
        item_id,
    )).fetchone()
    con.commit()
コード例 #18
0
def process_album(path,
                  componist_id=None,
                  performer_id=None,
                  mother_id=None,
                  is_collectie=0):
    """
    haal stukken (cuesheets en music files) op voor een album
    """
    # if len(path.split('[')) > 1:
    #     print('from: ' + __file__, currentframe().f_lineno)
    #     ColorPrint.print_c('cue_path mag geen accolades of vierkante haken bevatten - quitting', ColorPrint.RED)
    #     return -1
    path = decode_semi_colon(path)
    if not os.path.exists(path):
        print('from: ' + __file__, currentframe().f_lineno)
        ColorPrint.print_c('This directory does not exist - quitting',
                           ColorPrint.RED)
        return
    # if has_music_files(path):
    #     print('from: ' + __file__, currentframe().f_lineno)
    #     ColorPrint.print_c('No music files in this directory - quitting',
    #                        ColorPrint.RED)
    #     return

    conn, c = connect()
    w = path.split('/')
    album_title = w[-1].replace("_", " ")
    p = path[len(AUDIO_ROOT):]
    album_id = insert_album(
        title=album_title,
        path=p,
        is_collectie=is_collectie,
        c=c,
        conn=conn,
        album_id=mother_id,
    )[0]
    print('from: ' + __file__, currentframe().f_lineno)
    ColorPrint.print_c("created album id: {}".format(album_id),
                       ColorPrint.LIGHTCYAN)
    insert_pieces(path, album_id, conn, c)
    if componist_id:
        insert_componist_by_id(componist_id, c, conn, album_id)
    if performer_id:
        insert_performer_by_id(performer_id, c, conn, album_id)
    conn.close()
    return album_id
コード例 #19
0
def cue_full_cuesheet(data, cue_id, filename):
    try:
        lines = data.split('\n')
        cue = parse_cuesheet(lines)
    except:
        ColorPrint.print_c('*** parse cue failed (utf-8?)', ColorPrint.RED)
        return None
    discid, asin = parse_rem(cue['rem'])
    if cue['performer']:
        cue['performers'] = cue['performer'].split(',')
    return {
        'Filename': filename,
        'Title': cue.get('title'),
        'ID': cue_id,
        'cue': cue,
        'discid': discid,
        'asin': asin
    }
コード例 #20
0
def opentageditor(path):
    if os.path.exists(path):
        cmd = ['open', '-a', TAG_EDITOR]
        for f in os.listdir(path):
            extension = f.split('.')[-1]
            if extension == 'flac':
                p = '{}/{}'.format(path, f)
                cmd.append(p)

        process = subprocess.Popen(cmd,
                                   stdout=subprocess.PIPE,
                                   stderr=subprocess.PIPE)
        out, err = process.communicate()
        if len(out) == 0:
            print(err)
    else:
        ColorPrint.print_c('Path does not exist: {}'.format(path),
                           ColorPrint.RED)
コード例 #21
0
ファイル: update.py プロジェクト: jacron/music_a
def process_album(path, mother_id):
    """
    haal stukken (cuesheets en music files) op voor een album
    """
    conn, c = connect()
    w = path.split('/')
    album_title = w[-1].replace("_", " ")
    dbpath = path.replace(AUDIO_ROOT, '')

    album_id = insert_album(
        title=album_title,
        path=dbpath,
        is_collectie=0,
        c=c,
        conn=conn,
        album_id=mother_id,
    )[0]
    ColorPrint.print_c("album_id={}".format(album_id), ColorPrint.LIGHTCYAN)
    insert_pieces(path, album_id, conn, c)
    conn.close()
    return album_id
コード例 #22
0
ファイル: splitflac.py プロジェクト: jacron/music_a
def split_file(flac, filepath):
    if not flac:
        return
    duration = to_duration(flac['time'])
    if not duration:
        return
    args = [FFMPEG, '-i', filepath, '-ss', duration]
    if flac['duration']:
        flac_duration = to_duration(flac['duration'])
        if flac_duration:
            args += [
                '-t',
                flac_duration,
            ]
        else:
            ColorPrint.print_c('found no duration for ' + flac['path'],
                               ColorPrint.RED)
    args.append(flac['path'])
    ColorPrint.print_c(flac['fname'], ColorPrint.CYAN)
    socket_log(flac['fname'], 'info')
    subprocess.Popen(args)
コード例 #23
0
def get_album_count_for_person(person_id, type):
    if type == 'componist':
        sql = '''
    SELECT count(*) 
    FROM main.Album A
    JOIN main.Componist_Album C
    ON C.AlbumID=A.ID
    WHERE C.ComponistID=?
        '''
    elif type == 'performer':
        sql = '''
    SELECT count(*) 
    FROM main.Album A
    JOIN main.Performer_Album P
    ON P.AlbumID=A.ID
    WHERE P.PerformerID=?
    '''
    else:
        ColorPrint.print_c('Unknown type: {}'.format(type), ColorPrint.RED)
        return None
    field = get_items_with_parameter(sql, person_id)
    return field[0]
コード例 #24
0
def data_full_cuesheet(path):
    data = None
    with open(path, 'r') as f:
        try:
            data = f.read()
        except UnicodeDecodeError as u:
            ColorPrint.print_c("can't read unicode here", ColorPrint.RED)
            ColorPrint.print_c(str(u), ColorPrint.BLUE)
            ColorPrint.print_c('retrying...', ColorPrint.BLUE)
            with open(path, 'r', encoding='latin1') as f:
                try:
                    data = f.read()
                except Exception as e:
                    ColorPrint.print_c(str(e), ColorPrint.BLUE)
    return data
コード例 #25
0
ファイル: tag.py プロジェクト: jacron/music_a
def get_metatags(p):
    try:
        import mutagen
        return mutagen.File(p)
        # ntags = {}
        # for tag, value in tags.tags:
        #     if tag != 'cuesheet' and tag !='APIC:':
        #         ntags[tag] = value
        # return ntags
    except MutagenError as t:
        ColorPrint.print_c(str(t), ColorPrint.CYAN)
        ColorPrint.print_c(p, ColorPrint.BLUE)
    except Exception as ex:
        ColorPrint.print_c(str(ex), ColorPrint.CYAN)
        ColorPrint.print_c(str(p), ColorPrint.CYAN)
    return None
コード例 #26
0
ファイル: tag.py プロジェクト: jacron/music_a
def delete_tag(p, tag):
    import mutagen
    song = mutagen.File(p)
    try:
        del song[tag]
        song.save()
    except KeyError as ke:
        ColorPrint.print_c('key not found: ' + str(ke), ColorPrint.CYAN)
        ColorPrint.print_c(p, ColorPrint.BLUE)
    except TypeError as te:
        ColorPrint.print_c('type error: ' + str(te), ColorPrint.CYAN)
        ColorPrint.print_c(p, ColorPrint.BLUE)
    except MutagenError as t:
        ColorPrint.print_c(str(t), ColorPrint.CYAN)
        ColorPrint.print_c(p, ColorPrint.BLUE)
    except APEBadItemError as a:
        ColorPrint.print_c(str(a), ColorPrint.CYAN)
        ColorPrint.print_c(p, ColorPrint.BLUE)
コード例 #27
0
def get_path_of_album(album_id):
    if album_id is None:
        ColorPrint.print_c('No album ID given, so quitting', ColorPrint.RED)
        return
    conn, c = connect()
    return get_album_path_by_id(album_id, c)
コード例 #28
0
ファイル: ajaxpost.py プロジェクト: jacron/music_a
def update_piece_name(piece_id, piece_name, album_id):
    try:
        rename_piece_name(piece_id, piece_name, album_id)
        update_db_piece_name(piece_id, piece_name)
    except Exception as ex:
        ColorPrint.print_c(str(ex), ColorPrint.CYAN)