HydrogenAudio

Hosted Forums => foobar2000 => General - (fb2k) => Topic started by: lieti on 2010-06-21 19:27:36

Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: lieti on 2010-06-21 19:27:36
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
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: herojoker on 2010-06-21 19:43:18
Copy the Flac folder to the MP3 folder, then use foobar to convert the contents of the MP3 folder (which currently contains FLACs) to MP3s and after that delete all flac files (for example from within foobar).
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: shakey_snake on 2010-06-21 19:53:40

Use:
Code: [Select]
$replace(%path%,\FLAC\,\MP3\)\%filename%

In the Name Format box of the Converter.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: lieti on 2010-06-21 20:32:37
Copy the Flac folder to the MP3 folder, then use foobar to convert the contents of the MP3 folder (which currently contains FLACs) to MP3s and after that delete all flac files (for example from within foobar).

Thanks , it is also solution (maybe best), but I dont have enough storage capacity for it.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: lieti on 2010-06-21 20:49:21
Use:
Code: [Select]
$replace(%path%,\FLAC\,\MP3\)\%filename%

In the Name Format box of the Converter.


Thanks a lot, It seems interesting, but results are strange.
For instance when I converting from directory d:\Hudba\__FLAC\Teatro Fatal - Divadlo Frizúr\
result is d:\Hudba\__FLAC\Teatro Fatal - Divadlo Frizúr\D-\Hudba\__MP3\Teatro Fatal - Divadlo Frizúr\01 Divadlo frizúr.flac\
that mean that it create in orginal directory subdirectory D-\Hudba\__MP3\Teatro Fatal - Divadlo Frizúr
than in this subdirectory next subdirectory with original name of song \01 Divadlo frizúr.flac\ and in this subdirectory is song stored

I use your command (modified to __FLAC and __MP3)  in field  called  "Name format"
And output folder seting "Same as source file"

But biggest problem is that it doesn´t keep album art in tag, or dosn´t copy abum art file from source directory.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: shakey_snake on 2010-06-21 21:11:46
Thanks a lot, It seems interesting, but results are strange.
For instance...
Yeah, for Output Path you'll need to select "Specify folder" and leave it blank. My guess is you selected "Source Track Folder".

But biggest problem is that it doesn´t keep album art in tag, or dosn´t copy abum art file from source directory.

It's a new file, so it never had artwork; there is nothing to "keep". But yes, the Converter doesn't transfer artwork from source tags to the new file's tags. No part of fb2k does artwork embedding, the Converter included.

I believe dbPowerAmp does, if you need a program to do that. You can also embed art in the files post-conversion, using mp3tag.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: garym on 2010-06-21 21:34:24
I believe dbPowerAmp does, if you need a program to do that. You can also embed art in the files post-conversion, using mp3tag.


Yes, dbpa will do it all including transferring the album art, embedded or in subdirectory as file, or both, as well as allowing you to have a dynamic naming string so that the new mp3 directory mirrors the structure of the old FLAC directory with the exception of the first level (i.e., flac vs mp3)
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: lieti on 2010-06-21 22:01:14
Thanks people,
It seems that dbPowerAmp is good solution.
So now few our of converting waiting for me.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: Mike Brown on 2010-07-07 13:52:30
Thanks a lot, It seems interesting, but results are strange.
For instance...
Yeah, for Output Path you'll need to select "Specify folder" and leave it blank. My guess is you selected "Source Track Folder".

But biggest problem is that it doesn´t keep album art in tag, or dosn´t copy abum art file from source directory.

It's a new file, so it never had artwork; there is nothing to "keep". But yes, the Converter doesn't transfer artwork from source tags to the new file's tags. No part of fb2k does artwork embedding, the Converter included.

I believe dbPowerAmp does, if you need a program to do that. You can also embed art in the files post-conversion, using mp3tag.


I'm having the same trouble.  I have a large directory of albums that I want to convert to mp3 and keep a similar directory structure in the new folder, so I decided to just try your method out on one track to see if I could get it to work.

I'm trying to convert this:
C:\Users\Mike\Music\Doors\flac\01 Doors - Doors (DCC Gold)\The Doors - The Doors (DCC Gold) - 01 - Break On Through (To The Other Side).flac

To this:
C:\Users\Mike\Music\Doors\mp3\01 Doors - Doors (DCC Gold)\The Doors - The Doors (DCC Gold) - 01 - Break On Through (To The Other Side).mp3

And in the preview window, Foobar is telling me it will do this:
C-\Users\Mike\Music\Doors\flac\01 Doors - Doors (DCC Gold)\The Doors - The Doors (DCC Gold) - 01 - Break On Through (To The Other Side).flac\The Doors - The Doors (DCC Gold) - 01 - Break On Through (To The Other Side).mp3

I don't know why it's putting a dash after the C, and why it thinks it should make a subdirectory of a file.

I selected "specify folder" and left it blank, as you said.  And when I click OK, to make the conversion, it brings up a window asking me to choose a destination folder.

What am I doing wrong here?
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: 2E7AH on 2010-07-07 14:04:12
because you put that pattern in name format and colon [:] is not valid character

you should select root folder in "Output path" setting and use some common sense in name pattern (check foobar help file)
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: Mike Brown on 2010-07-08 00:02:29
because you put that pattern in name format and colon [:] is not valid character

you should select root folder in "Output path" setting and use some common sense in name pattern (check foobar help file)

But I didn't put that pattern in the name format, though.  What I put was:
Code: [Select]
$replace(%path%,\FLAC\,\MP3\)\%filename%

And Foobar is trying to create a directory off a file (Which is impossible), and putting in a dash after the C.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: Purple Monkey on 2010-07-08 02:48:50
Well sure you did, what do you think %path% evaluates to? You need strip the "base" directory and not add another %filename%:
Code: [Select]
$replace(%path%,c:\Users\Mike\Music,,\flac\,\mp3\)
Change the "c:\users\.." to where you have pointed the converter. The converter dialogue has a preview of the output paths you can always check before you start a conversion, although it won't popup if you choose a preset from the submenu.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: domanix on 2012-01-22 12:36:33
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  (wont delete any files, however)
5) Works on windows, could be modded for linux

Code: [Select]
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()
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: bluto on 2012-01-23 00:30:16
Just in case it helps others, this is what I use when converting FLAC to MP3.
I am using an old version of Foobar (v.1.1.7) so you may need to tweak this slightly.
My artwork is not embedded - I keep it as separate files (usually "cover.jpg") inside the relevant directories.

Suppose FLACs are in C:\Users\Popeye\Music\Flacs

1) Create a suitable folder for the MP3 files e.g. C:\Users\Popeye\Music\MP3s
2) Load up your FLAC directory into Foobar and make sure all the files are highlighted
3) Right click on the files and select "Convert / ..."
4) Output Format Settings - Set the output type to MP3 and choose your quality setting
5) Destination Settings - Click on "Specify folder" and browse to whatever folder you created in step 1
6) Destination Settings - Use the following name formatting for "Convert each track to an individual file":

$replace(%path%,C:\Users\Popeye\Music\Flacs,,.flac,)

7) Other Settings - Type the following in "Copy other files to the destination folder" to copy all artwork across:

*.jpg;*.gif;*.png

8) Convert!

What this does is to replace "C:\Users\Popeye\Music\Flacs" with "", and also the ".flac" with "".
i.e. It strips down the path to just the subdirectory within your FLACs folder, together with the filename minus the .flac extension.
The converter then appends this to your chosen MP3 directory, and automatically adds the MP3 extension.

My understanding of $replace is that it works like this: $replace(A,B1,C1,B2,C2,B3,C3,...,Bn,Cn)
It looks inside string A, replacing Bi with Ci for i=1,2,3,...,n.

Bluto
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: ryangoan on 2012-02-17 12:03:50
hey all,

thanks for this thread. really helped me out by converting my entire flac library to mp3 while keeping the same folder structure.

for anyone else who wants to know

im using foobar v1.1.10
select files, right click
specify the output folder
select "generate multi-tracks"
paste this $replace( %directoryname%\ %filename%,\FLAC\,\MP3\)
and it will do it perfectly.

test with a few files first to make sure, but its working great for me.
good luck.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: ryangoan on 2012-02-17 12:47:51
my bad.
the post above doesnt recreate all subfolders.

this one does.

$replace( $replace(%path%,.flac,),\FLAC\,\MP3\)

just change .flac if you have other formats.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: Ouroboros on 2012-02-17 13:09:24
You might also want to have a look at flac2mp3.py (http://www.hydrogenaudio.org/forums/index.php?s=&showtopic=73482&view=findpost&p=647028). As well as doing the conversion, it has lots of useful features, like using an MD5 checksum to work out which file(s) haven't changed since the last conversion and only converting those that have, and allowing you to only update the tags between your lossless and lossy library.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: bluto on 2012-02-18 11:32:25
my bad.
the post above doesnt recreate all subfolders.

this one does.

$replace( $replace(%path%,.flac,),\FLAC\,\MP3\)

just change .flac if you have other formats.


This doesn't seem to work for me - I get the same problem the original poster had.

Foobar won't preserve the colon in C: if it appears in the full path, changing it to C- instead.
The only way round this as far as I can tell is to specify a target folder, and strip the initial part
of the path completely as in my post #14 above.

Bluto
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: The_Egg on 2012-07-23 08:20:46
Bluto, you rock.  Using your directions in post #14, I was able to eliminate a very tedious step from my conversion process.  I specified my Mp3 output folder under "Output path", and then spliced my root FLAC source folder into your code, and Foobar now automatically creates the entire subdirectory structure in my specified MP3 destination.  For the others, my code now looks like this:
Code: [Select]
$replace(%path%,C:\Temp\MUSIC RIP,,.flac,)
To Bluto, I get the same result whether the code is pasted under individual or multi-track output files, so I've left it at individual for now.  To everyone else, if you try transcoding a FLAC which isn't in the source folder specified in the code, it's not going to work properly.  Now, if we could find a way to have Foobar preserve the album art during the transcode, I'd be one happy camper.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: bluto on 2012-07-23 12:55:46
Glad it worked for you!

I don't think Foobar can copy across embedded artwork yet; I seem to recall this being raised before in the forum as something which wasn't possible. Personally, I don't like the thought of cluttering up music files with graphics data. Having a single "cover.jpg" file in each directory works fine for me, and is easy to change if necessary without altering the music files themselves.

Regarding the Foobar options, I'm not at all sure what "Generate Multi-track files" means, given that there is already an option for "Merge all tracks into one output file".

Bluto
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: db1989 on 2012-07-23 13:00:54
Now, if we could find a way to have Foobar preserve the album art during the transcode, I'd be one happy camper.
I don't think Foobar can copy across embedded artwork yet; I seem to recall this being raised before in the forum as something which wasn't possible.
bluto is correct. Whether this will be addressed remains to be seen.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: Cwluc on 2012-10-12 13:32:41
hey all,

thanks for this thread. really helped me out by converting my entire flac library to mp3 while keeping the same folder structure.

for anyone else who wants to know

im using foobar v1.1.10
select files, right click
specify the output folder
select "generate multi-tracks"
paste this $replace( %directoryname%\ %filename%,\FLAC\,\MP3\)
and it will do it perfectly.

test with a few files first to make sure, but its working great for me.
good luck.



my bad.
the post above doesnt recreate all subfolders.

this one does.

$replace( $replace(%path%,.flac,),\FLAC\,\MP3\)

just change .flac if you have other formats.


ryangoan you are a life saver. Thank you!
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: Lysaar on 2013-10-29 18:13:57
Hi

thanks for a lot of info but i still strugle

i will convert flac to mp3 (div players)



flac is like this by artist\album (nas server)
\\modesty\Modesty\media\Min musikk\FLAC\Pop og rock\Adele\Adele 19\(all songs to album 19.flac)
\\modesty\Modesty\media\Min musikk\FLAC\Pop og rock\Adele\Adele 21\(all songs to album 21.flac)


i like to have output cat like this

\\modesty\Modesty\media\mp3 convert\Adele\Adele 19\(all songs by songs from album 19.mp3)
\\modesty\Modesty\media\mp3 convert\Adele\Adele 21\(all songs by songs from album 21.mp3)


i have tried with quite success with a double replace but i cant get i right, i get extra catalogs under my mp3 convert cat

$replace( $replace(%path%,\modesty\modesty\media\Min musikk,),\FLAC\,\\\\)


i get this
m:\mp3 convert\_\Pop og rock\Adele\Adele - 19\songs.mp3

I hope some of ou can help me out...

Thanks
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: scope6 on 2014-09-08 00:29:04
Thanks everyone for all of the info.  I had a similar issue to the OP.  I played around with functions like replace and substr and I am amazed at the flexibility...but it was overkill for what I was wanting to do.

All of my FLAC files were in C:\media\audio\lossless\CD\<artist>\<album>\<filename>.flac

The easiest way, that I found, to get everything automatically copied to
C:\media\audio\lossy\CD\<artist>\<album>\<filename>.mp3

was to configure the converter Destination like this:
Output path: C:\media\audio\lossy\CD
Name format: %artist%\%album%\%filename%

and configure the converter Other like this:
[checked] Transfer metadata (tags)
[checked] Transfer attached pictures
Copy other files to the destination folder: *.jpg (to copy album art, if stored externally)

Example input: C:\media\audio\lossless\CD\Nine Inch Nails\Fixed\02 Wish [Remixed by J.G. Thirlwell].flac
Resulting output: C:\media\audio\lossy\CD\Nine Inch Nails\Fixed\02 Wish [Remixed by J.G. Thirlwell].mp3

Folders were automatically created.

Hope this helps!
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: ChrisBLN on 2015-04-26 17:44:23
Quote
flac is like this by artist\album (nas server)
\\modesty\Modesty\media\Min musikk\FLAC\Pop og rock\Adele\Adele 19\(all songs to album 19.flac)
\\modesty\Modesty\media\Min musikk\FLAC\Pop og rock\Adele\Adele 21\(all songs to album 21.flac)


i like to have output cat like this

\\modesty\Modesty\media\mp3 convert\Adele\Adele 19\(all songs by songs from album 19.mp3)
\\modesty\Modesty\media\mp3 convert\Adele\Adele 21\(all songs by songs from album 21.mp3)


Here is a simple solution, using the foobar formatting function $directory(x,n), which extracts the nth directory from below of the pathname x.

For the example, in the destination dialog, set the output folder to : \\modesty\Modesty\media\mp3 convert

In the name format, use the following string:

$directory(%path%,2)\$directory(%path%,1)\%filename%

which will let you keep the two directories over the filename: \Adele\Adele 21\

In the preview area in the lower part of the dialog window you can see the final result of the naming scheme, before starting the batch conversion.

Best regards
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: Alexxander on 2015-04-29 19:38:58
A problem raises when you have multiCD albums with each CD stored in its own subdirectory.
Title: Batch convert FLAC to MP3 with copying of folder structure.
Post by: Thad E Ginathom on 2015-04-29 22:24:43
Just in case any Linux users are looking for an answer, there is a command line utility called pacpl which converts between multiple formats, creates directories where necessary (if asked) and can also overwrite/ignore existing files. I like it very much.

I just wish it would copy album art too, but it looks as if I have to write my own script to do that, and my *nix scripting, which once helped to earn my living, is now dismal.

Title: Re: Batch convert FLAC to MP3 with copying of folder structure.
Post by: omgiafs on 2016-11-27 12:58:15
Example:
Files to convert are stored at NAS, path is "\\nas\\music\FLAC\Breakbeat\"
I want to convert them to *.ogg and save converted files to "H:\music\OGG" with copying of folder structure.

How to make it:
1. Output folder:
Code: [Select]
H:\music\OGG

2. Output style and filename formatting:
Code: [Select]
$directory_path($replace(%path%,\\nas\\music\FLAC\,))\%filename%
This expression make 2 things:
1. remove path to folder, where stored folders with files to convert.
2. remove filename with extension from path, trimmed at 1
3. add filename without old extension.

File stored as
Code: [Select]
\\nas\music\FLAC\Breakbeat\Hyper\Hyper - Bully (The Remixes) [2015]\01. Hyper - Ghost (Davip Remix).flac
Will be converted to
Code: [Select]
H:\music\OGG\Breakbeat\Hyper\Hyper - Bully (The Remixes) [2015]\01. Hyper - Ghost (Davip Remix).ogg
Title: Re: Batch convert FLAC to MP3 with copying of folder structure.
Post by: eahm on 2017-09-25 21:42:57
Please delete, still testing.