Export Playlis but with different file path

Post a reply

In an effort to prevent automatic submissions, we require that you complete the following challenge.
:D :) :( :o :-? 8) :lol: :x :P :oops: :cry: :evil: :roll: :wink:

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review

Expand view Topic review: Export Playlis but with different file path

Re: Export Playlis but with different file path

by groovekanzler » Thu Apr 28, 2016 12:17 pm

Thank you Lowlander,

that actually worked quite well!! It's a bot slow, seems like it's doing more than just finding and replacing existing paths, but it works!!!

Re: Export Playlis but with different file path

by Lowlander » Sat Apr 23, 2016 9:45 pm

Export Playlis but with different file path

by groovekanzler » Sat Apr 23, 2016 3:11 pm

Hi everyone,

I am looking for a way to export all playlists in a batch job but with a slight modification: Is it possible to alter the file path pointing to the mp3 files?

Reason for asking is that I play all files in MM from my local HDD whereas the exported playlist should point to files residing on a NAS (with same files/ folder structure). I had a look at the installed export script, but it's really all chinese to me.

So is there a simple way to alter that script to replace the original file path of a corresponding mp3 file from "A" to "B" where A ist the local file path (eg. I:\music\) an B is the file path on the NAS eg. SMB-SHARE-XY\MUSIC\ or network drive x:\music\

I'll attach a copy of the script, if someone is willing to highlight where changes have to be made to the script to do that.

Many thanx for responding!!

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
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 & ","
          ln = ln & "-1,"
        End If
        art = trck.ArtistName
        tit = trck.Title
        If art<>"" Then
          If tit<>"" Then
            ln = ln & art & " - " & tit
            ln = ln & art
          End If
          If tit<>"" then
            ln = ln & tit
          End If
        End If
        fout.WriteLine ln 
        fout.WriteLine trck.Path
    End If
    Progress.Value = i+1
End Sub