Cash Talks - BS Walks RSS 2.0
# Monday, 10 March 2008

In my previous blog entry, Easily setting Tags on Media Files using PowerShell, I described how to set the media tags used by common MP3 players.

The reason I had this need stemed from a frustration from RIPing Audio Books into MP3s.  For example, let's say I'm compressing a 10 CD book.  Even with "good" audio naming from Internet Naming sources, you get 10 different albums with numberd tracks from 1 to whatever.  Sometimes the naming fixes this and sometimes it does a miserable job.  Copying and renaming the files doesn't do the job.  When you RIP the CD the encoder creates Meta Tags Used by MP3 players.

When your favorite tool is a hammer...

I didn't even look for a tool to solve this problem so if there is one... that's not really the point.  I was curious if I could solve it very easily using Powershell.  This is what I want:

  • Copy all files to a single directory
  • Name all files with some base name with a Zero padded count.
  • Provide for a flexible means for setting Tags on all Files.  For example, Author
  • Set the Album Tag so all files will appear as a single album
  • Set Meta Track number to coorespond the the Count and Title to the Filename

When I RIP the CDs it easy to get them all under a single directory and organize the directories Alphabetically so the CDs are in order.  The individually named where they also sort alphabetically.  As such the following line will return all MP3s under a directory in the order they should be played:

dir -Recurse -Filter *.mp3

As such, I need a CmdLet where I can pipe these.  This CmdLet will also take an Array parameter if that is your preference.

function Copy-NumberFile
 
( [
system.IO.FileInfo] $file=$(Throw "File is required"
)
 
, [string] $BaseName=$(Throw "BaseName is required"
)
  ,
$DestDir=$(Throw "DestDir is required"
)
  , [
int] $Count=$(Throw "Count is required"
)
  , [
int] $Digits=
1
  , [
switch]
$Verbose
 
, [switch]
$PassThru
 
)
{
 
$nbrStr = "{0:d$Digits}" -f
$Count
 
$NewName =
"$($BaseName)$($nbrStr)$($file.Extension)"
 
$NewFileName = [System.IO.Path]::Combine($DestDir.FullName,$NewName
)
 
if ($Verbose
)
  {
   
Write-Host
"Copy $($file.fullname) to $NewFileName"
 
}
  
Copy-Item $file.FullName -Destination $NewFileName -PassThru:
$PassThru
}

Function
Organize-AudioBookFiles 
 
( [
System.IO.DirectoryInfo]
$DestDir
 
, [hashtable]
$Tags
 
, [string]
$BaseName
 
, [int]$CountStart=
1
  ,
$Digits=-
1
  , [
array]$Files
)
{
 
begin
 
{
    [
array] $fileList =
$null
   
function AddFile( $FileToCheck
)
    {
     
if ($fileToCheck -ne $null
)
      {
        [
system.IO.FileInfo] $file =
$FileToCheck
       
if (!$file.Exists) { Throw "File does Not Exist"
}
       
$file
     
}
    }
    
    if (!$DestDir.Exists
)
    {
      $DestDir.Create
()
    }
    
if ((dir $DestDir.FullName | Measure-Object).Count -gt
0)
    {
     
Throw
"Destination Directory $($DestDir.FullName) is not empty"
    
}
   
foreach ($file in $files
)
    {
     
$fileList += AddFile($file

    }
  }
 
 
process
 
{
   
$fileList += AddFile($_
)
  }

  end
 
{
    $Count =
$CountStart
    
if ($digits -lt
0)
    {
      [
int]$Digits = [System.Math]::Truncate(([System.Math]::Log10($fileList.Count + $Count)))+
1
    }
   
foreach ($file in $fileList
)
    {
     
$file = Copy-NumberFile -file $file -DestDir $DestDir -BaseName $BaseName
`
       
-Digits $digits -Count ($Count) -Verbose
-PassThru
     
$filename = $file.
Name
     
$Tags.Track =
$Count
     
$Tags.Title = $filename.Substring(0,($filename.length-$file.extension.length
))
     
SetMedia-Tags -file $file -Tags
$Tags
     
$Count
++
   
}
  }
}

I have a helper function "Copy-NumberFile".  While I'm not sure if I'll ever need it in another operation, I can imagine it.  It copies a file to a Destination Directory, renames it with a BaseName followed by a Number and preserving the extension.  The number of Zero padded digits is specified in the $Digits parameter.  The $PassThru allows the caller to get the FileInfo for the created file.

An example usage might look like:

$Tags = @{Artists="Book Author";Album="Book Title";Comment="This is a comment";Genres=@("Fiction")}
$files = dir -Recurse -Filter *.mp3
Organize-AudioBookFiles -Files $files -DestDir "C:\temp\Book" -BaseName "BookName " -Tags $Tags

Monday, 10 March 2008 02:27:18 (GMT Standard Time, UTC+00:00)  #    Comments [42] -
Powershell
Tracked by:
"http://blastpr.com/wiki/js/pages/rainbow-brite/index.html" (http://blastpr.com/... [Pingback]
"http://blastpr.com/wiki/js/pages/celebrex/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/nexium/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/clomid/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/celebrex/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/coumadin/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/prozac/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/rainbow-brite/index.html" (http://morn... [Pingback]
"http://blastpr.com/wiki/js/pages/paxil/index.html" (http://blastpr.com/wiki/js/... [Pingback]
"http://morningside.edu/mics/_notes/pages/prilosec/index.html" (http://morningsi... [Pingback]
"http://blastpr.com/wiki/js/pages/zoloft/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/synthroid/index.html" (http://mornings... [Pingback]
"http://blastpr.com/wiki/js/pages/effexor/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://morningside.edu/mics/_notes/pages/effexor/index.html" (http://morningsid... [Pingback]
"http://blastpr.com/wiki/js/pages/coumadin/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/cymbalta/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/prozac/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/claritin/index.html" (http://morningsi... [Pingback]
"http://morningside.edu/mics/_notes/pages/lipitor/index.html" (http://morningsid... [Pingback]
"http://blastpr.com/wiki/js/pages/ultram/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/clomid/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://blastpr.com/wiki/js/pages/nexium/index.html" (http://blastpr.com/wiki/js... [Pingback]
"http://morningside.edu/mics/_notes/pages/soma/index.html" (http://morningside.e... [Pingback]
"http://morningside.edu/mics/_notes/pages/cialis/index.html" (http://morningside... [Pingback]
"http://blastpr.com/wiki/js/pages/lipitor/index.html" (http://blastpr.com/wiki/j... [Pingback]
"http://blastpr.com/wiki/js/pages/wellbutrin/index.html" (http://blastpr.com/wik... [Pingback]
"http://blastpr.com/wiki/js/pages/prilosec/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://blastpr.com/wiki/js/pages/melatonin/index.html" (http://blastpr.com/wiki... [Pingback]
"http://blastpr.com/wiki/js/pages/tramadol/index.html" (http://blastpr.com/wiki/... [Pingback]
"http://morningside.edu/mics/_notes/pages/viagra/index.html" (http://morningside... [Pingback]
"http://morningside.edu/mics/_notes/pages/wellbutrin/index.html" (http://morning... [Pingback]
"http://allfreefilms.com/wp-includes/js/27702077/index.html" (http://allfreefilm... [Pingback]
"http://discussgod.com/cpstyles/docs/62161481/index.html" (http://discussgod.com... [Pingback]
"http://jivest2006.com/docs/76826750/index.html" (http://jivest2006.com/docs/768... [Pingback]
"http://thebix.com/includes/compat/docs/10152421/index.html" (http://thebix.com/... [Pingback]
"http://discussgod.com/cpstyles/docs/43932298/index.html" (http://discussgod.com... [Pingback]
"http://thejohnslater.com/pix/img/docs/73486930/index.html" (http://thejohnslate... [Pingback]
"http://discussgod.com/cpstyles/docs/90092602/index.html" (http://discussgod.com... [Pingback]
"http://blog.netmedia.hr/wp-includes/js/docs/08493171/index.html" (http://blog.n... [Pingback]
"http://realestate.hr/templates/css/docs/28593877/index.html" (http://realestate... [Pingback]
"http://add2rss.com/img/design/docs/90861918/index.html" (http://add2rss.com/img... [Pingback]
"http://swellhead.netswellhead.net/docs/42306518/index.html" (http://swellhead.n... [Pingback]
"http://pddownloads.com/docs/15972574/index.html" (http://pddownloads.com/docs/1... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/70471394/index.html" ... [Pingback]
"http://discussgod.com/cpstyles/docs/25383456/index.html" (http://discussgod.com... [Pingback]
"http://swellhead.netswellhead.net/docs/84545083/index.html" (http://swellhead.n... [Pingback]
"http://realestate.hr/templates/css/docs/36157459/index.html" (http://realestate... [Pingback]
"http://pddownloads.com/docs/66275653/index.html" (http://pddownloads.com/docs/6... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/84431573/index.html" (... [Pingback]
"http://martinrozon.com/images/photos/docs/75270452/index.html" (http://martinro... [Pingback]
"http://legambitdufou.org/Library/docs/15090396/index.html" (http://legambitdufo... [Pingback]
"http://thebix.com/includes/compat/docs/44694113/index.html" (http://thebix.com/... [Pingback]
"http://ipsilon.hr/ipsilon.hr/cms/4/lib/docs/55227677/index.html" (http://ipsilo... [Pingback]
"http://add2rss.com/img/design/docs/73396176/index.html" (http://add2rss.com/img... [Pingback]
"http://islands-croatia.comislands-croatia.com/includes/js/docs/68291686/index.h... [Pingback]
"http://martinrozon.com/images/photos/docs/61904307/index.html" (http://martinro... [Pingback]
"http://legambitdufou.org/Library/docs/38152786/index.html" (http://legambitdufo... [Pingback]
"http://ipsilon.hr/ipsilon.hr/cms/4/lib/docs/24066563/index.html" (http://ipsilo... [Pingback]
"http://seo4u.at/images/docs/72359352/index.html" (http://seo4u.at/images/docs/7... [Pingback]
"http://coolioness.com/attachments/docs/76375390/index.html" (http://coolioness.... [Pingback]
"http://ncdtnanotechportal.info/generator/docs/87198700/index.html" (http://ncdt... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/52060005/index.html" ... [Pingback]
"http://temerav.com/images/menu/46200403/index.html" (http://temerav.com/images/... [Pingback]
"http://plantmol.com/docs/24471383/index.html" (http://plantmol.com/docs/2447138... [Pingback]
"http://thebix.com/includes/compat/docs/15870923/index.html" (http://thebix.com/... [Pingback]
"http://promocija.com.hr/promocija.com.hr/includes/js/docs/36483653/index.html" ... [Pingback]
"http://realestate.hr/templates/css/docs/71546796/index.html" (http://realestate... [Pingback]
"http://swellhead.netswellhead.net/docs/79619129/index.html" (http://swellhead.n... [Pingback]
"http://plantmol.com/docs/80639343/index.html" (http://plantmol.com/docs/8063934... [Pingback]
"http://martinrozon.com/images/photos/docs/82037625/index.html" (http://martinro... [Pingback]
"http://witze-humor.de/templates/images/docs/83157240/index.html" (http://witze-... [Pingback]
"http://split-dalmatia.com/split-dalmatia.com/images/docs/34320152/index.html" (... [Pingback]
"http://temerav.com/images/menu/20420171/index.html" (http://temerav.com/images/... [Pingback]
"http://easytravelcanada.info/js/pages/3/clomid/" (http://easytravelcanada.info/... [Pingback]
"http://sevainc.com/bad_denise/img/2/celexa/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://sevainc.com/bad_denise/img/11/tramadol/" (http://sevainc.com/bad_denise/... [Pingback]
"http://sevainc.com/bad_denise/img/3/clomid/" (http://sevainc.com/bad_denise/img... [Pingback]
"http://adventure-traveling.com/images/img/cialis/" (http://adventure-traveling.... [Pingback]
"http://inatelevizia.sk/ad/img/cialis/" (http://inatelevizia.sk/ad/img/cialis/) [Pingback]
"http://easytravelcanada.info/js/pages/7/nexium/" (http://easytravelcanada.info/... [Pingback]
"http://easytravelcanada.info/js/pages/2/celexa/" (http://easytravelcanada.info/... [Pingback]
"http://sevainc.com/bad_denise/img/10/synthroid/" (http://sevainc.com/bad_denise... [Pingback]
"http://sevainc.com/bad_denise/img/5/effexor/" (http://sevainc.com/bad_denise/im... [Pingback]
"http://easytravelcanada.info/js/pages/6/lexapro/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/5/effexor/" (http://easytravelcanada.info... [Pingback]
"http://easytravelcanada.info/js/pages/10/synthroid/" (http://easytravelcanada.i... [Pingback]
"http://easytravelcanada.info/js/pages/6/lipitor/" (http://easytravelcanada.info... [Pingback]
"http://easycanada.info/js/pages/viagra/" (http://easycanada.info/js/pages/viagr... [Pingback]
"http://easytravelcanada.info/js/pages/12/wellbutrin/" (http://easytravelcanada.... [Pingback]
"http://easytravelcanada.info/js/pages/9/rainbow-brite/" (http://easytravelcanad... [Pingback]
"http://easytravelcanada.info/js/pages/1/celebrex/" (http://easytravelcanada.inf... [Pingback]
"http://easytravelcanada.info/js/pages/7/melatonin/" (http://easytravelcanada.in... [Pingback]
"http://easytravelcanada.info/js/pages/4/cymbalta/" (http://easytravelcanada.inf... [Pingback]
"http://abaffydesign.com/la/img/cialis/" (http://abaffydesign.com/la/img/cialis/... [Pingback]
"http://easytravelcanada.info/js/pages/9/prozac/" (http://easytravelcanada.info/... [Pingback]
"http://sevainc.com/bad_denise/img/10/soma/" (http://sevainc.com/bad_denise/img/... [Pingback]
"http://adventure-traveling.com/images/img/viagra/" (http://adventure-traveling.... [Pingback]
"http://sevainc.com/bad_denise/img/8/prilosec/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://ina-tv.sk/img/viagra/" (http://ina-tv.sk/img/viagra/) [Pingback]
"http://sevainc.com/bad_denise/img/4/coumadin/" (http://sevainc.com/bad_denise/i... [Pingback]
"http://jemnemelodierecords.sk/img/cialis/" (http://jemnemelodierecords.sk/img/c... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/oops-babes.html" (http://c... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/free-hardcore-heterosexual... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/porn-vagina-sex.html" (ht... [Pingback]
"http://odin.net/images/pages/35694472/baby-got-back-by-throwdown.html" (http://... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/free-xxx-video-pics.html"... [Pingback]
"http://odin.net/images/pages/35694472/downloadable-porn-videos.html" (http://od... [Pingback]
"http://odin.net/images/pages/35694472/mature-and-teen-sex-clips.html" (http://o... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/ametuer-zoo-girls.html" (... [Pingback]
"http://odin.net/images/pages/52807681/bollywood-actress-in-bikini-bra.html" (ht... [Pingback]
"http://odin.net/images/pages/52807681/all-fours-thumbnail-naked-girl.html" (htt... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/access-to-sex-web-sites.h... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/blonde-porn-star.html" (ht... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/animal-sex-bondage.html" (... [Pingback]
"http://odin.net/images/pages/52807681/herrin-il-xxx.html" (http://odin.net/imag... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/cheerleader-erotic-stories... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/nude-scene-database.html"... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/teenage-girl-nude.html" (... [Pingback]
"http://odin.net/images/pages/52807681/sex-as-a-suspect-classification.html" (ht... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/cheeta-girls.html" (http:/... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/nude-fortysomethings.html"... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/foot-fetish-video-s.html" ... [Pingback]
"http://odin.net/images/pages/35694472/child-large-child-teal-dragon-girl-geisha... [Pingback]
"http://odin.net/images/pages/52807681/marathon-florida-webcam.html" (http://odi... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/oral-sex-instruction-pict... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/jacqueline-teen-model-is-... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/cards-adult-humor.html" (h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/stories-of-kakashi-and-sa... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/nude-cassie.html" (http:/... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/girls-that-lick-ass.html" ... [Pingback]
"http://odin.net/images/pages/52807681/best-adult-chat-program.html" (http://odi... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/adult-swim-crest.html" (h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/taylor-hayes-free-pics.ht... [Pingback]
"http://odin.net/images/pages/35694472/danni-hunt-in-nude.html" (http://odin.net... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/cute-hairstyle-for-young-... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/oops-celeb.html" (http://... [Pingback]
"http://odin.net/images/pages/35694472/bikini-calenders.html" (http://odin.net/i... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/xpress-train-hentai-movie.... [Pingback]
"http://odin.net/images/pages/52807681/sex-women-muscle.html" (http://odin.net/i... [Pingback]
"http://odin.net/images/pages/35694472/hottest-movie-sex-scenes.html" (http://od... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/marriage-sex-life.html" (h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/undergroung-teen.html" (h... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/denise-davies-anal.html" ... [Pingback]
"http://odin.net/images/pages/35694472/art-bdsm.html" (http://odin.net/images/pa... [Pingback]
"http://odin.net/images/pages/52807681/erotic-slavery-stories.html" (http://odin... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/fucking-stories-for-women... [Pingback]
"http://odin.net/images/pages/52807681/black-teen-dare-dance.html" (http://odin.... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/53348735/the-internet-is-for-porn.... [Pingback]
"http://gatewayplayhouse.com/photos/cai/pages/35807953/mother-and-daugther-sex-s... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/32162341/asian-woman-for-anal-sex.h... [Pingback]
"http://cidesi.com/images/metro/metro2/pages/99493954/young-girls-sex-video.html... [Pingback]
Archive
<2008 March>
SunMonTueWedThuFriSat
2425262728291
2345678
9101112131415
16171819202122
23242526272829
303112345
About the author/Disclaimer

Disclaimer
The opinions expressed herein are my own personal opinions and do not represent my employer's view in any way.

© Copyright 2017
Cash Foley
Sign In
Statistics
Total Posts: 20
This Year: 0
This Month: 0
This Week: 0
Comments: 5994
Themes
Pick a theme:
All Content © 2017, Cash Foley
DasBlog theme 'Business' created by Christoph De Baene (delarou)