Script to modify playlist after Sync

Download and get help for different MediaMonkey for Windows 4 Addons.

Moderators: Peke, Gurus

marc_unwired
Posts: 5
Joined: Thu Oct 16, 2008 11:28 pm

Script to modify playlist after Sync

Post by marc_unwired »

I'm trying to use MM to manage all my music including syncing my playlists to my BlackBerry ... All the songs in my lists will sync correctly, but when I try to play the list, nothing happens ... when I view the list, all the songs are listed, but with play times of 0:00.

I have tries a bunch of things and (sort of) have it working now .. here is what I did.

Sync all songs to a single folder \BlackBerry\Music and have the track names as <artist>-<Track Name>.mp3 ... I then have the playlist synced to the same folder. The playlist automatically adds the full path to the track name .... for example ... in a text editor the Comedy.M3U playlist file looks like this ...

\BlackBerry\Music\Dane Cook - Creepy Guy @ Work_1.mp3
\BlackBerry\Music\Dane Cook - Dream House.mp3
\BlackBerry\Music\Patton Oswalt - The Dukes Of Hazzard.mp3
\BlackBerry\Music\Dane Cook - BAMF.mp3

This does not work ... if I remove the full path so that theplaylist looks like this

Dane Cook - Creepy Guy @ Work_1.mp3
Dane Cook - Dream House.mp3
Patton Oswalt - The Dukes Of Hazzard.mp3
Dane Cook - BAMF.mp3

It works fine ...

I posted this same issue in the Tech Suport forum http://www.mediamonkey.com/forum/viewto ... &sk=t&sd=a and someone in there (thanks Peke) suggesetd that I ask in this forum about a post sync event script.

Any help would be appreciated

Thanks

Marc
marc_unwired
Posts: 5
Joined: Thu Oct 16, 2008 11:28 pm

Re: Script to modify playlist after Sync

Post by marc_unwired »

OK .. so I took a shot at this myself .. I'm comfortable with VB Script but not an expert and sort of glued this together from other scripts that I had worked on in the past ...

Code: Select all

'==========================================================================
'
' NAME: BB-MM-PlaylistFix.vbs
'
' DATE  : 10/24/2008
'
' COMMENT:
'
'==========================================================================

Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")

'--Set Variable for Path  -- the script will search all files in this path (unless limited by extention below)

     sPath = "F:\Music"

'--Get extension to search For -- Limit the search to files with this extension

      sExt = "m3u"

'--Call the Function to Do search and Replace

 s = DoSearch(sPath, sExt)


' -- The meat of the script ... function to replace text, basically reads all text into a variable then replaces any instance of
'-- \Music with . then writes the contents of the modified variable to the same filename.

Function DoSearch(FolPath, sExtName)

Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim SubPath, Fol, s1, sList, oFol, Fils, oFil, s, sPath, Fols, LExt
    LExt = Len(sExtName)
    sExtName = UCase(sExtName)
    Set oFol = objFSO.GetFolder(FolPath)
    Set Fils = oFol.Files
      If Fils.count > 0 Then
         For Each oFil In Fils
            Set objFile = objFSO.OpenTextFile(sPath & oFil, ForReading)
            strText = objFile.ReadAll
            objFile.Close
            strNewText = Replace(strText, "\Music", ".")
            
            Set objFile = objFSO.OpenTextFile(sPath & oFil, ForWriting)
            objFile.WriteLine strNewText
            objFile.Close
         Next
       End If
End Function
This works well enough for me, but now I'd like to see if I can have this script run after a sync automatically ... is there a way to do this?

Thanks again for any help.

Marc
Kryzn

Re: Script to modify playlist after Sync

Post by Kryzn »

Hey Marc

I saw your post at Crackberry, too. Am also looking for a way to use my Blackberry with Media Monkey, since I do not care much for Itunes. I unfortunately do not know anything about scripting, but just wanted to let you know that I would be really grateful if you, or someone else, could figure out a way to sync playlists.

Cheers
Kryzn
marc_unwired
Posts: 5
Joined: Thu Oct 16, 2008 11:28 pm

Re: Script to modify playlist after Sync

Post by marc_unwired »

Well ... I decided to punt and go back to iTunes, when you add in the Media Sync app from Blackberry (allows you to sync iTunes playlists) it Just works. I'm going to use iTunes plus BB Media Sync for now, and when I have some spare time go back to work on getting Media Monkey to work, I like it better, but right now I just need something that works.

Curiuosly enough, after reinstalling iTunes and BB Media Sync, setting up all my play lists and podcasts and resyncing my BB, I took a look at the .M3U files that are synced using that setup. On the BB (when opened in a text editor) they are in a different format, one that uses the "URL" format for the file path.

The Media Sync program automatically copies music to Media Card\BlackBerry\Music\Media Sync\<Artist>\<Album>\<Track> and creates the playlist files in the ..\..\..\Media Sync Directory ... so the entry for a tune in the .M3U looks like this

Code: Select all

#EXTM3U
#EXTINF:334,Red Hot Chili Peppers - Snow ((Hey Oh))
file:///SDCard/BlackBerry/music/Media%20Sync/Red%20Hot%20Chili%20Peppers/Stadium%20Arcadium%20(disc%201_%20Jupiter)/1-02%20Snow%20((Hey%20Oh)).mp3
I have seen this format mentioned in a few other articles and to be honest, I have no idea if this is the correct format, or the other one is correct, or if they both are (the beautiful thing about standards is there are so many to choose from). The important part is that somewhere, this is a standard so I'd be that somewhere Media Monkey could be set to output the .M3U files in this format ... one thing I know is that my scripting ability is no where near what it needs to be to turn the format I get from MM to the "URL Format.

No time to dig into that now ... but someday.

Marc
Guest

Re: Script to modify playlist after Sync

Post by Guest »

Taking the script snippet above, I was able to get this working (mostly) with my Blackberry Bold. You were almost there! Unfortunately, I've done a lot of digging in these forums and in the documentation, and it doesn't appear that there is an event handler that you can use to make this happen automatically whenever syncing finishes. So, you have to run the script manually every time after you sync. Otherwise, this method seems to work perfectly.

MM developers, please consider writing this event handler into the next version!

Directions:
1. Save the script (below) to c:\Program Files\MediaMonkey\Scripts\FixBBm3us.vbs
2. Edit all references to "F:\Blackberry\music" in the script to your particular environment - whatever you've set it to in the plugin sync settings in MM. Note this is case sensitive and must match exactly.
3. Edit Scripts.ini to get the script registered with MediaMonkey. I added these lines:

Code: Select all

[FixBBM3Us]
FileName=FixBBm3us.vbs
ProcName=FixBBM3Us
Order=40
DisplayName=Fix Blackberry M3U playlists
Description=Edits M3U format to get them to work on BB Media Player
Language=VBScript
ScriptType=0
4. Restart MM
5. After syncing, run the script via Tools | Scripts | Fix Blackberry M3u...

Here is my modified script... Thanks to the OP for getting me 90% of the way there!

Code: Select all


    Const ForReading = 1
    Const ForWriting = 2
    Set objFSO = CreateObject("Scripting.FileSystemObject")

	Sub FixBBM3Us()

    '--Set Variable for Path  -- the script will search all files in this path (unless limited by extention below)

         sPath = "F:\Blackberry\music"

    '--Get extension to search For -- Limit the search to files with this extension

          sExt = "m3u"

    '--Call the Function to Do search and Replace

    s = DoSearch(sPath, sExt)

	End Sub

    ' -- The meat of the script ... function to replace text, basically reads all text into a variable then replaces any instance of
    '-- \Music with . then writes the contents of the modified variable to the same filename.

    Function DoSearch(FolPath, sExtName)

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Dim SubPath, Fol, s1, sList, oFol, Fils, oFil, s, sPath, Fols, LExt
        LExt = Len(sExtName)
        sExtName = UCase(sExtName)
        Set oFol = objFSO.GetFolder(FolPath)
        Set Fils = oFol.Files
          If Fils.count > 0 Then
             For Each oFil In Fils
                Set objFile = objFSO.OpenTextFile(sPath & oFil, ForReading)
                strText = objFile.ReadAll
                objFile.Close
                strNewText = Replace(strText, "\Blackberry\Music", ".")
               
                Set objFile = objFSO.OpenTextFile(sPath & oFil, ForWriting)
                objFile.WriteLine strNewText
                objFile.Close
             Next
             
             SDB.MessageBox "Successfully fixed " & Fils.count & " M3U playlists.", mtInformation, Array(mbOk)
             
           End If
    End Function
Kryzn

Re: Script to modify playlist after Sync

Post by Kryzn »

Works on my Curve.

You are my new Hero. Only thing missing now is the ability to run the script automatically. But even this is awesome. Thank you so much!
marc_unwired
Posts: 5
Joined: Thu Oct 16, 2008 11:28 pm

Re: Script to modify playlist after Sync

Post by marc_unwired »

Awesome .. thank you unknown scripting master ...

Guest wrote:Taking the script snippet above, I was able to get this working (mostly) with my Blackberry Bold. You were almost there! Unfortunately, I've done a lot of digging in these forums and in the documentation, and it doesn't appear that there is an event handler that you can use to make this happen automatically whenever syncing finishes. So, you have to run the script manually every time after you sync. Otherwise, this method seems to work perfectly.

MM developers, please consider writing this event handler into the next version!

Directions:
1. Save the script (below) to c:\Program Files\MediaMonkey\Scripts\FixBBm3us.vbs
2. Edit all references to "F:\Blackberry\music" in the script to your particular environment - whatever you've set it to in the plugin sync settings in MM. Note this is case sensitive and must match exactly.
3. Edit Scripts.ini to get the script registered with MediaMonkey. I added these lines:

Code: Select all

[FixBBM3Us]
FileName=FixBBm3us.vbs
ProcName=FixBBM3Us
Order=40
DisplayName=Fix Blackberry M3U playlists
Description=Edits M3U format to get them to work on BB Media Player
Language=VBScript
ScriptType=0
4. Restart MM
5. After syncing, run the script via Tools | Scripts | Fix Blackberry M3u...

Here is my modified script... Thanks to the OP for getting me 90% of the way there!

Code: Select all


    Const ForReading = 1
    Const ForWriting = 2
    Set objFSO = CreateObject("Scripting.FileSystemObject")

	Sub FixBBM3Us()

    '--Set Variable for Path  -- the script will search all files in this path (unless limited by extention below)

         sPath = "F:\Blackberry\music"

    '--Get extension to search For -- Limit the search to files with this extension

          sExt = "m3u"

    '--Call the Function to Do search and Replace

    s = DoSearch(sPath, sExt)

	End Sub

    ' -- The meat of the script ... function to replace text, basically reads all text into a variable then replaces any instance of
    '-- \Music with . then writes the contents of the modified variable to the same filename.

    Function DoSearch(FolPath, sExtName)

    Set objFSO = CreateObject("Scripting.FileSystemObject")

    Dim SubPath, Fol, s1, sList, oFol, Fils, oFil, s, sPath, Fols, LExt
        LExt = Len(sExtName)
        sExtName = UCase(sExtName)
        Set oFol = objFSO.GetFolder(FolPath)
        Set Fils = oFol.Files
          If Fils.count > 0 Then
             For Each oFil In Fils
                Set objFile = objFSO.OpenTextFile(sPath & oFil, ForReading)
                strText = objFile.ReadAll
                objFile.Close
                strNewText = Replace(strText, "\Blackberry\Music", ".")
               
                Set objFile = objFSO.OpenTextFile(sPath & oFil, ForWriting)
                objFile.WriteLine strNewText
                objFile.Close
             Next
             
             SDB.MessageBox "Successfully fixed " & Fils.count & " M3U playlists.", mtInformation, Array(mbOk)
             
           End If
    End Function
proximous
Posts: 4
Joined: Tue Jan 30, 2007 11:49 am

Re: Script to modify playlist after Sync

Post by proximous »

Thanks for the above.

I don't know if I caused this, but my playlists ended up in a directory called Playlist at the root of SD card.

So if anyone wants the more generic fix, that will work wherever your playlists end up, make the following change in FixBBm3us.vbs:

Change:

Code: Select all

strNewText = Replace(strText, "\Blackberry\Music", ".")
to

Code: Select all

strNewText = Replace(strText, "\Blackberry\Music", "\SDCard\Blackberry\Music")
solomon grundy

Re: Script to modify playlist after Sync

Post by solomon grundy »

Wow - thanks everyone. I have the same issue as the last poster where my playlists are stored in the root of the SD card in a folder named Playlists. His fixed worked like a charm, as is. Be aware of the case-sensitivity of all paths you put in the script. For instance, my music is stored in \<mediacard>\BlackBerry\music. Note that "BlackBerry" has two capital "B"s in my case and "music" has a lower-case "m". It took me a while to figure out why the script was finding the playlist files but wouldn't make any changes to them.
Does this only work with the Curve?

Re: Script to modify playlist after Sync

Post by Does this only work with the Curve? »

I have a pearl 8120 and this is not working for me, if I create a playlist from my pearl it works and it looks like this:
file:///SDCard/BlackBerry/music/3%20Gymnopedies%20-%20Gymnopedie%20No%201%20Lent%20et%20douloureux.mp3
file:///SDCard/Music/The%20Gin%20Blossoms/Outside%20Looking%20in%20-%20The%20Best%20of%20the%20Gin%20Blossoms/03%20-%20Until%20I%20Fall%20Away.MP3
Following the instruction for the script the playlist shows empty and it looks like this:
\BlackBerry\Music\Luis Miguel\0239 Romance 3\¿Que Sabes Tú.mp3
\BlackBerry\Music\The Gin Blossoms\Outside Looking in - The Best of the Gin Blossoms\03 - Until I Fall Away.mp3
\BlackBerry\Music\The Gipsy Kings\The Very Best Of\A Mi Manera.mp3
Has anybody been able to make this work on the Pearl 8120?
Thanks.
TaGR
Posts: 1
Joined: Sun May 24, 2009 9:57 am

Re: Script to modify playlist after Sync

Post by TaGR »

proximous wrote:Thanks for the above.

I don't know if I caused this, but my playlists ended up in a directory called Playlist at the root of SD card.

So if anyone wants the more generic fix, that will work wherever your playlists end up, make the following change in FixBBm3us.vbs:

Change:

Code: Select all

strNewText = Replace(strText, "\Blackberry\Music", ".")
to

Code: Select all

strNewText = Replace(strText, "\Blackberry\Music", "\SDCard\Blackberry\Music")
I tested this script on my BOLD 9000 with OS Build v4.6.0.162 and it didn't work... I have MM Syncing files to:

Music on the BB Media Card. Because of this, the 3mu playlist files were being saved into their own directory on the SdCard's root folder "Playlists"
Here is the changes I made to have MM successfully update those 3mu files:

Code: Select all

sPath = "J:\Playlists"

Code: Select all

strNewText = Replace(strText, "\Music", "\SDCard\Music")
Here is the Complete Code for simplicity sake:

Code: Select all

        Const ForReading = 1
        Const ForWriting = 2
        Set objFSO = CreateObject("Scripting.FileSystemObject")

       Sub FixBBM3Us()

        '--Set Variable for Path  -- the script will search all files in this path (unless limited by extention below)

             sPath = "J:\Playlists"

        '--Get extension to search For -- Limit the search to files with this extension

              sExt = "m3u"

        '--Call the Function to Do search and Replace

        s = DoSearch(sPath, sExt)

       End Sub

        ' -- The meat of the script ... function to replace text, basically reads all text into a variable then replaces any instance of
        '-- \Music with . then writes the contents of the modified variable to the same filename.

        Function DoSearch(FolPath, sExtName)

        Set objFSO = CreateObject("Scripting.FileSystemObject")

        Dim SubPath, Fol, s1, sList, oFol, Fils, oFil, s, sPath, Fols, LExt
            LExt = Len(sExtName)
            sExtName = UCase(sExtName)
            Set oFol = objFSO.GetFolder(FolPath)
            Set Fils = oFol.Files
              If Fils.count > 0 Then
                 For Each oFil In Fils
                    Set objFile = objFSO.OpenTextFile(sPath & oFil, ForReading)
                    strText = objFile.ReadAll
                    objFile.Close
                    strNewText = Replace(strText, "\Music", "\SDCard\Music")
                   
                    Set objFile = objFSO.OpenTextFile(sPath & oFil, ForWriting)
                    objFile.WriteLine strNewText
                    objFile.Close
                 Next
                 
                 SDB.MessageBox "Successfully fixed " & Fils.count & " M3U playlists.", mtInformation, Array(mbOk)
                 
               End If
        End Function
Many, many thanks to the original poster along with all others who collaborated on getting this to work with the Blackberry Bold..

Cheers!
ruebyi
Posts: 23
Joined: Mon Aug 03, 2009 3:04 am

Re: Script to modify playlist after Sync

Post by ruebyi »

Hi guys!

I managed to get my Playlists synced thanks to this great Thread!
Here the Version of the Script I use:
Const ForReading = 1
Const ForWriting = 2
Set objFSO = CreateObject("Scripting.FileSystemObject")

Sub FixBBM3Us()

'--Set Variable for Path -- the script will search all files in this path (unless limited by extention below)

sPath = "O:\Blackberry\music\newPlaylists"

'--Get extension to search For -- Limit the search to files with this extension

sExt = "m3u"

'--Call the Function to Do search and Replace

s = DoSearch(sPath, sExt)

End Sub

' -- The meat of the script ... function to replace text, basically reads all text into a variable then replaces any instance of
'-- \Music with . then writes the contents of the modified variable to the same filename.

Function DoSearch(FolPath, sExtName)

Set objFSO = CreateObject("Scripting.FileSystemObject")

Dim SubPath, Fol, s1, sList, oFol, Fils, oFil, s, sPath, Fols, LExt
LExt = Len(sExtName)
sExtName = UCase(sExtName)
Set oFol = objFSO.GetFolder(FolPath)
Set Fils = oFol.Files
If Fils.count > 0 Then
For Each oFil In Fils
Set objFile = objFSO.OpenTextFile(sPath & oFil, ForReading)
strText = objFile.ReadAll
objFile.Close
strNewText = Replace(strText, "\BlackBerry\music\", "\SDCard\Blackberry\music\")

Set objFile = objFSO.OpenTextFile(sPath & oFil, ForWriting)
objFile.WriteLine strNewText
objFile.Close
Next

SDB.MessageBox "Successfully fixed " & Fils.count & " M3U playlists.", mtInformation, Array(mbOk)

End If
End Function
thanks to the guy who wrote this!
But now I want something more, because of a Problem:
When I have already Playlists on my Blackberry and add new My Old Playlists are changed again, so the Path looks something like
\SDCard\SDCard\Blackberry\music\Roger Cicero\Artgerecht\F?r 'nen Kerl.mp3
Now I sync my Playlists with MM to "newPlaylists folder and copy them manually to Playlists"

But I want to get my Playlist automatically cut form the folder "newPlaylist" and pasteds in the folder "Playlists".

I know there is a way to do this, but I never scripted before, so I kindly ask for your help with this...

ruebyi
Jay

Re: Script to modify playlist after Sync

Post by Jay »

Ruebyi,

Pretty quick fix, just replace the line (in your code):

strNewText = Replace(strText, "\BlackBerry\music\", "\SDCard\Blackberry\music\")

with the following:

If InStr (strText, "SDCard") < 1 Then
strNewText = Replace(strText, "\BlackBerry\music\", "\SDCard\Blackberry\music\")
End If


That should fix the problem. I started searching on the web about trying to fix this playlist issue and it kills me that A) the black berries aren't "smart" enough to figure out the playlist thing and b) that there is no way to control it out of MM. Love the product (lifetime member) but I would think that bb having a pretty large market they would have some dll or option or something. Anyway, since I'm sick and I'm stuck at home, I decided to take up some vbs...its been a long, long time since I programmed but I figured it out, a pretty clean way to code it up and it works for me. Below is the code that you could just cut and paste into a file, name it something .vbs and run it. Just make sure you change the drive letter, depending on how the Mass storage device connects to your machine.
I love MM and dumped my iphone (in water) and went back to a bb (had a curve before) bold 2 9700. With this fix I just worked up, I'm all good....now only if MM would have post process script link....

I'm basically getting a list of all files in the \music folder, opening the .m3u pulling the whole thing into memory, doing a find and replace, then over writing the org file.

Is there a better way, yes...is there a cleaner way...yes....does it work...yes...just wanted to get that out there :)



Const ForReading = 1
Const ForWriting = 2

PlayListsLocation = "D:\BlackBerry\music\"
OldPath = "\BlackBerry\music\"
NewPath = "\SDCard\BlackBerry\music\"

Set objFSO = CreateObject("Scripting.FileSystemObject")

Set PLFolder = objFSO.GetFolder(PlayListsLocation)
set PLFiles = PLFolder.Files

for Each x in PLFiles
If InStr (LCase(x), ".m3u") And (x.size > 0) Then
Set objFile = objFSO.OpenTextFile(x, ForReading)
PlayList = objFile.ReadAll
objFile.Close
If Instr (PlayList, NewPath) < 1 Then
PlayList = Replace(PlayList, OldPath, NewPath)
End If
Set objFile = objFSO.OpenTextFile(x, ForWriting)
objFile.Write PlayList
End If
Next
opT

Re: Script to modify playlist after Sync

Post by opT »

Hello all,

I am using the Blackberry Curve 8520 and am having problems using this script.

--I changed the drive F to my K drive.

--I changed

Code: Select all

  strNewText = Replace(strText, "\BlackBerry\music", ".")
to

Code: Select all

 strNewText = Replace(strText, "\Blackberry\Music", ".")
to fix my casing.

After syncing my playlists are in K:\BlackBerry\music when viewed on my computer, and /Media Card/BlackBerry/music when viewed from my Blackberry. I am getting an error that reads "Path not found" on this line:

Code: Select all

   strText = objFile.ReadAll
My playlists are viewable on the Blackberry but I get the error that it contains no valid playlist songs. For clarification here is my full code:

Code: Select all

        Const ForReading = 1
        Const ForWriting = 2
        Set objFSO = CreateObject("Scripting.FileSystemObject")

       Sub FixBBM3Us()

        '--Set Variable for Path  -- the script will search all files in this path (unless limited by extention below)

             sPath = "K:\Blackberry\music"

        '--Get extension to search For -- Limit the search to files with this extension

              sExt = "m3u"

        '--Call the Function to Do search and Replace

        s = DoSearch(sPath, sExt)

       End Sub

        ' -- The meat of the script ... function to replace text, basically reads all text into a variable then replaces any instance of
        '-- \Music with . then writes the contents of the modified variable to the same filename.

        Function DoSearch(FolPath, sExtName)

        Set objFSO = CreateObject("Scripting.FileSystemObject")

        Dim SubPath, Fol, s1, sList, oFol, Fils, oFil, s, sPath, Fols, LExt
            LExt = Len(sExtName)
            sExtName = UCase(sExtName)
            Set oFol = objFSO.GetFolder(FolPath)
            Set Fils = oFol.Files
              If Fils.count > 0 Then
                 For Each oFil In Fils
                    Set objFile = objFSO.OpenTextFile(sPath & oFil, ForReading)
                    strText = objFile.ReadAll
                    objFile.Close
                    strNewText = Replace(strText, "\BlackBerry\music", ".")
                   
                    Set objFile = objFSO.OpenTextFile(sPath & oFil, ForWriting)
                    objFile.WriteLine strNewText
                    objFile.Close
                 Next
                 
                 SDB.MessageBox "Successfully fixed " & Fils.count & " M3U playlists.", mtInformation, Array(mbOk)
                 
               End If
        End Function
What could be my problem?
Jay

Re: Script to modify playlist after Sync

Post by Jay »

opT

Not exactly sure why you are getting an error but I was getting random errors with that code so that is when I decided to write my own (this way I know what is going on in each line), which is above your post. I've been using for a while now and not have had any issues with it. I used it on my old curve and now on my new Bold 2 and works like a champ. I'd give that a shot and see if you get the same problem.
Post Reply