title
Products            Purchase            Codec Central            Forum & Support            Professional            About
  
Results 1 to 8 of 8

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

  1. #1
    Da Man
    Join Date
    Apr 2002
    Posts
    36,564

    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 at 06:36 AM.

  2. #2
    dBpoweramp Guru
    Join Date
    Dec 2008
    Location
    London, UK
    Posts
    2,969

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

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

  3. #3
    Da Man
    Join Date
    Apr 2002
    Posts
    36,564

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

    About to go into beta today, will be here:

    http://forum.dbpoweramp.com/showthre...gg-Wavpack-etc

  4. #4

    Join Date
    Dec 2007
    Posts
    13

    Re: External Tag Scripting (ID Tag Processing & 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.

  5. #5
    Da Man
    Join Date
    Apr 2002
    Posts
    36,564

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

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

  6. #6

    Join Date
    Dec 2007
    Posts
    13

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

    Quote Originally Posted by Spoon View Post
    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.

  7. #7

    Join Date
    Sep 2010
    Posts
    24

    Re: External Tag Scripting (ID Tag Processing & 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 at 02:37 PM.

  8. #8
    Da Man
    Join Date
    Apr 2002
    Posts
    36,564

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

    Thank you

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright 2018 Illustrate. All Rights Reserved.