newpersn Posted October 23, 2014 Posted October 23, 2014 I have a folder full of tracks. and im after a script that will create the folder by reading the artist and album name. and then move the tracks in to that folder. Any Help? Thanks
pcstru Posted October 23, 2014 Posted October 23, 2014 In Powershell we can grab the extended file attributes, at least from mp3 : function Add-FileDetails { param( [Parameter(ValueFromPipeline=$true)] $fileobject, $hash = @{Artists = 13; Album = 14; Year = 15; Genre = 16; Title = 21; Length = 27; Bitrate = 28} ) begin { $shell = New-Object -COMObject Shell.Application } process { if ($_.PSIsContainer -eq $false) { $folder = Split-Path $fileobject.FullName $file = Split-Path $fileobject.FullName -Leaf $shellfolder = $shell.Namespace($folder) $shellfile = $shellfolder.ParseName($file) #Write-Progress 'Adding Properties' $fileobject.FullName $hash.Keys | ForEach-Object { $property = $_ $value = $shellfolder.GetDetailsOf($shellfile, $hash.$property) if ($value -as [Double]) { $value = [Double]$value } $fileobject | Add-Member NoteProperty "Extended_$property" $value -force } } $fileobject } } #------------------------------------------------------------------------------ A typical use of that might be to list some of the attributes : get-childitem $args -ea silentlycontinue | Add-FileDetails | select-object Mode, LastWriteTime, Length, Name, Extended_Bitrate | format-table Mode, LastWriteTime, Length, Name, Extended_Bitrate -auto You probably want to pipe that into a list then process the list to create teh directory and move the files. 1
newpersn Posted October 23, 2014 Author Posted October 23, 2014 Media monkey can do it. Got to pay for that? (looking at the specs)
benjie Posted October 23, 2014 Posted October 23, 2014 There is a fee version. It has been a while since I have used it, so can't remember if you need to pay for this feature.
RageSto Posted October 23, 2014 Posted October 23, 2014 Yep, the free version can do that. You can pretty well customize what you want the resulting file structure to look like. 1
Admiral208 Posted October 23, 2014 Posted October 23, 2014 Check this out. It can rename all the files to the same format and put them in the correct folder structure. And its free... https://musicbrainz.org/doc/MusicBrainz_Picard
LosOjos Posted October 23, 2014 Posted October 23, 2014 Check this out. It can rename all the files to the same format and put them in the correct folder structure. And its free... https://musicbrainz.org/doc/MusicBrainz_Picard Rename or convert? (I know it sounds pedantic, but one is great, the other is a potential nightmare...)
Admiral208 Posted October 23, 2014 Posted October 23, 2014 rename. when I say the same format, I mean it can rename to something like [Track Number] - [Artist] [Track Name].extension you can also use it to add any missing meta data and album art.
Geoff Posted October 23, 2014 Posted October 23, 2014 (edited) You get to choose what you want Picard/MusicBrainz to do IIRC. It can do any of those options and also fix broken ID3 tags. Also, here's the Linux bash script solution to your problem. #!/bin/bash #Renames and organizes your music data. #Provide the full path of your source music folder as an argument. #Renames music files according to its metadata in format "Track - Title - Album - Artist". #Creates a directory in the target folder with Artist name and stores file in it. if [ -z "$1" ];then #setting default directory cd ~ else cd "$1" fi target_dir='~/Music' for F in ./*.mp3 #change this line to 'for F in ./*' if you have files other than mp3 format do if [ -f "$F" ];then # Get metadata track=`mminfo "$F"|grep track|awk -F: '{print $2}'` track=${track:1} artist=`mminfo "$F"|grep artist|awk -F: '{print $2}'` artist=${artist:1} title=`mminfo "$F"|grep title|awk -F: '{print $2}'` title=${title:1} album=`mminfo "$F"|grep album|awk -F: '{print $2}'` album=${album:1} if [ -n "$artist" ] && [ -n "$title" ] && [ -n "$album" ];then filename="$track - $title - $album - $artist.mp3";echo $filename cp "$F" "$filename" #renaming the file(copy) if [ -d "$target_dir/$artist/$album" ];then #moving file to the artist folder mv "$filename" "$target_dir/$artist/$album" else if [ -d "$target_dir/$artist" ];then mkdir "$target_dir/$artist/$album" mv "$filename" "$target_dir/$artist/$album" else mkdir "$target_dir/$artist" mkdir "$target_dir/$artist/$album" mv "$filename" "$target_dir/$artist/$album" fi fi else echo -e "Skipping b/c insufficient metadata: $F \n" fi fi done Edited October 23, 2014 by Geoff
pcstru Posted October 24, 2014 Posted October 24, 2014 Since I'm in need of a bit of powershell therapy, here's the hacked together script to process a single path (not recursive). Files without the extended attributes populated won't get moved. I need a very similar thing to get rid of all the 128bit rubbish that I foolishly thought would be OK. function Add-FileDetails { param( [Parameter(ValueFromPipeline=$true)] $fileobject, $hash = @{Artists = 13; Album = 14; Year = 15; Genre = 16; Title = 21; Length = 27; Bitrate = 28} ) begin { $shell = New-Object -COMObject Shell.Application } process { if ($_.PSIsContainer -eq $false) { $folder = Split-Path $fileobject.FullName $file = Split-Path $fileobject.FullName -Leaf $shellfolder = $shell.Namespace($folder) $shellfile = $shellfolder.ParseName($file) #Write-Progress 'Adding Properties' $fileobject.FullName $hash.Keys | ForEach-Object { $property = $_ $value = $shellfolder.GetDetailsOf($shellfile, $hash.$property) if ($value -as [Double]) { $value = [Double]$value } $fileobject | Add-Member NoteProperty "Extended_$property" $value -force } } $fileobject } } clear $flist = Get-Childitem -Path "F:\test" | Add-FileDetails foreach ($file in $flist) { $targ_dir = $file.DirectoryName + "\" + $file.Extended_Artists if (!(Test-Path $targ_dir)) { New-Item $targ_dir -type directory } if ( $file.Attributes -ne "Directory" ) { Move-Item $file.FullName $targ_dir } } 1
Koldov Posted May 12, 2022 Posted May 12, 2022 (edited) Sorry for the necro... but I came across this thread (good old EDUGEEK) on a Google search for just such a thing, as I'm downsizing my home PC setup and don't need computers all around the house. Most of the other PS scripts require some sort of module downloading or blogs/forum posts (like this one) that suggest installing some other software (Picard/Media Monkey), but I'd rather not. The above script almost got me there (put them in 'Artist' folders but not 'Album' folders within those), but I'm not a Powershell guy so I'm not exactly sure why... So I'm hoping to consolidate all the various DATA/STORAGE hard drives and moving all my music onto one disk, just copying it all across for now. Eventually I know I'm going to have to go through it and things like the iTunes backup just has a massive folder with thousands of tracks. Most have full ID3 tags (but at the least have Artist & Album and that's all I'm interested in), some have strange track names (#?@! Yourself - Steve Vai) that I can deal with manually I guess. But at the minimum I'd like it to create 'Artist' folders and within that 'Album' folders and have all the tracks moved to the relevant folders. Edited May 12, 2022 by Koldov
Andrew_C Posted May 12, 2022 Posted May 12, 2022 Not sure if it does exactly what you want, but ID3-tagIT would be worth a look.
Koldov Posted May 12, 2022 Posted May 12, 2022 Thanks, may have fixed it though... added in the red part on a hunch that is what is creating the folders and it seems to have worked OK. function Add-FileDetails { param( [Parameter(ValueFromPipeline=$true)] $fileobject, $hash = @{Artists = 13; Album = 14; Year = 15; Genre = 16; Title = 21; Length = 27; Bitrate = 28} ) begin { $shell = New-Object -COMObject Shell.Application } process { if ($_.PSIsContainer -eq $false) { $folder = Split-Path $fileobject.FullName $file = Split-Path $fileobject.FullName -Leaf $shellfolder = $shell.Namespace($folder) $shellfile = $shellfolder.ParseName($file) #Write-Progress 'Adding Properties' $fileobject.FullName $hash.Keys | ForEach-Object { $property = $_ $value = $shellfolder.GetDetailsOf($shellfile, $hash.$property) if ($value -as [Double]) { $value = [Double]$value } $fileobject | Add-Member NoteProperty "Extended_$property" $value -force } } $fileobject } } clear $flist = Get-Childitem -Path "F:\test" | Add-FileDetails foreach ($file in $flist) { $targ_dir = $file.DirectoryName + "\" + $file.Extended_Artists [b][color="#FF0000"]+ "\" + $file.Extended_Album[/color][/b] if (!(Test-Path $targ_dir)) { New-Item $targ_dir -type directory } if ( $file.Attributes -ne "Directory" ) { Move-Item $file.FullName $targ_dir } }
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now