Playlist with absolute/relative Path...

Get answers about using MediaMonkey 4 for Windows.

Moderator: Gurus

Michael Vogel
Posts: 54
Joined: Mon Jan 29, 2007 4:31 am

Playlist with absolute/relative Path...

Post by Michael Vogel »

Hi,

I am not sure if this is a normal behaviour, but on my car (FIAT 500) playlists created by the MediaMonkey are not recognized.

The path of the entries look like "..\..\..\MP3\Album\Interpret\Track.mp3", when I change this (with a text editor) to "\MP3\Album\Interpret\Track.mp3" everything works.

My question, who is doing the wrong thing? And - beside this - is it possible to let the MediaMonkey create FIAT-compatible playlists with no manually hand work?

Thanks,
Michael

PS this is a new question - I've tried to find something similar in the forum, but searching for strings like "../.." do not work
wolfzell
Posts: 155
Joined: Fri Apr 23, 2004 8:42 am
Location: Germany

Re: Playlist with absolute/relative Path...

Post by wolfzell »

There are scripts to export playlists in both ways, with relative and absolute paths. Trixmoto made them once and I changed some little details to fit my needs.

In my "Report"-Menu, I got two options: Playlists relative, Playlists iTunes and Playlists absolute.

Here are the necessary codes:

First the relevant part of Scripts.ini

Code: Select all


[ExportM3Us]
FileName=ExportM3Us.vbs
ProcName=ExportM3Us
Order=11
DisplayName=All Playlists absolute(&M3U)
Description=
Language=VBScript
ScriptType=1

[ExportM3Ui]
FileName=ExportM3Ui.vbs
ProcName=ExportM3Ui
Order=11
DisplayName=All Playlists iTunes
Description=
Language=VBScript
ScriptType=1

[ExportM3Ur]
FileName=ExportM3Ur.vbs
ProcName=ExportM3Ur
Order=12
DisplayName=All Playlists relative (&M3U)
Description=
Language=VBScript
ScriptType=1

And these are the Scripts:

ExportM3Us.vbs:

Code: Select all

' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' This file can be replaced  in one of the future versions,
' so please if you want to modify it, make  a copy, do your
' modifications  in that copy and  change Scripts.ini  file 
' appropriately. 
' If you do not do this, you will lose all  your changes in
' this script when you install a new version of MediaMonkey
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Option Explicit     ' report undefined variables, ...

' SDB variable is connected to MediaMonkey application object

' Recursively process all playlists
Sub ReadPlaylists( playlists, plst, prefix)
  Dim items
  Set items = plst.ChildPlaylists

  If prefix<>"" Then
    prefix = prefix & " - "
  End If

  Dim i, newplst, title
  For i=0 To items.Count-1
    Set newplst = items.Item(i)
    title = prefix & newplst.Title
    If Not playlists.exists(title) Then
      playlists.Add title, newplst
    End If
    ReadPlaylists playlists, newplst, title
  Next
End Sub

Sub ExportM3Us
  ' Open inifile and get last used directory
  Dim iniF
  Set iniF = SDB.IniFile

  ' Let user select the output path
  Dim path
  path = iniF.StringValue( "Scripts", "LastExportM3UsDir")

  path = SDB.SelectFolder( path, SDB.Localize( "Select where to export all M3U files."))

  If path="" Then
    Exit Sub
  End If

  If Right( path, 1)<>"\" Then
    path = path & "\"
  End If

  ' Write selected directory to the ini file
  iniF.StringValue( "Scripts", "LastExportM3UsDir") = path
  Set iniF = Nothing

  ' Connect to the FileSystemObject
  Dim fso
  Set fso = SDB.Tools.FileSystem

  Dim playlists
  Set playlists = CreateObject("Scripting.Dictionary")

  ' Use progress to notify user about the current action
  Dim Progress, ExpText
  Set Progress = SDB.Progress
  ExpText = SDB.Localize("Exporting...")
  Progress.Text = ExpText

  ' Prepare a list of all playlists
  ReadPlaylists playlists, SDB.PlaylistByTitle( ""), ""

  ' Go through the list and export each playlist
  Dim i, iTrck, plst, fout, plsts, titles, title, tracks, trck, ln, tlen, art, tit
  plsts = playlists.Items
  titles = playlists.Keys
  Progress.MaxValue = playlists.count
  For i=0 To playlists.Count-1
    Set plst = plsts(i)
    Set tracks = plst.Tracks
    title = Titles(i)
    Progress.Text = ExpText & " (" & title & ")"
    If tracks.Count>0 Then
      Set fout = fso.CreateTextFile( path & fso.CorrectFilename(title) & ".m3u", True)
      fout.WriteLine "#EXTM3U"
      For iTrck=0 To tracks.Count-1
        Set trck = tracks.Item(iTrck)
        ln = "#EXTINF:"
        tlen = trck.SongLength
        If tlen>0 Then
          ln = ln & tlen \ 1000 & ","
        Else
          ln = ln & "-1,"
        End If
        art = trck.ArtistName
        tit = trck.Title
        If art<>"" Then
          If tit<>"" Then
            ln = ln & art & " - " & tit
          Else
            ln = ln & art
          End If
        Else
          If tit<>"" then
            ln = ln & tit
          End If
        End If
        fout.WriteLine ln 
        fout.WriteLine trck.Path
      Next
      fout.Close
    End If
    Progress.Value = i+1
  Next
End Sub
ExportM3Ui.vbs:

Code: Select all

' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' This file can be replaced  in one of the future versions,
' so please if you want to modify it, make  a copy, do your
' modifications  in that copy and  change Scripts.ini  file 
' appropriately. 
' If you do not do this, you will lose all  your changes in
' this script when you install a new version of MediaMonkey
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

Option Explicit     ' report undefined variables, ...

' SDB variable is connected to MediaMonkey application object

' Recursively process all playlists
Sub ReadPlaylists( playlists, plst, prefix)
  Dim items
  Set items = plst.ChildPlaylists

  If prefix<>"" Then
    prefix = prefix & " - "
  End If

  Dim i, newplst, title
  For i=0 To items.Count-1
    Set newplst = items.Item(i)
    title = prefix & newplst.Title
    If Not playlists.exists(title) Then
      playlists.Add title, newplst
    End If
    ReadPlaylists playlists, newplst, title
  Next
End Sub

Sub ExportM3Ui
  ' Open inifile and get last used directory
  Dim iniF
  Set iniF = SDB.IniFile

  ' Let user select the output path
  Dim path
  path = iniF.StringValue( "Scripts", "LastExportM3UsDir")

  path = SDB.SelectFolder( path, SDB.Localize( "Select where to export all M3U files."))

  If path="" Then
    Exit Sub
  End If

  If Right( path, 1)<>"\" Then
    path = path & "\"
  End If

  ' Write selected directory to the ini file
  iniF.StringValue( "Scripts", "LastExportM3UsDir") = path
  Set iniF = Nothing

  ' Connect to the FileSystemObject
  Dim fso
  Set fso = SDB.Tools.FileSystem

  Dim playlists
  Set playlists = CreateObject("Scripting.Dictionary")

  ' Use progress to notify user about the current action
  Dim Progress, ExpText
  Set Progress = SDB.Progress
  ExpText = SDB.Localize("Exporting...")
  Progress.Text = ExpText

  ' Prepare a list of all playlists
  ReadPlaylists playlists, SDB.PlaylistByTitle( ""), ""

  ' Go through the list and export each playlist
  Dim i, iTrck, plst, fout, plsts, titles, title, tracks, trck, ln, tlen, art, tit
  plsts = playlists.Items
  titles = playlists.Keys
  Progress.MaxValue = playlists.count
  For i=0 To playlists.Count-1
    Set plst = plsts(i)
    Set tracks = plst.Tracks
    title = Titles(i)
    Progress.Text = ExpText & " (" & title & ")"
    If tracks.Count>0 Then
      Set fout = fso.CreateTextFile( path & fso.CorrectFilename(title) & ".m3u", True)
      For iTrck=0 To tracks.Count-1
        Set trck = tracks.Item(iTrck)
        ln = trck.Path
        ln = "E:\MP3"+ Right(ln, len(ln)-7)
        If Right(ln, 4)="flac" Then
          ln = Left(ln, len(ln)-4)+"mp3"
        End If
        fout.WriteLine ln
      Next
      fout.Close
    End If
    Progress.Value = i+1
  Next
End Sub
ExportM3Ur.vbs:

Code: Select all

' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
' This file can be replaced  in one of the future versions, 
' so please if you want to modify it, make  a copy, do your 
' modifications  in that copy and  change Scripts.ini  file 
' appropriately. 
' If you do not do this, you will lose all  your changes in 
' this script when you install a new version of MediaMonkey 
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! 
' 
' Modified by Trixmoto (20/10/2006)
' Modified by wolfzell (20/10/2006) 
' 

Option Explicit     ' report undefined variables, ... 

' SDB variable is connected to MediaMonkey application object 

' Recursively process all playlists 
Sub ReadPlaylists( playlists, plst, prefix) 
  Dim items 
  Set items = plst.ChildPlaylists 

  If prefix<>"" Then 
    prefix = prefix & " - " 
  End If 

  Dim i, newplst, title 
  For i=0 To items.Count-1 
    Set newplst = items.Item(i) 
    title = prefix & newplst.Title 
    If Not playlists.exists(title) Then 
      playlists.Add title, newplst 
    End If 
    ReadPlaylists playlists, newplst, title 
  Next 
End Sub 

Sub ExportM3Ur 
  ' Open inifile and get last used directory 
  Dim iniF 
  Set iniF = SDB.IniFile 

  ' Let user select the output path 
  Dim path 
  path = iniF.StringValue( "Scripts", "LastExportM3UrDir") 

  path = SDB.SelectFolder( path, SDB.Localize( "Select where to export all M3U files.")) 

  If path="" Then 
    Exit Sub 
  End If 

  If Right( path, 1)<>"\" Then 
    path = path & "\" 
  End If 

  ' Write selected directory to the ini file 
  iniF.StringValue( "Scripts", "LastExportM3UrDir") = path 
  Set iniF = Nothing 

  ' Connect to the FileSystemObject 
  Dim fso 
  Set fso = SDB.Tools.FileSystem 

  Dim playlists 
  Set playlists = CreateObject("Scripting.Dictionary") 

  ' Use progress to notify user about the current action 
  Dim Progress, ExpText 
  Set Progress = SDB.Progress 
  ExpText = SDB.Localize("Exporting...") 
  Progress.Text = ExpText 

  ' Prepare a list of all playlists 
  ReadPlaylists playlists, SDB.PlaylistByTitle( ""), "" 

  ' Go through the list and export each playlist 
  Dim i, iTrck, plst, fout, plsts, titles, title, tracks, trck, ln, tlen, art, tit 
  plsts = playlists.Items 
  titles = playlists.Keys 
  Progress.MaxValue = playlists.count 
  For i=0 To playlists.Count-1 
    Set plst = plsts(i) 
    Set tracks = plst.Tracks 
    title = Titles(i) 
    Progress.Text = ExpText & " (" & title & ")" 
    If tracks.Count>0 Then 
      Set fout = fso.CreateTextFile( path & fso.CorrectFilename(title) & ".m3u", True) 
      fout.WriteLine "#EXTM3U" 
      For iTrck=0 To tracks.Count-1 
        Set trck = tracks.Item(iTrck) 
        ln = "#EXTINF:" 
        tlen = trck.SongLength 
        If tlen>0 Then 
          ln = ln & tlen \ 1000 & "," 
        Else 
          ln = ln & "-1," 
        End If 
        art = trck.ArtistName 
        tit = trck.Title 
        If art<>"" Then 
          If tit<>"" Then 
            ln = ln & art & " - " & tit 
          Else 
            ln = ln & art 
          End If 
        Else 
          If tit<>"" then 
            ln = ln & tit 
          End If 
        End If 
        fout.WriteLine ln 
        
        'Trixmoto - make path relative 
        'fout.WriteLine trck.Path 
        Dim relp : relp = trck.Path 
        If InStr(relp,path) = 1 Then 
          relp = Replace(relp,path,"") 
        End If 
        fout.WriteLine relp 
      Next 
      fout.Close 
    End If 
    Progress.Value = i+1 
  Next 
End Sub
I hope you can use it. These scripts solved my playlist-export problems in MediaMonkey ever since.

bye
Wolfgang
pbergeron

Re: Playlist with absolute/relative Path...

Post by pbergeron »

Just a small fix to get the relative paths even if the destination folder is deeper than the track. E.g. destination path is /My Songs/mp3/playlists and tracks are in /My Songs/mp3.

Code: Select all

' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
' This file can be replaced  in one of the future versions,
' so please if you want to modify it, make  a copy, do your
' modifications  in that copy and  change Scripts.ini  file
' appropriately.
' If you do not do this, you will lose all  your changes in
' this script when you install a new version of MediaMonkey
' !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
'
' Modified by Trixmoto (20/10/2006)
' Modified by wolfzell (20/10/2006)
' Modified by pbergeron (14/10/2012)
'

Option Explicit     ' report undefined variables, ...

' SDB variable is connected to MediaMonkey application object

' Recursively process all playlists
Sub ReadPlaylists( playlists, plst, prefix)
  Dim items
  Set items = plst.ChildPlaylists

  If prefix<>"" Then
    prefix = prefix & " - "
  End If

  Dim i, newplst, title
  For i=0 To items.Count-1
    Set newplst = items.Item(i)
    title = prefix & newplst.Title
    If Not playlists.exists(title) Then
      playlists.Add title, newplst
    End If
    ReadPlaylists playlists, newplst, title
  Next
End Sub

Sub ExportM3Ur
  ' Open inifile and get last used directory
  Dim iniF
  Set iniF = SDB.IniFile

  ' Let user select the output path
  Dim path
  path = iniF.StringValue( "Scripts", "LastExportM3UrDir")

  path = SDB.SelectFolder( path, SDB.Localize( "Select where to export all M3U files."))

  If path="" Then
    Exit Sub
  End If

  If Right( path, 1)<>"\" Then
    path = path & "\"
  End If

  ' Write selected directory to the ini file
  iniF.StringValue( "Scripts", "LastExportM3UrDir") = path
  Set iniF = Nothing

  ' Connect to the FileSystemObject
  Dim fso
  Set fso = SDB.Tools.FileSystem

  Dim fsys
  Set fsys = CreateObject("Scripting.FileSystemObject")

  Dim playlists
  Set playlists = CreateObject("Scripting.Dictionary")

  ' Use progress to notify user about the current action
  Dim Progress, ExpText
  Set Progress = SDB.Progress
  ExpText = SDB.Localize("Exporting...")
  Progress.Text = ExpText

  ' Prepare a list of all playlists
  ReadPlaylists playlists, SDB.PlaylistByTitle( ""), ""

  ' Go through the list and export each playlist
  Dim i, iTrck, plst, fout, plsts, titles, title, tracks, trck, ln, tlen, art, tit
  plsts = playlists.Items
  titles = playlists.Keys
  Progress.MaxValue = playlists.count
  For i=0 To playlists.Count-1
    Set plst = plsts(i)
    Set tracks = plst.Tracks
    title = Titles(i)
    Progress.Text = ExpText & " (" & title & ")"
    If tracks.Count>0 Then
      Set fout = fso.CreateTextFile( path & fso.CorrectFilename(title) & ".m3u", True)
      fout.WriteLine "#EXTM3U"
      For iTrck=0 To tracks.Count-1
        Set trck = tracks.Item(iTrck)
        ln = "#EXTINF:"
        tlen = trck.SongLength
        If tlen>0 Then
          ln = ln & tlen \ 1000 & ","
        Else
          ln = ln & "-1,"
        End If
        art = trck.ArtistName
        tit = trck.Title
        If art<>"" Then
          If tit<>"" Then
            ln = ln & art & " - " & tit
          Else
            ln = ln & art
          End If
        Else
          If tit<>"" then
            ln = ln & tit
          End If
        End If
        fout.WriteLine ln
       
        'Trixmoto - make path relative
        'fout.WriteLine trck.Path
        'Use short filenames to be WiiMC compatible
        Dim relp : relp = trck.Path

        If InStr(relp, path) = 1 Then
          relp = Replace(relp, path, "")
        Else
          'pbergeron - Destination path isn't in track's path... Walk to the root
          Dim rpath : rpath = path
          Dim pfold : pfold = ""
	  Do While rpath <> "" And InStr(relp, rpath) <> 1
	     rpath = fsys.GetParentFolderName(rpath)
             pfold = fsys.BuildPath(pfold, "..")
          Loop
          If rpath <> "" Then
             relp = fsys.BuildPath(pfold, Replace(relp, rpath, ""))
          End If
        End If
        fout.WriteLine relp
      Next
      fout.Close
    End If
    Progress.Value = i+1
  Next
End Sub
Post Reply