473,728 Members | 1,978 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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

52 New Member
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 1660
ilikepython
844 Recognized Expert Contributor
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
BurnTard
52 New Member
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 Recognized Expert Contributor
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
BurnTard
52 New Member
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
BurnTard
52 New Member
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:\documen ts and settings\Bj\xf8 rn 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
2987
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
9315
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
1612
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 is shown in Label.. greetings
0
1507
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 songs. My job is to find a way to preview their selections in a Flash player. Their Java app does a great job at building the composed mp3's, but they still need a way to preview their selections when the user is composing. So far I've been...
14
3662
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 player without WMP OCX and use it as a reference but since it has no tutorial i have to see the codes 1by1 i cant play my project..here's my code.. Private Sub CmdBrowse_Click() On Error GoTo error With CDlg1 'On Cancel do nothing ...
11
11678
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 should be there// pygame.mixer.init(22050, -16, 2, 3072) pygame.mixer.music.load("example1.mp3")
5
1682
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 all the song name to uppercase and then removing the spaces, any number and other characters. #!/usr/bin/perl use strict; use warnings; my $cnt = 1; my $folder = "/home/kk/song/latest";
2
3531
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
8903
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, weíll explore What is ONU, What Is Router, ONU & Routerís main usage, and What is the difference between ONU and Router. Letís take a closer look ! Part I. Meaning of...
0
8758
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9422
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9277
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9130
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6013
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3236
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
2663
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2161
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.