|
|
发表于 2013-7-24 18:31:00
|
显示全部楼层
我网上搜的,打把,简单吧,
http://www.powershell.nu/2009/09 ... through-powershell/
http://vallery.net/2012/04/27/or ... ic-with-powershell/
http://tomorrow.uspeoples.org/20 ... ing-via-taglib.html
----------------------------------------------------------
Download the latest taglib: http://download.banshee.fm/taglib-sharp/
#Create a variable for the tag-lib dll file
$taglib = "C:\PowerShell\taglib\libraries\taglib-sharp.dll"
#Load it into Powershell
[system.reflection.assembly]::loadfile($taglib)
#Find an MP3 and either assign it to a variable or put it's name into the create field
$media = [taglib.file]::create("e:\test\body.mp3")
#Now you can view, edit, and save ID3 information
PS E:\test> $media.properties
Codecs : {TagLib.Mpeg.AudioHeader}
Duration : 00:05:12.3120000
MediaTypes : Audio
Description : MPEG Version 1 Audio, Layer 3
AudioBitrate : 128
AudioSampleRate : 44100
BitsPerSample : 0
AudioChannels : 2
VideoWidth : 0
VideoHeight : 0
PhotoWidth : 0
PhotoHeight : 0
PhotoQuality : 0
Compare Taglib field entries to Windows Explorers Detail tab:
PS E:\test> $media.tag
StartTag : TagLib.NonContainer.StartTag
EndTag : TagLib.NonContainer.EndTag
TagTypes : Id3v1, Id3v2
Tags : {, }
Title : Body
Performers : {Bush}
PerformersSort : {}
AlbumArtistsSort : {}
AlbumArtists : {Bush}
Composers : {Gavin Rossdale}
ComposersSort : {}
TitleSort :
AlbumSort :
Album : Sixteen Stone
Comment :
Genres : {Alternative}
Year : 1994
Track : 6
TrackCount : 0
Disc : 1
DiscCount : 1
Lyrics :
Grouping :
BeatsPerMinute : 0
Conductor :
Copyright :
MusicBrainzArtistId :
MusicBrainzReleaseId :
MusicBrainzReleaseArtistId :
MusicBrainzTrackId :
MusicBrainzDiscId :
MusicIpId :
AmazonId :
MusicBrainzReleaseStatus :
MusicBrainzReleaseType :
MusicBrainzReleaseCountry :
Pictures : {}
IsEmpty : False
Artists : {Bush}
FirstArtist : Bush
FirstAlbumArtist : Bush
FirstAlbumArtistSort :
FirstPerformer : Bush
FirstPerformerSort :
FirstComposerSort :
FirstComposer : Gavin Rossdale
FirstGenre : Alternative
JoinedArtists : Bush
JoinedAlbumArtists : Bush
JoinedPerformers : Bush
JoinedPerformersSort :
JoinedComposers : Gavin Rossdale
JoinedGenres : Alternative
PS E:\test> $media.properties.duration
Days : 0
Hours : 0
Minutes : 5
Seconds : 12
Milliseconds : 312
Ticks : 3123120000
TotalDays : 0.00361472222222222
TotalHours : 0.0867533333333333
TotalMinutes : 5.2052
TotalSeconds : 312.312
TotalMilliseconds : 312312
#An example of how I load variables from my music files
$filename = $file.basename
$fileextension = $file.name.split('.')[1]
$filetitle = $media.tag.title
$fileperformers = $media.tag.performers
$filealbumartists = $media.tag.albumartists
$filealbum = $media.tag.album
$filegenres = $media.tag.genres
$fileyear = $media.tag.year
$filetrack = $media.tag.track
$filetrackcount = $media.tag.trackcount
$fileaudiobitrate = $media.properties.audiobitrate
$fileconductor = $media.tag.conductor
$filecomposers = $media.tag.Composers
$fileBPM = $media.tag.BeatsPerMinute
$filedurationminutes = $media.properties.duration.minutes
$filedurationseconds = $media.properties.duration.seconds
$filedurationtotalseconds = $media.properties.duration.totalseconds
#Here's a way to clean the title tag. It cleans the annoying buggy brackets
#then it restricts all characters except the ranges inside the brackets
#Lifted clip explaining some regex expressions:
# Expression:
# ([0-9a-zA-Z\.]+) --> Gets all chars, numbers and '.'. Discard comma and others.
if ($filetitle){
$filetitle = $filetitle -replace ("\[","")
$filetitle = $filetitle -replace ("\]","")
$filetitle = $filetitle -replace ("[^0-9a-zA-Z-&\']"," ")}
#inserting Album Photo:
#(requires PowerShell 3.0 for this album photo catching section)
#To populate the picture tag, I call upon Discogs API via Invoke-Restmethod
#Please refer to the Discogs developer pages for information how to search for your music
#In this example, I used the weighted results and select the first hit for my album search
$filealbum = $media.tag.album
$apialbum = $filealbum -replace (' ','%20')
$albumfound = (invoke-restmethod http://api.discogs.com/database/search?title=$apialbum).results[0]
$thumb = $currentfolder + "\" + $albumfound.thumb.split('/')[-1]
invoke-webrequest -uri $albumfound.thumb -outfile $thumb
$pic = $pic + [taglib.picture]::createfrompath("$thumb")
#writing back to the file
$media.tag.title = [string]$filetitle
$media.tag.performers = [string]$fileperformers
$media.tag.albumartists = [string]$filealbumartists
$media.tag.album = [string]$filealbum
$media.tag.genres = [string]$filegenres
$media.tag.year = $fileyear
$media.tag.track = [string]$filetrack
$media.tag.trackcount = [string]$filetrackcount
$media.tag.conductor = [string]$fileconductor
$media.tag.composers = [string]$filecomposers
$media.tag.BeatsPerMinute = [string]$filebpm
$media.tag.pictures = $pic
$media.save() |
|