Skip to content
Advertisement

IndentationError in python script for organising Music

I have made this script in the past and I want to use it now, but an error occurs when trying to run it. This script is about organising my music. I have a directory organised by label and want to grab the artist name from the directory names inside label and year directory and create new directories inside the artist and year directory.

The names of directories inside label are like this

LabelName_[Artist-AlbumName]_2015-08-09

And want to create symlinks inside artist directories and year directories( by date ) like this

2015-08-09_[Artist-AlbumName]_LabelName

import os
basedir = "/home/zab/Music/#01.Label"
artist_parent_dir = "/home/zab/Music/#03.Artist"
date_parent_dir = "/home/zab/Music/#04.ReleaseDate"
for fn in os.listdir(basedir):
    label_path = os.path.join( basedir, fn)
    for album in os.listdir(label_path):
        i = 1
        words = album.split("_")
        for word in words:
            if i == 1:
                label = word
            elif i == 2:
                name = word
            else:
                date = word
            i = i + 1
        artist_album = name.split("-")
        j = 1
        for part in artist_album:
            if j == 1:
                artist = part.replace("[","")
            j = j + 1
        date_parts = date.split("-")
        z =  1
        for part_two in date_parts:
            if z == 1:
                year = part_two
            z = z + 1
        if not os.path.isdir(os.path.join(artist_parent_dir,artist)):
            os.mkdir(os.path.join(artist_parent_dir,artist))
        if not os.path.isdir(os.path.join(date_parent_dir,year)):
            os.mkdir(os.path.join(date_parent_dir,year))
        src = os.path.join(label_path,album)
        artist_dst = os.path.join(artist_parent_dir, artist, name + "_" + label + "_" + date)
        year_dst = os.path.join(date_parent_dir,year, date + "_" + name + "_" + label)
        if not os.path.exists(artist_dst):
            os.symlink(src, artist_dst)
        if not os.path.exists(year_dst):
            os.symlink(src, year_dst)

File "/home/zab/Music/_Scripts/OrganizeByArtist.py", line 22
    artist = part.replace("[","")
                                ^
IndentationError: expected an indented block

What is going wrong? Is part.replace outdated or something? Any suggestion to improve this script would be appreciated.

Advertisement

Answer

You’re probably mixing spaces and tabs, which makes it hard to figure out how Python sees the indentation.

User contributions licensed under: CC BY-SA
6 People found this is helpful
Advertisement