找回密码
 注册
搜索
[新手上路]批处理新手入门导读[视频教程]批处理基础视频教程[视频教程]VBS基础视频教程[批处理精品]批处理版照片整理器
[批处理精品]纯批处理备份&还原驱动[批处理精品]CMD命令50条不能说的秘密[在线下载]第三方命令行工具[在线帮助]VBScript / JScript 在线参考
查看: 19982|回复: 2

[问题求助] PowerShell怎样删除mp3文件属性中的部分信息?

[复制链接]
发表于 2013-7-23 22:44:50 | 显示全部楼层 |阅读模式
我从www.guodashi.com下载了一些郭德纲相声的mp3文件,但是文件属性里面有些信息我想删掉,比如:

PowerShell怎样实现?
发表于 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()
 楼主| 发表于 2013-7-24 20:24:07 | 显示全部楼层
回复 2# PowerShell


    英语不行,看不懂。能否帮忙写一个可以直接拿来执行的?我试试,然后体会一下。
您需要登录后才可以回帖 登录 | 注册

本版积分规则

Archiver|手机版|小黑屋|批处理之家 ( 渝ICP备10000708号 )

GMT+8, 2026-3-17 02:51 , Processed in 0.017576 second(s), 8 queries , File On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表