473,398 Members | 2,335 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Tired of renaming mp3's? I am...

Hi guys. It's been ages since I tried making anything halfway useful in python, and back when I did, I was almost never successful...

Anyways, the thing is: I'm finally finished moving my mp3's from a great heap in a folder called "miscellany", and I'm dead tired of organizing stuff that should have been organized ages ago, and have already been organized on my laptop...
What is the matter at the moment is that most mp3's, ripped from cd's or acquired by other means, come with a free but annoying band-name at the beginning. So what did I do? I undusted python of course, and found myself sorely incompetent... This is roughly what I want... I take it you get the picture?

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. for n in range(1000)
  4.  
  5.  
  6.     bandname=raw_input("Band Name? ")
  7.     folderpath=raw_input("The exact path to the folder in which the mp3's are? ")
  8.     l1=[]
  9.     l1.append(filenames in folderpath)
  10.  
  11.     for item in l1:
  12.         if item contains bandname:
  13.             item=item-bandname
  14.  
  15.  
  16.     for item in l1:
  17.         assign item to corresponding file or summat like that
  18.  
  19.  
  20.     questionthingie=raw_input("Wanna start again? ")
  21.     if questionthingie=="Yeah":
  22.         print "Okay, here we go"
  23.     else:
  24.         break
  25.  
  26.  
Anyone have any suggestions as to where I should go from here?
I would greatly appreciate it ^^

Burnie
Aug 6 '07 #1
5 1643
ilikepython
844 Expert 512MB
Hi guys. It's been ages since I tried making anything halfway useful in python, and back when I did, I was almost never successful...

Anyways, the thing is: I'm finally finished moving my mp3's from a great heap in a folder called "miscellany", and I'm dead tired of organizing stuff that should have been organized ages ago, and have already been organized on my laptop...
What is the matter at the moment is that most mp3's, ripped from cd's or acquired by other means, come with a free but annoying band-name at the beginning. So what did I do? I undusted python of course, and found myself sorely incompetent... This is roughly what I want... I take it you get the picture?

Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. for n in range(1000)
  4.  
  5.  
  6.     bandname=raw_input("Band Name? ")
  7.  
  8.     l1=[]
  9.     l1.append(filenames in folderpath)
  10.  
  11.     for item in l1:
  12.         if item contains bandname:
  13.             item=item-bandname
  14.  
  15.  
  16.     for item in l1:
  17.         assign item to corresponding file or summat like that
  18.  
  19.  
  20.     questionthingie=raw_input("Wanna start again? ")
  21.     if questionthingie=="Yeah":
  22.         print "Okay, here we go"
  23.     else:
  24.         break
  25.  
  26.  
Anyone have any suggestions as to where I should go from here?
I would greatly appreciate it ^^

Burnie
I'm not really sure what you want to do. Do you want to rename all files with a band name without the bandname?:
Expand|Select|Wrap|Line Numbers
  1. import os, os.path
  2. while 1:
  3.     bandname =  raw_input("Bandname: ")
  4.     if not bandname: break
  5.     folderpath = raw_input("The exact path in which the MP3's are located: ")
  6.  
  7.     filenames = [name for name in os.listdir(folderpath) if os.path.splitext(name)[1] == ".mp3"]
  8.  
  9.     for name in filenames:
  10.         if bandname in name:
  11.             newname = os.path.join(folderpath, name.replace(bandname, ""))
  12.             os.rename(os.path.join(folderpath, name), newname)
  13.  
  14.  
Is that what you need?
Aug 7 '07 #2
I'm not really sure what you want to do. Do you want to rename all files with a band name without the bandname?:
Expand|Select|Wrap|Line Numbers
  1. import os, os.path
  2. while 1:
  3.     bandname =  raw_input("Bandname: ")
  4.     if not bandname: break
  5.     folderpath = raw_input("The exact path in which the MP3's are located: ")
  6.  
  7.     filenames = [name for name in os.listdir(folderpath) if os.path.splitext(name)[1] == ".mp3"]
  8.  
  9.     for name in filenames:
  10.         if bandname in name:
  11.             newname = os.path.join(folderpath, name.replace(bandname, ""))
  12.             os.rename(os.path.join(folderpath, name), newname)
  13.  
  14.  
Is that what you need?
I think this is what I need, but I don't quite understand it. Could you explain it line by line? What I need is to make it rename the files so that if the bandname is in the filename, it removes the bandname from the filename.
Aug 7 '07 #3
ilikepython
844 Expert 512MB
I think this is what I need, but I don't quite understand it. Could you explain it line by line? What I need is to make it rename the files so that if the bandname is in the filename, it removes the bandname from the filename.
Of first you import the os and os.path modules. They help with renaming the files and searching the directory.
Expand|Select|Wrap|Line Numbers
  1. import os, os.path
  2.  
Then you have the main loop. Here you ask the user for the band name and the folderpath. If the user doesn't give a bandname, the loop exits
Expand|Select|Wrap|Line Numbers
  1. while 1:
  2.     bandname =  raw_input("Bandname: ")
  3.     if not bandname: break
  4.     folderpath = raw_input("The exact path in which the MP3's are located: ")
  5.  
Next, you get all the filenames from the directory:
Expand|Select|Wrap|Line Numbers
  1.    filenames = [name for name in os.listdir(folderpath) if os.path.splitext(name)[1] == ".mp3"]
  2.  
That line could be translated into this:
Expand|Select|Wrap|Line Numbers
  1. filenames = []
  2. for name in os.listdir(folderpath):    # listdir return a list of files in the directory
  3.     if os.path.splitext(name)[1] == ".mp3":   # only files with extension ".mp3"
  4.         filenames.append(name)   # add to list
  5.  
Now, all that's left is to rename the files. You check if bandname is in the filename for every file in filenames and if it is you remove it:
Expand|Select|Wrap|Line Numbers
  1.     for name in filenames:   # iterate over files
  2.         if bandname in name: # check if the bandname is in the filename
  3.             newname = os.path.join(folderpath, name.replace(bandname, ""))  # os.path.join joins 2 directories; join the path and the name; # replace the bandname with an empty string
  4.             os.rename(os.path.join(folderpath, name), newname) # rename using the os module
  5.  
Does that make sense?
Aug 7 '07 #4
Does that make sense?
That makes, if not perfect, a lot of sense! Thank you a lot, this was a great help! You guys just keep on impressing me =P

Again thanks!
Aug 13 '07 #5
Now the program seems to be running along smoothly, though there is one small problem. I'm from Norway, and when I first started using this computer, I did a very stupid thing... I called myself by my real name, which unfortunately contains an norwegian letter, "ř". Is there any way to make python understand this letter?

At the moment, it can't change a single name, because it runs into this cursed letter before it even gets that far... For now, all the program does is inform me that it cant find the folder: "c:\documents and settings\Bj\xf8rn Magne\min musikk\musikk\", which really us no wonder, because my name isn't Bj\xf8rn Magne, no matter how much I want it to be...

Anyone help? This problem is starting to annoy me...
Aug 14 '07 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

16
by: dudufigueiredo | last post by:
I have one folder containing mp3 files, the folder is: C:\My Shared Folder\Rubber Soul And the files are: 01 drive my car.mp3 02 norwegian wood.mp3 03 you won't see me.mp3 04 nowhere man.mp3...
4
by: _BNC | last post by:
..NET/C# doesn't seem to have much support for MIDI interface and music playback in general. Are there any good references on it?
8
by: Aleksandar Djurdjevic | last post by:
Hello I made small mp3 player in VB.NET Express Edition..but i don't know how to read mp3 filename in Label..for example...i load mp3 by OpenFileDialog..the music starts and filename of that mp3...
0
by: ctrent | last post by:
I have a client who built a Java app to compose music tracks. They have mp3 files broken down into segments (intro, verse, chorus, turnaround, etc) that the user can piece together to form complete...
14
by: chokies12 | last post by:
hello guys im new here..hope you can help make my first project in visual basic..i want to make a mp3 player in visual basic without using the WMP OCX.. i have started i downloaded a simple mp3...
11
by: globalrev | last post by:
http://www.pygame.org/docs/ref/mixer.html import pygame #pygame.mixer.init(frequency=22050, size=-16, channels=2, buffer=3072) //it complained abiout words= so i guess its only the nbrs...
5
by: kumarboston | last post by:
Hi All, I am trying to organize my song directory and trying to remove the duplicate entries, I have written a small code but somehow I am not able to rename the song name. I am trying to change...
2
by: rotaryfreak | last post by:
Hi, I was just wondering if it is possible to write a java program that will rename a whole bunch of .mp3 files? if it is possible, how would i go about doing that? thanks!
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.