IPB

Welcome Guest ( Log In | Register )

> foobar2000 General Forum Rules

This is NOT a tech support forum.
Tech support questions go to foobar2000 Tech Support forum instead.

See also: Hydrogenaudio Terms of Service.

Batch convert FLAC to MP3 with copying of folder structure.
lieti
post Jun 21 2010, 19:27
Post #1





Group: Members
Posts: 7
Joined: 21-June 10
Member No.: 81695



HELLo.
I want to convert my FLAC an APE collection to MP3 with highest quality, because FLAC is too big for my mp3 player.
I know how to convert between formats (but if somebody give me correct parameters for mp3 settings I will be thankfull)
Problem is that I want to convert it in batch proccess.
Now I have my FLAC collection in directory "D:\Music\Flac\...." and I want to convert it automaticly to the folder d:\Music\MP3, with keeping of everything, like tags,album art in tag folder and subfolder structure and files.
Thanks a lot for answer
Go to the top of the page
+Quote Post
 
Start new topic
Replies
domanix
post Jan 22 2012, 13:36
Post #2





Group: Members
Posts: 1
Joined: 22-January 12
Member No.: 96616



Hi,

Sorry to resurrect an old thread. I've had the same problem with the output from F2k and, while using %path% is a nice option, I would prefer to be able to copy artwork too. Currently, I use F2k to convert the FLAC files into mp3 in the source folders, and then use the following python script to move the mp3s into a new folder while copying the artwork and maintaining the directory structure. I thought I'd share the code as, until F2k is updated, this will be an issue.

Notes on code:
1) Code is a hack, comes without warranty
2) Takes two folders - input folder with flac/mp3/artwork, empty output folder for mp3
3) Input folder must not be a subfolder of output folder or vice versa
4) Overwrites files in target directory without warning blink.gif (wont delete any files, however)
5) Works on windows, could be modded for linux

CODE
print "-----------------------------------------------"
print "Application to relocate mp3 files whilst "
print "preserving directory structure and album art"
print "DL 2012"
print "v. 0.1"
print "-----------------------------------------------"

import os, subprocess
import tkFileDialog
from Tkinter import *
from tkMessageBox import askokcancel

# moveit: file f relocates from src to dest
def moveit( f , sorc , dest):
fullPath = sorc + "\\" + f
subprocess.Popen("move" + " \"" + fullPath + "\" " + " \"" + dest + "\" ",shell=True)
return

# copyit: file f duplicates in dest folder
def copyit( f , sorc , dest):
fullPath = sorc + "\\" + f
subprocess.Popen("copy" + " \"" + fullPath + "\" " + " \"" + dest + "\" ",shell=True)
return

# parseDirs: reproduces directory structure, copys/moves files
def parseDirs(srcMain , dstMain):
src = srcMain
dst = dstMain

reparseDirs = [] # directories to reparse
reparseDirs.append('')

# outer loop : moves between directories
while len(reparseDirs)>0:
subfolder = reparseDirs.pop()
print('\rreparseDirs:' + src + "\\" + subfolder)
listOfFiles = os.listdir(src + "\\" + subfolder)

# inner loop : moves files, creates directories
for f in listOfFiles:
temp = f
temp=temp.lower()

#verify file longer than 4 chars (e.g. at least x.xx)
if len(temp)>3:
ext = temp[len(temp)-4:len(temp)]
else:
ext = 'x.xx' # dummy output

# identify file type
if os.path.isdir(src + "\\" + subfolder + "\\" + f):
# duplicate folder structure
print('creating folder: ' + f)
try:
os.mkdir(dst + "\\" + subfolder + "\\" + f)
except OSError:
print 'folder already exists'
reparseDirs.append(subfolder + "\\" + f) # search source dir for files
elif ('flac' in ext)|('ape' in ext)|('m4a' in ext)|('alac' in ext):
#ignore lossless
print ('ignoring lossless file: ' + f)
elif 'cue' in ext:
#ignore cue
print ('ignoring cue file: ' + f)
elif 'mp3' in ext:
#relocate mp3
print ('moving mp3 in file: ' + f)
moveit(f , src + "\\" + subfolder, dst + "\\" + subfolder)
else:
#copy other file types
print ('copying file: ' + f)
copyit(f , src + "\\" + subfolder, dst + "\\" + subfolder)

########### Begin GUI Block
class openDialog(Frame):
def __init__(self, parent=None):
Frame.__init__(self, parent)
self.parent = parent # create a reference to the Tk() instance
self.createWidgets()
self.launchApp()

def createWidgets(self):
self.textDirIn = StringVar()
self.textDirOut = StringVar()

self.DirIn = Entry(self, width=70, textvariable=self.textDirIn)
self.DirIn.pack()

self.DirOut = Entry(self, width=70, textvariable=self.textDirOut)
self.DirOut.pack()

self.pack()

def getDir(self):
self.dirin=tkFileDialog.askdirectory()
return self.dirin

def launchApp(self):
inputDir = self.getDir()
self.textDirIn.set(inputDir)
outputDir = self.getDir()
self.textDirOut.set(outputDir)

if askokcancel(title="Continue?", message="Continue using these folders?"):
print 'Continue...'
parseDirs(inputDir,outputDir)
self.textDirIn.set('complete!')
self.textDirOut.set('close window to finish')
print 'complete: close window to finish'
else:
print 'Operation cancelled'
self.textDirIn.set('cancelled')
self.textDirOut.set('cancelled')
########### End GUI Block

#### MAIN ####
if __name__ == "__main__":
root=Tk()
openDialog(root)
root.mainloop()
Go to the top of the page
+Quote Post

Posts in this topic
- lieti   Batch convert FLAC to MP3 with copying of folder structure.   Jun 21 2010, 19:27
- - herojoker   Copy the Flac folder to the MP3 folder, then use f...   Jun 21 2010, 19:43
|- - lieti   QUOTE (herojoker @ Jun 21 2010, 19:43) Co...   Jun 21 2010, 20:32
- - shakey_snake   Use: CODE$replace(%path%,\FLAC...   Jun 21 2010, 19:53
|- - lieti   QUOTE (shakey_snake @ Jun 21 2010, 19:53)...   Jun 21 2010, 20:49
|- - shakey_snake   QUOTE (lieti @ Jun 21 2010, 15:49) Thanks...   Jun 21 2010, 21:11
|- - garym   QUOTE (shakey_snake @ Jun 21 2010, 14:11)...   Jun 21 2010, 21:34
||- - lieti   Thanks people, It seems that dbPowerAmp is good so...   Jun 21 2010, 22:01
|- - Mike Brown   QUOTE (shakey_snake @ Jun 21 2010, 15:11)...   Jul 7 2010, 13:52
- - 2E7AH   because you put that pattern in name format and co...   Jul 7 2010, 14:04
|- - Mike Brown   QUOTE (2E7AH @ Jul 7 2010, 08:04) because...   Jul 8 2010, 00:02
- - Purple Monkey   Well sure you did, what do you think %path% evalua...   Jul 8 2010, 02:48
- - domanix   Hi, Sorry to resurrect an old thread. I've h...   Jan 22 2012, 13:36
|- - bluto   Just in case it helps others, this is what I use w...   Jan 23 2012, 01:30
- - ryangoan   hey all, thanks for this thread. really helped me...   Feb 17 2012, 13:03
- - ryangoan   my bad. the post above doesnt recreate all subfold...   Feb 17 2012, 13:47
|- - bluto   QUOTE (ryangoan @ Feb 17 2012, 14:47) my ...   Feb 18 2012, 12:32
- - Ouroboros   You might also want to have a look at flac2mp3.py....   Feb 17 2012, 14:09
- - egglick   Bluto, you rock. Using your directions in post #1...   Jul 23 2012, 08:20
|- - bluto   Glad it worked for you! I don't think Foo...   Jul 23 2012, 12:55
- - db1989   QUOTE (egglick @ Jul 23 2012, 07:20) Now,...   Jul 23 2012, 13:00
- - Cwluc   QUOTE (ryangoan @ Feb 17 2012, 07:03) hey...   Oct 12 2012, 13:32
|- - Lysaar   Hi thanks for a lot of info but i still strugle ...   Oct 29 2013, 19:13
- - scope6   Thanks everyone for all of the info. I had a simi...   Sep 8 2014, 00:29


Reply to this topicStart new topic
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:

 



RSS Lo-Fi Version Time is now: 16th September 2014 - 16:49