[MM3 Script] Simple Append [2009-04-10]

Download and get help for different MediaMonkey Addons.

Moderators: Peke, Gurus

Re: [MM3 Script] Simple Append [2009-04-10]

Postby thefaceman » Thu Sep 15, 2011 2:58 pm

Lowlander wrote:
thefaceman wrote:I get an error - Product Installation error
See: http://www.mediamonkey.com/support/inde ... ticleid=59


WOW - That was FAST and EASY and WORKED. I greatly THANK YOU for making a bad day go better. Little bits of help like this forum really go a LONG way.

-thefaceman
thefaceman
 
Posts: 367
Joined: Sun Aug 28, 2005 10:43 pm

Re: [MM3 Script] Simple Append [2009-04-10]

Postby Nanya » Thu Oct 04, 2012 11:52 pm

I made some modifications to this script, which makes it more of a "Simple Insert" rather than just append and prepend.

1: Now includes option to insert in the middle of the string, just specify an index!
2: Don't want/need a space added when you insert your string? There's a checkbox for that!
3: Simplified the code that applies the new data.

If you find this code useful/helpful, please let me know, I'm new at this!
Code: Select all
Option Explicit
'==========================================================================
'
' MediaMonkey Script
'
' SCRIPTNAME: Simple Append
' INITIAL VERSION: 2009.01.09
  Dim Version : Version = "2009.04.10.1600"

' DESCRIPTION: simple dialog to append or pre-pend user text to specified field
' FORUM THREAD: http://www.mediamonkey.com/forum/viewtopic.php?f=2&t=36013

' [SimpleAppend]
' filename=simpleappend.vbs
' procname=start
' displayname=Simple Append
' language=vbscript
' scripttype=0
 
' INSTALL:
' - download install package @ http://teknojnky.googlepages.com/simpleappend.mmip
' - activate via script menu'

' Initial Release:
'   Due to apparent problem saving stringvalue with leading/trailing spaces
'   there is a space hard coded in'

' Recent Updates:
'   * fixed type error
'
'   * added genre, classifcations and custom fields'
'   * forgot to disabled resize'

  Dim MainForm, UserText, Action, Field, FieldText, Preview, SongList
  Preview = ""
  ''''''''''''''''''''''''
  Dim indexField, Index, spaceBox, Space
  Index = 0
  ''''''''''''''''''''''''
 
Sub Start()

  Set Songlist = SDB.CurrentSongList
  If Songlist.Count > 0 Then
    Set MainForm = SDB.UI.NewForm
      MainForm.Caption = "Simple Append/Pre-pend"
      MainForm.Common.SetRect 200, 200, 600, 100
      MainForm.FormPosition = 4
      MainForm.BorderStyle = 3
      MainForm.StayOnTop = True
      MainForm.SavePositionName = "SimpleAppend"
 
    Dim DropAction
    Set DropAction = SDB.UI.NewDropDown(MainForm)
      DropAction.Common.ControlName = "Action"
      DropAction.Common.Hint = "Action"
      DropAction.Style = 2
      DropAction.Common.SetRect 10, 10, 100, 30
      DropAction.AddItem("Append (to end)")
      DropAction.AddItem("PrePend (to front)")
     '
     DropAction.AddItem("Insert at: ")
     '
      If SDB.IniFile.IntValue("SimpleAppend","Action") = 0 Then
        DropAction.ItemIndex = 0
      ElseIf SDB.IniFile.IntValue("SimpleAppend","Action") = 1 Then
        DropAction.ItemIndex = 1
     Else
       DropAction.ItemIndex = 2
      End If
      Action = DropAction.ItemIndex
      Script.RegisterEvent DropAction, "OnChange", "PreviewIt"
       
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   Set indexField = SDB.UI.NewEdit(MainForm)
     indexField.Common.ControlName = "Index"
     indexField.Common.Hint = "Index in the field where the string should be added"
     indexField.Common.SetRect 120, 10, 30, 30
     indexField.Common.Enabled = False
     indexField.Text = "..."
     Script.RegisterEvent indexField, "OnChange", "PreviewIt"
   
   Set spaceBox = SDB.UI.NewCheckBox(MainForm)
     spaceBox.Common.ControlName = "Space"
     spaceBox.Common.Hint = "Add a space before/after your text?"
     spaceBox.Common.SetRect 500, 10, 80, 20
     spaceBox.Caption = "Space?"
     spaceBox.Checked = True
     Script.RegisterEvent spaceBox.Common, "OnClick", "PreviewIt"
    
   ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
   
    Dim edtUser
    Set edtUser = SDB.UI.NewEdit(MainForm)
      edtUser.Common.ControlName = "Edit"
      edtUser.Common.Hint = "Text you wish to add"
      edtUser.Common.SetRect 160, 10, 180, 30
      If SDB.IniFile.StringValue("SimpleAppend","UserText") <> "" Then
        edtUser.Text = SDB.IniFile.StringValue("SimpleAppend","UserText")
      End If
      UserText = edtUser.Text
      Script.RegisterEvent edtUser, "OnChange", "PreviewIt"
       
    Dim lbl
    Set lbl = SDB.UI.NewLabel(MainForm)
      lbl.Caption = "into"
      lbl.Common.SetRect 346, 12, 20, 30
     
    Dim DropField
    Set DropField = SDB.UI.NewDropDown(MainForm)
      DropField.Common.ControlName = "Field"
      DropField.Common.Hint = "Field to add to"
      DropField.Style = 2
      DropField.Common.SetRect 370, 10, 120, 30
      DropField.AddItem("Title")
      DropField.AddItem("Comment")
      DropField.AddItem("Artist")
      DropField.AddItem("AlbumArtist")
      DropField.AddItem("Album")
      DropField.AddItem("Tempo")
      DropField.AddItem("Mood")
      DropField.AddItem("Quality")
      DropField.AddItem("Custom 1")
      DropField.AddItem("Custom 2")
      DropField.AddItem("Custom 3")
      DropField.AddItem("Custom 4")
      DropField.AddItem("Custom 5")
      Script.RegisterEvent DropField, "OnChange", "PreviewIt"
      If SDB.IniFile.IntValue("SimpleAppend","Field") < 1 Then
        DropField.ItemIndex = 0
      Else
        DropField.ItemIndex = SDB.IniFile.IntValue("SimpleAppend","Field")
      End If
'       Field = DropField.ItemText(DropField.ItemIndex)
      Field = DropField.ItemIndex
             
    Dim btnDoIt
    Set btnDoIt = SDB.UI.NewButton(MainForm)
      btnDoIt.Caption = "&Do It!"
      btnDoIt.Common.Hint = "Apply It Now (NO UNDO) Escape to Cancel"
      btnDoIt.ModalResult = 1
      btnDoIt.Common.SetRect 500,35,80,30
       
    Set lbl = SDB.UI.NewLabel(MainForm)
      lbl.Caption = "PREVIEWING: 1st of " & Songlist.Count
      lbl.Common.SetRect 12, 45, 120, 30
    
   
    Dim edtPreview
    Set edtPreview = SDB.UI.NewEdit(MainForm)
      edtPreview.Common.ControlName = "Preview"
      edtPreview.Common.Hint = "Preview of the first of the selected track(s)"     
      edtPreview.Common.SetRect 140, 40, 350, 50
      edtPreview.Common.Enabled = False
      edtPreview.Text = Preview
       
    Dim btnClose
    Set btnClose = SDB.UI.NewButton(MainForm)
      btnClose.Cancel = True
      btnClose.ModalResult = 2
      btnClose.Common.SetRect 0,0,0,0
 
    If MainForm.ShowModal = 1 Then
      DoIt(MainForm)
    End If
   
    Script.UnregisterAllEvents

  End If
End Sub

Sub PreviewIt(obj)
  Dim tmp, Song
  Set tmp = obj.Common.TopParent

  Action = tmp.Common.ChildControl("Action").ItemIndex
  UserText = tmp.Common.ChildControl("Edit").Text
  Field = tmp.Common.ChildControl("Field").ItemIndex
 
  ''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
  'if "Insert at" is selected:
  If Action = 2 Then
    If indexField.Common.Enabled = False Then
     indexField.Text = "0"
     indexField.Common.Enabled = True
    ElseIf isNumeric(indexField.Text) Then
      Index = indexField.Text
    Else
      Exit Sub
   End If
  Else
    indexField.Common.Enabled = False
  End If
 
  'If the spaceBox is Checked, toggle the variable
  Space = spaceBox.Checked
  If spaceBox.Checked Then
    Space = " "
  Else
    Space = ""
  End If
  '''''''''''''''''''''''''''''''''''''''''''''''''''''''''''''
 
  If Songlist.Count > 0 Then
    Set Song = Songlist.Item(0)
 
    Select Case Field
      Case 0
        FieldText = Song.Title
      Case 1
        FieldText = Song.Comment
      Case 2
        FieldText = Song.ArtistName
      Case 3
        FieldText = Song.AlbumArtistName
      Case 4
        FieldText = Song.AlbumName
      Case 5
        FieldText = Song.Genre
      Case 6
        FieldText = Song.Tempo
      Case 7
        FieldText = Song.Mood
      Case 8
        FieldText = Song.Occasion
      Case 9
        FieldText = Song.Quality
      Case 10
        FieldText = Song.Custom1
      Case 11
        FieldText = Song.Custom2
      Case 12
        FieldText = Song.Custom3
      Case 13
        FieldText = Song.Custom4
      Case 14
        FieldText = Song.Custom5
      Case Else
        msgbox("Invalid field selected?")
    End Select
   
    If Action = 0 Then 'Append
      Preview = FieldText & Space & UserText
   ElseIf Action = 1 Then 'Prepend
     Preview = UserText & Space & FieldText
   Else 'Insert
     If Index = 0 Then
       Preview = UserText & Space & Mid(FieldText,Index+1,len(FieldText))
      ElseIf Index = len(FieldText) Then
       Preview = Mid(FieldText,1,Index) & Space & UserText
     Else
       Preview = Mid(FieldText,1,Index) & Space & UserText & Space & Mid(FieldText,Index+1,len(FieldText))
     End If
    End If
    If Not tmp.Common.ChildControl("Preview") Is Nothing Then
      tmp.Common.ChildControl("Preview").Text = Preview
    End If
  End If

  SDB.IniFile.IntValue("SimpleAppend","Action") = Action
  SDB.IniFile.IntValue("SimpleAppend","Field") = Field
  SDB.IniFile.StringValue("SimpleAppend","UserText") = UserText
 
End Sub

Sub DoIt(obj)
'   msgbox("Doing It, there is no undo!")
   
  If Songlist.Count > 0 Then
    Dim Txt, Track, x, NewSongs, Song, Preview, NewField
    Set NewSongs = SDB.NewSongList
    For x = 0 to Songlist.Count-1
      Set Song = Songlist.Item(x)
     Select Case Field
      Case 0
          FieldText = Song.Title
      Case 1
        FieldText = Song.Comment
       Case 2
          FieldText = Song.ArtistName
       Case 3
          FieldText = Song.AlbumArtistName
       Case 4
          FieldText = Song.AlbumName
      Case 5
        FieldText = Song.Genre
      Case 6
        FieldText = Song.Tempo
      Case 7
        FieldText = Song.Mood
      Case 8
        FieldText = Song.Occasion
      Case 9
        FieldText = Song.Quality
      Case 10
        FieldText = Song.Custom1
      Case 11
        FieldText = Song.Custom2
      Case 12
        FieldText = Song.Custom3
      Case 13
        FieldText = Song.Custom4
      Case 14
        FieldText = Song.Custom5
      Case Else
        msgbox("Invalid field selected?")
      End Select
      If Action = 0 Then 'Append
        NewField = FieldText & Space & UserText
     ElseIf Action = 1 Then 'Prepend
       NewField = UserText & Space & FieldText
     Else 'Insert
      If Index = 0 Then
         NewField = UserText & Space & Mid(FieldText,Index+1,len(FieldText))
        ElseIf Index = len(FieldText) Then
         NewField = Mid(FieldText,1,Index) & Space & UserText
       Else
         NewField = Mid(FieldText,1,Index) & Space & UserText & Space & Mid(FieldText,Index+1,len(FieldText))
       End If
     End If
     Select Case Field
        Case 0
          Song.Title = NewField
        Case 1
          Song.Comment = NewField
        Case 2
          Song.ArtistName = NewField
        Case 3
          Song.AlbumArtistName = NewField
        Case 4
          Song.AlbumName = NewField
        Case 5
          Song.Genre = NewField
        Case 6
          Song.Tempo = NewField
        Case 7
          Song.Mood = NewField
        Case 8
          Song.Occasion = NewField
        Case 9
          Song.Quality = NewField
        Case 10
          Song.Custom1 = NewField
        Case 11
          Song.Custom2 = NewField
        Case 12
          Song.Custom3 = NewField
        Case 13
          Song.Custom4 = NewField
        Case 14
          Song.Custom5 = NewField
        Case Else
      End Select
      NewSongs.Add(Song)
      SDB.ProcessMessages
    Next
  Else
    msgbox("No Tracks Selected")
  End If 
  NewSongs.UpdateAll
End Sub

Sub Install()
  Dim scriptName : scriptName = "SimpleAppend"
  'Add scripts.ini entries
  Dim inip : inip = SDB.ApplicationPath&"Scripts\Scripts.ini"
  Dim inif : Set inif = SDB.Tools.IniFileByPath(inip)
  If Not (inif Is Nothing) Then
     inif.StringValue(scriptName,"Filename") = "SimpleAppend.vbs"
     inif.StringValue(scriptName,"Procname") = "Start"
     inif.StringValue(scriptName,"DisplayName") = "Simple Append"
     inif.StringValue(scriptName,"Description") = "Adds text to selected field"
     inif.StringValue(scriptName,"Language") = "VBScript"
     inif.StringValue(scriptName,"ScriptType") = "0"
     SDB.RefreshScriptItems
  End If
End Sub


Nanya
 
Posts: 21
Joined: Wed Oct 03, 2012 8:04 pm

Re: [MM3 Script] Simple Append [2009-04-10]

Postby MusicBringer » Sat Mar 02, 2013 7:54 am

Teknojnky, Simple Append [2009-04-10] is one of my fav scripts. I use it a lot to add suffix to titles.

Nanya, a bit late I know, but I've only just seen your post.

I know nothing about coding.
Please tell me how I can make use of the Simple Insert code.
Thanks,
MediaMonkey user since 2006
MusicBringer
 
Posts: 622
Joined: Wed Oct 25, 2006 12:53 pm

Re: [MM3 Script] Simple Append [2009-04-10]

Postby saxguyty » Tue Oct 03, 2017 10:22 am

Teknojnky wrote: updated, added genres


genre was the only thing I wanted, but it's not actually there. there is Title, Comment, Artist, AlbumArtist,Album, Tempo, Mood, Quality and Custom 1-4
saxguyty
 
Posts: 3
Joined: Tue Sep 29, 2009 1:43 am

Previous

Return to Need Help with Addons?

Who is online

Users browsing this forum: Bing [Bot], Hdhntr23, Peke and 10 guests