title
Products            Buy            Support Forum            Professional            About            Codec Central
 

External Tag Scripting (ID Tag Processing & Update ID Tag)

Collapse
This is a sticky topic.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Spoon
    Administrator
    • Apr 2002
    • 43891

    External Tag Scripting (ID Tag Processing & Update ID Tag)

    The utility codec [ID Tag Update] (R4 or later) and the DSP effect ID Tag Processing (R10 or later) contain an option Externally Script Tags

    Externally scripting allows tag actions to take place which could not otherwise be accommodated in dBpoweramp, the scripting language (in this example uses VB Scripting) can do almost anything to the tags. The following example simply replaces the Artist with "abc"

    A command line is specified for this value, for example:

    cscript.exe "z:\tag.vbs" "%idtagstxt%"

    This runs the program cscript.exe which in turn executes the Tag.vbs script. The value %idtagstxt% is replaced by the filename of a temporary unicode text file containing the ID Tags, an example:

    Code:
    Title=What Up Gangsta
    replaygain_album_gain=-10.96 dB
    replaygain_album_peak=1
    AccurateRipResult=AccurateRip: Accurate (confidence 143)   [6E45E560]
    AccurateRipDiscID=019-002dabb6-028d652e-2b105113-2
    Year=2003 02 06
    Composer=Rob Tewlow
    UPC=606949354428
    Style=Hardcore Rap
    Album=Get Rich or Die Tryin'
    Genre=Rap
    Artist=50 Cent{_MUL_}Artist2
    Rating=7
    replaygain_track_gain=-10.19 dB
    replaygain_track_peak=0.952637
    Track=2/19
    Disc=1/1
    Album Artist=50 Cent
    _albumart_1_Front Album Cover=z:\tmpusr\dbpA532.tmp\18.bin
    Each tag line has an element=value

    Album art is listed as: _albumart_1xxxxxxxxx _albumart_2xxxxxxxxxx the latter part of the art element name represents the art type:

    Code:
    32x32 Icon,				(apic 1)
    Other Icon,				(apic 2)
    Front Album Cover,		(apic 3)
    Back Album Cover, 		(apic 4)
    Leaflet Page, 			(apic 5)
    Media >>CD image<<, 	(apic 6)
    Lead Artist,			(apic 7)
    Artist,					(apic 8)
    Conductor, 				(apic 9)
    Band, 					(apic 10)
    Composer, 				(apic 11)
    Writer, 				(apic 12)
    Recording Location,		(apic 13)
    During Recording,		(apic 14)
    During Performance,		(apic 15)
    Video Capture,			(apic 16)
    Illustration,			(apic 18)
    Artist Logo,			(apic 19)
    Publisher Logo 			(apic 20)
    The code in the vb script tag.vbs:

    Code:
    Const ForReading = 1, ForWriting = 2, ForAppending = 8
    
    on error resume next
    
    ' ----------------get the filename from dbpoweramp-----------------
    Dim args, IDTagsTXT
    set args = Wscript.arguments
    IDTagsTXT = args(0)
    
    ' ------------------ load the tags -------------------------------
    Dim Elements(), Values()
    LoadTags Elements, Values, IDTagsTXT
    
    
    ' in this example we find the artist tag and set to abc
    Dim IndexTag
    IndexTag = GetTagIdx ("aRtist", Elements)
    if IndexTag > -1 THEN
        Values(IndexTag) = "abc"
    end if
    
    
    SaveTags Elements, Values, IDTagsTXT
    
    '-----------------------------------------------------------------------
    '-----------------------------------------------------------------------
    '-----------------------------------------------------------------------
    '-----------------------------------------------------------------------
    '-----------------------------------------------------------------------
    '-----------------------------------------------------------------------
    '-----------------------------------------------------------------------
    
    '------------------load the tags to the array----------------------------
    Sub LoadTags(Elements(), Values(), IDTagsTXT)
        Dim fso, objFileRead, TagCount
        TagCount = 0
    
        Set fso = CreateObject("Scripting.FileSystemObject")
        Set objFileRead = fso.OpenTextFile(IDTagsTXT, ForReading, 0, -1)
    
        Do While objFileRead.AtEndOfStream <> True
            Dim Line, EqualPos, TagName, TagValue
            Line = objFileRead.ReadLine
    
            EqualPos = InStr(1, Line, "=", vbTextCompare)
    
            If EqualPos > 0 Then
                TagName = Left(Line, EqualPos -1)
                TagValue = Right(Line, Len(Line) - EqualPos)
                AddTag Elements, Values, TagName, TagValue, TagCount        
            End If
    
        Loop
    
        objFileRead.Close()
    End Sub
    
    '------------------Save the tags to the array----------------------------
    Sub SaveTags (Elements(), Values(), IDTagsTXT)
        Dim fso, objFileRead, TagCount
        TagCount = 0
        Set fso = CreateObject("Scripting.FileSystemObject")
        fso.DeleteFile(IDTagsTXT)
    
        Set objFileRead = fso.OpenTextFile(IDTagsTXT, ForWriting, true, -1)
    
        for i = 0 to UBound(Elements)
            if (Len(Elements(i)) > 0) Then
                Dim ToWrite
                ToWrite = Elements(i) + "=" + Values(i)
                objFileRead.WriteLine(ToWrite)
            End if
        next
    
        objFileRead.Close()
    End Sub
    
    '------------------adds a tag to the array----------------------------
    Sub AddTag (Elements(), Values(), Element, Value, ByRef TagCount)
        if (Len(Element) > 0) then 
        	ReDim Preserve Elements(TagCount + 1)
    	    ReDim Preserve Values(TagCount + 1)
    	    Elements(TagCount) = Element
    	    Values(TagCount) = Value
            TagCount = TagCount + 1
        end if
    End Sub
    
    '------------------finds a tag index, returns -1 if not there----------------------------
    Function GetTagIdx (Need, Elements())
    	GetTagIdx = -1
    	For i = 0 to Ubound(Elements)
            If StrComp(Elements(i), Need, vbTextCompare) = 0 Then 
                GetTagIdx = i
                Exit for
            End if
    	Next
    End Function
    Last edited by Spoon; 06-06-2016, 10:36 AM.
    Spoon
    www.dbpoweramp.com
  • mville
    dBpoweramp Guru
    • Dec 2008
    • 4015

    #2
    Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

    Where do we download the utility codec [ID Tag Update] R4?

    Comment

    • Spoon
      Administrator
      • Apr 2002
      • 43891

      #3
      Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

      About to go into beta today, will be here:

      These installs contain both 64 bit install (for dBpoweramp R15 beta 64 bit) and 32 bit installs. By default the install will match your dBpoweramp (32 bit or 64 bit). AAC Encoder Now Released: http://www.dbpoweramp.com/codec-central-m4a.htm CLI Encoder Now Released: http://www.dbpoweramp.com/codec-central-cli.htm m4a &amp;
      Spoon
      www.dbpoweramp.com

      Comment

      • tahel
        • Dec 2007
        • 13

        #4
        Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

        Hi,
        Do you have any tips for adding debugging to scripts?
        I tried adding a log method, but no file gets written.

        I'm not a fan of a single file log since I am running on multiple cores and I will quickly get into locking trouble.

        Comment

        • Spoon
          Administrator
          • Apr 2002
          • 43891

          #5
          Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

          I am not 100% sure what you are trying to do with the debug log.
          Spoon
          www.dbpoweramp.com

          Comment

          • tahel
            • Dec 2007
            • 13

            #6
            Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

            Originally posted by Spoon
            I am not 100% sure what you are trying to do with the debug log.
            A few of my tracks (3-10 out of a few thousand) emerge from the conversion with missing ID tags. I want to figure out why this is happening.
            A debug log is not that important, but an error log would be nice, so I've added an If Err and a section to write some debug info to file. To test out my file writing routine I started with a debug log, which in which I'm just writing artist and album title to a file. I get neither the error log nor the debug log where I specified.

            I could switch to python or something else, but your example vb script is serviceable and was easy to modify for my needs.
            What I'm doing is replacing the artist tag with artist + album title. I need this because my in-car audio system will only display artist and title from bluetooth and the artist field has some room for more info.

            Comment

            • TimR
              • Sep 2010
              • 24

              #7
              Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

              Hi,

              There is a small problem with the code in the LoadTags() subroutine presented in the first post above. Specifically it won't handle an "=" in tags.
              Although uncommon there are tags with "=" in them, so I thought I'd post my code as many people will likely use the original code above verbatim when getting started (I know I did!).

              I happened to find the issue because (like tahel above) I saw a few files out of 1000s that I processed had missing/corrupted tags. During debugging I traced the issue to the LoadTags() subroutine.

              There are two issues that occur in the following code section of LoadTags():
              Code:
                          If Count = 2 Then
                              AddTag Elements, Values, Splitted(0), Splitted(1), TagCount
                          End If
              1. Because a check is made on the Spitted array to make sure that only two elements exist, if an "=" exists in the tag value then the tag never gets loaded as Count > 2. Since the tag never gets loaded it also never gets written back out and is lost.
              2. Even correcting the above, the arguments to AddTag only use the first two elements of Splitted, so anything after the "=" would still get lost.


              A revised LoadTags routine that corrects both of the above and allows correct processing of tags with and "=" in their value is as follows:

              Code:
              '------------------load the tags to the array----------------------------
              Sub LoadTags(Elements(), Values(), IDTagsTXT)
                  Dim fso, objFileRead, TagCount
                  TagCount = 0
              
                  Set fso = CreateObject("Scripting.FileSystemObject")
                  Set objFileRead = fso.OpenTextFile(IDTagsTXT, ForReading, 0, -1)
              
                  Do While objFileRead.AtEndOfStream <> True
                      Dim Line, EqualPos, TagName, TagValue
                      Line = objFileRead.ReadLine
              
                      EqualPos = InStr(1, Line, "=", vbTextCompare)
              
                      If EqualPos > 0 Then
                          TagName = Left(Line, EqualPos -1)
                          TagValue = Right(Line, Len(Line) - EqualPos)
                          AddTag Elements, Values, TagName, TagValue, TagCount        
                      End If
              
                  Loop
              
                  objFileRead.Close()
              End Sub
              Hope that helps someone.

              Tim
              Last edited by TimR; 04-04-2015, 06:37 PM.

              Comment

              • Spoon
                Administrator
                • Apr 2002
                • 43891

                #8
                Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

                Thank you
                Spoon
                www.dbpoweramp.com

                Comment

                • hvaleton
                  • Oct 2010
                  • 9

                  #9
                  Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

                  Hi Spoon,

                  I am not sure I understand what this "external tag scripting" actually accomplishes. It looks to me that it only alters a TXT file containing a list of tags and their values. (Should one have prepared such a file manually beforehand?)
                  Where is it indicated of which music file the tags are altered? And what does all of this have to do with the ID Tag Update Utility Codec that I've installed today and that I can now use in the Conversion tool. (very handy!)
                  But that's still not what I'd really like to do.
                  My ideal is to use one of my MediaMonkey scripts (VBScript) to call an external tool such as dBPowerAmp's converter in conjunction with the ID Tag Update Utility Codec, and in this way add new tags to a number of music files.
                  These would be tags that MediaMonkey does not support natively, such as WORK, SECTION, MOVEMENT, PERSONNEL, RECORDINGSTARTDATE, RECORDINGENDDATE, RECORDINGLOCATION, etc.
                  Could you help me, please? I'm very much confused!

                  Thanks in advance, regards,
                  Hans Valeton

                  Comment

                  • hvaleton
                    • Oct 2010
                    • 9

                    #10
                    Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

                    Hello again, Spoon,

                    I think I've come a little bit further than yesterday with my investigations into scripting the ID Tag Update Utility from within a MediaMonkey VBS script. But...
                    I constantly get this error:
                    "ActiveX component cannot create object: 'dMCScripting.Converter'"

                    I have used the following part of the code I found here in my script:
                    Code:
                    ' create shell object
                    Set WshShell = CreateObject("WScript.Shell")
                    
                    ' Create dMC Object
                    Set dMC = CreateObject("dMCScripting.Converter")
                    
                    ' Read All IDTags
                    For i = 0 To 10000
                     Dim ElementValue
                     ElementValue = dMC.ReadIDTagElementValue("M:\1_KLAS\ZZ_Verzamel\Pianotrio\Gál, Shostakovich - Piano Trios (Briggs Piano Trio 2018)\01 Piano Trio in E major, Op. 18_ I. Tranquillo ma con moto.flac", i)
                     If ElementValue = "" Then Exit For
                     Call WshShell.Popup(ElementValue, , "Read Tag", 0)
                    Next
                    OS: Windows 10 build 1809, 64bit
                    Mediamonkey version 4.1.28.1905
                    dBpoweramp release 17 [64 bit]

                    What can I do to have the MediaMonkey script create the dMC Object successfully?

                    Thanks in advance!
                    Regards, Hans Valeton

                    Comment

                    • Spoon
                      Administrator
                      • Apr 2002
                      • 43891

                      #11
                      Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

                      You would not run dMCScripting. The code above is for when converting inside dBpoweramp, it allows the tags to be written to a text file, that text file can be modified outside of dBpoweramp, which then reads the text file back in and uses those tags whilst converting.

                      This will not work though media monkey.
                      Spoon
                      www.dbpoweramp.com

                      Comment

                      • d_m_g_3
                        • Mar 2022
                        • 4

                        #12
                        Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

                        Are these instructions still valid for R16 with ID Tag Update R5?
                        I'm trying to use Run External to modify some tags before the Move Destination File plugin runs
                        I've selected "After Conversion"
                        I've set the command line to pass in %idtagstxt% in the args but when my program tries to expand that environment variable, it doesn't appear to be set.
                        There's some text on the UI that talks about supplying [infile], [outfile], [infilelong] and [outfilelong] on the commandline but I can't find documentation on what this means.

                        Any help appreciated

                        thank you

                        Comment

                        • Spoon
                          Administrator
                          • Apr 2002
                          • 43891

                          #13
                          Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

                          This option is in ID Tag Processing DSP >> manipulation tab
                          Spoon
                          www.dbpoweramp.com

                          Comment

                          • d_m_g_3
                            • Mar 2022
                            • 4

                            #14
                            Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

                            Originally posted by Spoon
                            This option is in ID Tag Processing DSP >> manipulation tab
                            Yes, not sure how I got these mixed up.

                            For anyone else out there using this, it's worth noting that when you write the tags back to the file, it needs to be written in UTF16 Little Endian otherwise the ripper sets all the tags to blank.

                            Thanks for your help Spoon

                            Comment

                            • ForSerious
                              dBpoweramp Enthusiast
                              • Aug 2017
                              • 82

                              #15
                              Re: External Tag Scripting (ID Tag Processing &amp; Update ID Tag)

                              "%idtagstxt%" gets defined as a path to a real txt file, but it's always empty. I have ID Tag Processing as the only DSP. I do have some other manipulations set in it. Would that be why the txt file is always empty for me?
                              Because the txt file is empty, all the tags get deleted once everything is done processing.
                              Last edited by ForSerious; 12-20-2023, 06:14 PM.

                              Comment

                              Working...

                              ]]>