Jump to content

getID3Tag and setID3Tag


Xenobiologist
 Share

Recommended Posts

Hi,

I wrote some small funcs to get it done. (getID3Tag and setID3Tag)

You need this dll --> cddbcontrol.dll

You can download from --> Download link

#include <array.au3>

Global $file = "C:\Downloads\Musik\Chris De Burg - Lady in Red.mp3"

_DLLstartup()
Global $re = _getID3Tag($file)
If @error Then MsgBox(0, 'Error', 'Error - no array returned', 5)
_ArrayDisplay($re)
_setID3Tag($file, 'TrackPosition', 100)
If @error Then MsgBox(0, 'Error', 'Error - setID3Tag', 5)
_setID3Tag($file, 'TitleAlbum', 'Mega')
If @error Then MsgBox(0, 'Error', 'Error - setID3Tag', 5)
$re = _getID3Tag($file)
If @error Then MsgBox(0, 'Error', 'Error - no array returned', 5)
_ArrayDisplay($re)
_DLLshutdown()

;===================================================================================================
============
; 'TitleAlbum', 'Movie', 'Title', 'CopyrightYear', 'CopyrightHolder', 'Comments', 'Label', 'BeatsPerMinute',
; 'LeadArtist', 'PartOfSet', 'TrackPosition', 'Year', 'Genre', 'FileId', 'ISRC'
;===================================================================================================
=============
Func _setID3Tag($h_file, $detail, $value)
    Local $oId3 = ObjCreate("CDDBControl.CddbID3Tag")
    If Not IsObj($oId3) Then
        SetError(1)
        Return 0
    EndIf
    ; False means open for read-write
    $oId3.LoadFromFile ($h_file, False)

    Switch $detail
        Case 'TitleAlbum'
            $oId3.Album = $value
        Case 'LeadArtist'
            $oId3.LeadArtist = $value
        Case 'Title'
            $oId3.Title = $value
        Case 'TrackPosition'
            $oId3.TrackPosition = $value
        Case 'Year'
            $oId3.Year = $value
        Case 'Genre'
            $oId3.Genre = $value
        Case 'Comments'
            $oId3.Comments = $value
        Case 'Label'
            $oId3.Label = $value
        Case 'FileID'
            $oId3.FileId = $value
        Case 'IRSC'
            $oId3.ISRC = $value
        Case 'CopyrightHolder'
            $oId3.CopyrightHolder = $value
        Case 'CopyrightYear'
            $oId3.CopyrightYear = $value
        Case 'PartOfSet'
            $oId3.PartOfSet = $value
        Case 'Movie'
            $oId3.Movie = $value
        Case 'BeatsPerMinute'
            $oId3.BeatsPerMinute = $value
        Case Else
            SetError(2)
            Return 0
    EndSwitch
    $oId3.SaveToFile ($h_file)
    Return 1
EndFunc   ;==>_setID3Tag

Func _getID3Tag($h_file)
    Local $oId3 = ObjCreate("CDDBControl.CddbID3Tag")
    If Not IsObj($oId3) Then
        SetError(1)
        Return 0
    EndIf
    $oId3.LoadFromFile ($h_file, False)
    Local $idTag_A[15][2]
    $idTag_A[0][0] = 'Title'
    $idTag_A[0][1] = $oId3.Title
    $idTag_A[1][0] = 'LeadArtist'
    $idTag_A[1][1] = $oId3.LeadArtist
    $idTag_A[2][0] = 'Album'
    $idTag_A[2][1] = $oId3.Album
    $idTag_A[3][0] = 'TrackPosition'
    $idTag_A[3][1] = $oId3.TrackPosition
    $idTag_A[4][0] = 'Year'
    $idTag_A[4][1] = $oId3.Year
    $idTag_A[5][0] = 'Genre'
    $idTag_A[5][1] = $oId3.Genre
    $idTag_A[6][0] = 'Comments'
    $idTag_A[6][1] = $oId3.Comments
    $idTag_A[7][0] = 'Label'
    $idTag_A[7][1] = $oId3.Label
    $idTag_A[8][0] = 'FileId'
    $idTag_A[8][1] = $oId3.FileId
    $idTag_A[9][0] = 'ISRC'
    $idTag_A[9][1] = $oId3.ISRC
    $idTag_A[10][0] = 'CopyrightHolder'
    $idTag_A[10][1] = $oId3.CopyrightHolder
    $idTag_A[11][0] = 'CopyrightYear'
    $idTag_A[11][1] = $oId3.CopyrightYear
    $idTag_A[12][0] = 'PartOfSet'
    $idTag_A[12][1] = $oId3.PartOfSet
    $idTag_A[13][0] = 'Movie'
    $idTag_A[13][1] = $oId3.Movie
    $idTag_A[14][0] = 'BeatsPerMinute'
    $idTag_A[14][1] = $oId3.BeatsPerMinute
    Return $idTag_A
EndFunc   ;==>_getID3Tag

Func _DLLstartup($DLLpath = '')
    If $DLLpath = Default Or $DLLpath = '' Then $DLLpath = @ScriptDir & '\cddbcontrol.dll'
    RunWait('regsvr32 /s ' & '"' & $DLLpath & '"')
EndFunc   ;==>_DLLstartup

Func _DLLshutdown($DLLpath = '')
    If $DLLpath = Default Or $DLLpath = '' Then $DLLpath = @ScriptDir & '\cddbcontrol.dll'
    RunWait('regsvr32 /u /s ' & '"' & $DLLpath & '"')
EndFunc   ;==>_DLLshutdown

So long,

Mega

Edited by Xenobiologist

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • Replies 45
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

Looks good, I've been thinking of writing something to organize my music better and fix incorrect artists.

thanks

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Hi,

okay ;) so there might be some people who can use it. Nice! :)

Feel free to improve ...

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

HI,

thanks!

German forum somebody asked me whether it supports v1 or v2. So, I started to investigate :) , cause I didn't know the difference before.

It only supports v1, I suppose.

Anybody who knows a good dll, to write some udfs for id3 v2, too?

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

HI,

thanks!

German forum somebody asked me whether it supports v1 or v2. So, I started to investigate :) , cause I didn't know the difference before.

It only supports v1, I suppose.

Anybody who knows a good dll, to write some udfs for id3 v2, too?

So long,

Mega

You said on post #1 that it supports ID2 and ID3. is it 2 and 3 or just 1?

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

HI,

sorry. :) I do not know the difference. Look at the code what can be read and be written.

That is all.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

HI,

sorry. :) I do not know the difference. Look at the code what can be read and be written.

That is all.

So long,

Mega

LOL, it's cool, I'm going to try to write a script with this anyways today. So I will let ya know.

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

Well It seems to read ID3V1 and ID3V2 but only writes ID3V1.

I could be wrong, anyone an expert on ID3???

[center]AutoIT + Finger Print Reader/Scanner = COOL STUFF -> Check Out Topic![/center][center][font=Arial Black]Check out ConsultingJoe.com[/font][/center][center]My Scripts~~~~~~~~~~~~~~Web Protocol Managing - Simple WiFi Scanner - AutoTunes - Remote PC Control V2 - Audio SpectrascopePie Chart UDF - At&t's TTS - Custom Progress Bar - Windows Media Player Embed[/center]

Link to comment
Share on other sites

I'm going to add this to audio.au3. (If that is ok with you....)

Hi,

if you speak to me then - of course. Feel free to do work with it.

So long,

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

  • 10 months later...

Show your code, please.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

I was wrong error returned is 0

Show your code, please.

Mega

_DLLstartup()
Local $MP3FileList = _FileListToArray("C:\Documents and Settings\Deltaforce229\My Documents\My Music\","*.mp3")
GUICtrlSetData($Status, "Fixing MP3 files...")
For $i = 1 to $MP3FileList[0]
    $PercentComplete = Round(($i / $MP3FileList[0]) * 100)
    $Artist = " - " & $MP3FileList[$i]
    $Artist = _StringBetween($Artist," - "," - ")
    $Title = _StringBetween($MP3FileList[$i]," - ",".mp3")
    _setID3Tag("C:\Documents and Settings\Deltaforce229\My Documents\My Music\" & $MP3FileList[$i],'Artist',$Artist[0])
    _setID3Tag("C:\Documents and Settings\Deltaforce229\My Documents\My Music\" & $MP3FileList[$i],'Title',$Title[0])
    GUICtrlSetData($ProgressBar, $PercentComplete)
Next
_DLLshutdown()

EDIT: Never mind I figured out what I was doing wrong, I was using 'Artist' instead of 'LeadArtist'.

EDIT: Ok now I'm getting this error using the code above with leadartist instead of artist.

C:\Source\Autoit\ID3 Fixer\ID3 Fixer.au3 (62) : ==> The requested action with this object has failed.:

$oId3.SaveToFile ($h_file)

$oId3.SaveToFile ($h_file)^ ERROR

Edited by Deltaforce229

[size="1"]Please stop confusing "how to" with "how do"[/size]

Link to comment
Share on other sites

Hi,

I cannot reproduce your problem. Maybe you can script a little running example for testing.

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

The script below is supposed to fix the ID3 artist and title based on the file format 'artist - title.mp3' so that the music would work with my phone.

#Include <Array.au3>
#include <String.au3>
#Include <File.au3>
#Include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <ProgressConstants.au3>
#include <WindowsConstants.au3>

Local $ProgressGUI = GUICreate("ID3 Fixer", 501, 41, -1, -1, BitOR($WS_CAPTION,$WS_POPUP,$WS_BORDER,$WS_CLIPSIBLINGS), 0)
Local $Status = GUICtrlCreateLabel("Gathering mp3 files please wait...",0, 0, 500, 20)
Local $ProgressBar = GUICtrlCreateProgress(0, 20, 500, 20)
GUISetState(@SW_SHOW)

_DLLstartup()
Local $MP3FileList = _FileListToArray("C:\Documents and Settings\Deltaforce229\My Documents\My Music\","*.mp3")
GUICtrlSetData($Status, "Fixing MP3 files...")
For $i = 1 to $MP3FileList[0]
    $PercentComplete = Round(($i / $MP3FileList[0]) * 100)
    $Artist = "-" & $MP3FileList[$i]
    $Artist = _StringBetween($Artist,"-"," - ")
    $Title = _StringBetween($MP3FileList[$i]," - ",".mp3")
    ConsoleWrite(_setID3Tag("C:\Documents and Settings\Deltaforce229\My Documents\My Music\" & $MP3FileList[$i],'LeadArtist',$Artist[0]))
    ConsoleWrite(_setID3Tag("C:\Documents and Settings\Deltaforce229\My Documents\My Music\" & $MP3FileList[$i],'Title',$Title[0]))
    ConsoleWrite(_setID3Tag("C:\Documents and Settings\Deltaforce229\My Documents\My Music\" & $MP3FileList[$i],'TitleAlbum',''))
    ConsoleWrite(_setID3Tag("C:\Documents and Settings\Deltaforce229\My Documents\My Music\" & $MP3FileList[$i],'Genre',''))
    GUICtrlSetData($ProgressBar, $PercentComplete)
Next
_DLLshutdown()

Func _setID3Tag($h_file, $detail, $value)
    Local $oId3 = ObjCreate("CDDBControl.CddbID3Tag")
    If Not IsObj($oId3) Then
        SetError(1)
        Return 0
    EndIf
  ; False means open for read-write
    $oId3.LoadFromFile ($h_file, False)

    Switch $detail
        Case 'TitleAlbum'
            $oId3.Album = $value
        Case 'LeadArtist'
            $oId3.LeadArtist = $value
        Case 'Title'
            $oId3.Title = $value
        Case 'Genre'
            $oId3.Genre = $value
        Case Else
            SetError(2)
            Return 0
    EndSwitch
    $oId3.SaveToFile ($h_file)
    Return 1
EndFunc ;==>_setID3Tag

Func _DLLstartup($DLLpath = '')
    If $DLLpath = Default Or $DLLpath = '' Then $DLLpath = @ScriptDir & '\cddbcontrol.dll'
    ShellExecuteWait('regsvr32', '/s /i ' & $DLLpath, @WindowsDir, 'open', @SW_HIDE)
EndFunc ;==>_DLLstartup

Func _DLLshutdown($DLLpath = '')
    If $DLLpath = Default Or $DLLpath = '' Then $DLLpath = @ScriptDir & '\cddbcontrol.dll'
    ShellExecuteWait('regsvr32', ' /s /u ' & $DLLpath, @WindowsDir, 'open', @SW_HIDE)
EndFunc ;==>_DLLshutdown
Edited by Deltaforce229

[size="1"]Please stop confusing "how to" with "how do"[/size]

Link to comment
Share on other sites

Hi,

so what did you change? What was the problem? Problem in my code, or your fault?

Mega

Scripts & functions Organize Includes Let Scite organize the include files

Yahtzee The game "Yahtzee" (Kniffel, DiceLion)

LoginWrapper Secure scripts by adding a query (authentication)

_RunOnlyOnThis UDF Make sure that a script can only be executed on ... (Windows / HD / ...)

Internet-Café Server/Client Application Open CD, Start Browser, Lock remote client, etc.

MultipleFuncsWithOneHotkey Start different funcs by hitting one hotkey different times

Link to comment
Share on other sites

If any of you are interested in peering at some C++ code, there's a slick little MP3 tag editor/shell extension that I've found handy for years. It's called MP3ext and it handles ID3 V1 and V2, along with lots of other nifty functions (I love the icons that indicate bitrate). The program was fairly mature when the author ceased development on it a few years ago and has made it (along with the source code) avail as "giftware". Am guessing you might gleen some answers from peeking at his .cpp and .h files...

Just google MP3ext and you'll find his German site.

Edited by Spiff59
Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...