[Solved - sort of] Dialog to select a file to read

This forum is for questions / discussions regarding development of addons / tweaks for MediaMonkey for Windows 4.

Moderators: Gurus, Addon Administrators

pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

[Solved - sort of] Dialog to select a file to read

Post by pokeefe0001 »

I am trying to write a fairly simple script that will read an m3u file. I'm basing the script on Trixmoto's ImportM3U 3.8. That script (and every other script I've found so far) creates a dialog that selects a directory and then has a code that loops processing files in the directory. I want a dialog that allows the selection of one file, regardless of however many .mu3 files might be in the directory. I've found no scripts that do that but I'm sure they exist. could someone point me to such a script?

The chunk of code in the original script that gets the directory is

Code: Select all

  'get filename
  Dim dir : dir = ini.StringValue("Scripts","LastImportM3UDir")
  Dim res : res = SDB.SelectFolder(dir,"Select folder of playlists:")
  If res = "" Then
    ImportDir = False
    Dim dlg : Set dlg = SDB.CommonDialog
    dlg.DefaultExt = ".m3u"
    dlg.Filter = "Playlists (*.m3u)|*.m3u|Unicode playlists (*.m3u8)|*.m3u8|All files (*.*)|*.*"
    dlg.Flags = cdlOFNOverwritePrompt+cdlOFNHideReadOnly+cdlOFNNoChangeDir
    If dir = "" Then
      dlg.InitDir = SDB.MyMusicPath
    Else
      dlg.InitDir = dir
    End If
    dlg.ShowOpen
    If Not dlg.Ok Then 
      Exit Sub
    End If
    res = dlg.FileName
    ini.StringValue("Scripts","LastImportM3UDir") = Left(res,InStrRev(res,"\"))
  Else
    ImportDir = True
    If Right(res,1) <> "\" Then
      res = res&"\"
    End If 
    ini.StringValue("Scripts","LastImportM3UDir") = res        
  End If
It contains a lot I don't need (such as using the previously processed directory - meaningless in my case), but more importantly, it returns a directory name, not a file name. How do I create a dialog that prompts for selection of a file?
Last edited by pokeefe0001 on Sat Dec 18, 2021 7:55 pm, edited 1 time in total.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Erwin Hanzl
Posts: 1190
Joined: Tue Jun 13, 2017 8:47 am
Location: Vienna

Re: Dialog to select a file to read

Post by Erwin Hanzl »

Copy the corresponding playlist into an empty folder.
MMW 4.1.31.1919 Gold-Standardinstallation
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Dialog to select a file to read

Post by pokeefe0001 »

Erwin Hanzl wrote: Tue Nov 30, 2021 3:10 pm Copy the corresponding playlist into an empty folder.
Yes, I know I can do that. But that's a restriction I'm not willing to put on the users of the script. If they have a flash drive with a whole collection of mu3 files, why should they have to put each one in a separate folder just so each can be processed independently?

Or are you saying that MediaMonkey does not have the capability selecting a single file in a folder?
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Peke
Posts: 17861
Joined: Tue Jun 10, 2003 7:21 pm
Location: Earth
Contact:

Re: Dialog to select a file to read

Post by Peke »

Hi,
Why don't you simply use "My computer" tree node, navigate to folder with M3Us and pick one by one? eg. Select track in selected M3U -> Right Click -> Send To Playlists -> New Playlist. That way you will also have control over nested playlist structure.
Best regards,
Peke
MediaMonkey Team lead QA/Tech Support guru
Admin of Free MediaMonkey addon Site HappyMonkeying
Image
Image
Image
How to attach PICTURE/SCREENSHOTS to forum posts
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Dialog to select a file to read

Post by pokeefe0001 »

Peke wrote: Thu Dec 02, 2021 2:59 am Hi,
Why don't you simply use "My computer" tree node, navigate to folder with M3Us and pick one by one? eg. Select track in selected M3U -> Right Click -> Send To Playlists -> New Playlist. That way you will also have control over nested playlist structure.
I'll have to consider that. The whole purpose of the scripts I'm writing is to change paths in the M3U file before passing it to a playlist. If I use your technique I have a new playlist with unmodified paths. I then have the problem of invoking the script for that new playlist.

I guess I should learn how to add a script to the context menu for the tree node. Then I have the choice of writing the script to read the M3U file or writing it to read an MM playlist.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Erwin Hanzl
Posts: 1190
Joined: Tue Jun 13, 2017 8:47 am
Location: Vienna

Re: Dialog to select a file to read

Post by Erwin Hanzl »

"Dialog to select a file to read" - Need to reprogram the script

This is currently the shortest route:

Import M3U 3.8 functions:
It searches for the filename (not the full path) in your database, so this is useful if you moved files in the playlist.

Also has the option to ignore the extension in case you`ve converted your files since creating the playlist, as well as the option to ignore punctuation.
========================================================

So do the following:
1. Copy one or more playlists into an empty folder
2. Make sure that the playlist name is not already in your "Playlists", otherwise you change the name of the .M3U.
3. start MM4
4. Start the script "Import M3U 3.8"
5. Select the appropriate folder
6. use my settings

Image

7. The imported playlists are DIRECTLY visible under playlists with the corresponding name.
MMW 4.1.31.1919 Gold-Standardinstallation
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Dialog to select a file to read

Post by pokeefe0001 »

I have used that script as a model but have made lots of changes because my goal and the script's purpose are different. However, your suggestion starts with what I consider an unacceptable step:
Copy one or more playlists into an empty folder
There may be more than one playlist in the folder (or more likely, high level file on a flash drive). I want the user of the script to be able to select one file.




Background:
We have many several copies of our music library paired with a portable MM. (I'm aware of 8 copies, but we occasionally clone more.) The library and the portable MM are either in the same directory on a computer or top level directories on a flash drive. The library has the same structure everywhere but each instance has different high level qualifiers and drive letter. Each MM database points to its local music library.

We want a playlist created on any copy to be able to be imported into any other copy regardless of the high level part of the library's path. We do not need to create any tracks not found in the library - there should not be any - but we need an exact match on the path name excluding a variable amount of high order stuff. And actually, we don't even need to create a playlist in the target MM; just putting the list in Now Playing is sufficient.

Therefore, lots of stuff in the original script gets removed and lots of stuff gets changed. But for now that need to process a directory rather than a file is a problem.

If I cannot select a file withing MM I can probably write a script that runs outside MM, building a temporary file with the correct paths for the local MM and then (somehow) doing an "Open withe MdeiaMonkey" which puts the playlist in Now Playing. (That might actually be quicker.)
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Erwin Hanzl
Posts: 1190
Joined: Tue Jun 13, 2017 8:47 am
Location: Vienna

Re: Dialog to select a file to read

Post by Erwin Hanzl »

I think this is the perfect tool for you:
Recreate M3U 2.4 download: https://www.riklewis.com/mediamonkey/se ... ll=scripts

Description: This script allows you to import M3U files even if the filenames in the playlist do not appear in your database. It uses a progressive searching method to try and find the same track even if it has been reorganized.
Now if a track cannot be selected a screen is shown with the possible candidates for the user to select one. Also a text file can be imported with strings, though this is generally less effective.

See my settings:

Image
Last edited by Erwin Hanzl on Sun Dec 05, 2021 1:33 pm, edited 1 time in total.
MMW 4.1.31.1919 Gold-Standardinstallation
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Dialog to select a file to read

Post by pokeefe0001 »

I looked at the Recreate M3U 2.4 script a couple weeks ago and didn't find it useful. I'll look again.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
pokeefe0001
Posts: 97
Joined: Thu Oct 11, 2018 4:48 pm
Location: USA, Pacific Northwest

Re: Dialog to select a file to read

Post by pokeefe0001 »

It turns out that Windows doesn't provide an easy solution to this task so it's not surprising that MediaMonkey hasn't implemented a canned solution. However, Windows does provide a pretty good alternative. You just have to be willing to stick the script inside an HTA wrapper because HTA does (sort of) provide a solution. The HTA <input type=file ...> statement such as

Code: Select all

<input type="file" id="f1" style=width:40em oninput="ProcessFile()">
invokes a file selection dialog. The only downside (that I can see) is the the dialog display has "Choose file to upload" in its title bar.
MMV4 (1919) Portable
MMW5 (2606) Portable
Multiple Win11 x64 21H2
Multiple Win7 x32, unknown builds
Post Reply