0

This is a script I did to put the track numbers before the name of mp3s to keep the tracks in the correct order instead of alphabetized.

It ran fine on all (100+ folders / 1300+ songs) except for three folders .

I cannot tell wtf is going on here.

any body have any ideas?

output => 

Enter the path to the music file:/n>c:\test

path_name = c:\test\2 - Live Albums\1995 - MTV unplugged\Shooting Star.mp3

02 - Shooting Star.mp3

path_name = c:\test\2 - Live Albums\1995 - MTV Unplugged\The Times They are A-Changin'.mp3

04 - The Times They Are A-Changin'.mp 3 path_name = c:\test\2 - Live Albums\1995 - MTV Unplugged\Tombstone Blues.mp3 01 - Tombstone Blues.mp3

path_name = c:\test\2 - Live Albums\1995 - MTV Unplugged\With God On Our Side.mp3

12 - With God On Our Side.mp3

path_name = c:\test\1 - Studio Albums\1964 - The Times They Are A-Changin\Ballad Of Hollis Brown.mp3

Traceback (most recent call last):

File "C:/Users/Brian/Python Files/track_numbering_mp3.py", line 45, in

music_track_numbering(path)

File "C:/Users/Brian/Python Files/track_numbering_mp3.py", line 39, in music_track_numbering

os.rename(join(root,name),join(root,track_number)) # renames the file

WindowsError: [Error 3] The system cannot find the path specified

Process finished with exit code 1

#!usr/bin/env python
__author__ = 'Brian Kane'

"""This scripts takes a path argument to the root directory of the music files (mp3 here) and
   adds a padded number corresponding to the track number.  It will do this to all of the tracks in the folders
   and subfolders.  This allows for burning in the track order and not alphabetized.  In theory I suppose you could
   start at C:'\'"""

import os
from os.path import *
import string
from mutagen.mp3 import MP3
from mutagen.easyid3 import EasyID3


def music_track_numbering(path):
    nums = []

    for i in range(10):                                                     # just fills in nums to compare to track name
                                                                            # to not double number
        nums.append(str(i))

        for root, dirs, files in os.walk(path):                             # walks through the data tree to get files
            # print 'root = ', root
            # print 'dirs = ', dirs
            # print 'files = ',files
            for name in files:
                extension = os.path.splitext(name)[1][1:].strip().lower()  # gets the file extension

                if name[0] in nums:                                         # don't double number
                    break

                if extension == 'mp3':
                    # print 'name = ', name                                 # test purposes
                    path_name = root +'\\' + name                           # path_name is complete path
                    print 'path_name = ', path_name                         # test purposes
                    track = EasyID3(path_name)['tracknumber'][0]            # gets the track number from metadata
                    track_number = str(track).zfill(2) + ' - ' + name       # pads leading zero and adds dash to name
                    os.rename(join(root,name),join(root,track_number))      # renames the file
                    print track_number                                      # test purposes

# path = 'C:\\test'                                                         # this is a test path
path = raw_input('Enter the path to the music file:/n>')

music_track_numbering(path)
bkane56
  • 1,669
  • 1
  • 12
  • 17
  • 1
    Nothing obvious jumps out at me. How about adding a print statement just prior to `os.rename()` to display the arguments that are being passed to that function. Could it be a permissions problem, e.g. the directory can not be written to? – mhawke Mar 12 '15 at 23:42
  • Might want to learn the [pdb module](https://docs.python.org/2.7/library/pdb.html#module-pdb) if print statements don't work. – wwii Mar 13 '15 at 00:55
  • Tried renaming the folder and is busy somewhere. Time for a reboot. – bkane56 Mar 13 '15 at 02:03

0 Answers0