Jump to content

Sky Slate Blueberry Blackcurrant Watermelon Strawberry Orange Banana Apple Emerald Chocolate
Photo

Create Playlist - Explorer shell menu extension


  • Please log in to reply
24 replies to this topic
Serenity
  • Members
  • 1271 posts
  • Last active:
  • Joined: 07 Nov 2004
Here is a simple script that creates an .m3u playlist file via the Explorer shell menu. If the user right-clicks on a folder, it will create an m3u list based on the audio files inside that folder. If the user right-clicks on a file, it will create an m3u list based on audio files that reside in the files current directory.

This script can be installed uncompiled by specifying the path to AutoHotkey.exe in the command line. Sample registry keys required to link it to the shell menu are posted below along with the source code.

Recognised audio formats:
WAV,AIFF,AIF,IFF,SVX,SND,AU,VOC,CUE,OGG,MPC,MP+,MPP,MP3,MP2,MP4,M4A,AAC,FLAC,FLA,APE,MAC,WV,SPX,SID,CDA

Changelog:
* updated to write full path to audio files in m3u file
* updated to work with a wide range of audio formats
* updated to only create an m3u file if audio files exist in current directory
* script updated to get path details from clicked-on item
* script now titles the created .m3u file with the name of the directory it was created in

splitpath, 1, file, dir
  
filegetattrib, attr, %1%
if attr contains D ; launched from a directory
{

  m3u = %dir%\%file%\%file%.m3u
  
  loop, %dir%\%file%\*.*
  {
    splitpath, A_LoopFileName, , , ext
    if ext in WAV,AIFF,AIF,IFF,SVX,SND,AU,VOC,CUE,OGG,MPC,MP+,MPP,MP3,MP2,MP4,M4A,AAC,FLAC,FLA,APE,MAC,WV,SPX,SID,CDA
    {
      filelist = %filelist%%A_LoopFileLongPath%`n
      count++
    }
  }   
  
  if count = ; no audio files found
    return

  sort, filelist 
  
  filedelete, %m3u%
  fileappend, #EXTM3U`n%filelist%, %m3u%

}
else ; launched from a file
{

  ; get the current folder for the m3u name:
  stringsplit, array, dir, \
  folder := array%array0%   
  m3u = %dir%\%folder%.m3u

  loop, %dir%\*.*
  {
    splitpath, A_LoopFileName, , , ext
    if ext in WAV,AIFF,AIF,IFF,SVX,SND,AU,VOC,CUE,OGG,MPC,MP+,MPP,MP3,MP2,MP4,M4A,AAC,FLAC,FLA,APE,MAC,WV,SPX,SID,CDA
    {
      filelist = %filelist%%A_LoopFileLongPath%`n
      count++
    }
  }   

  if count = ; no audio files found
    return

  sort, filelist
  
  filedelete, %m3u%
  fileappend, #EXTM3U`n%filelist%, %m3u%

}
return


Compiled:

REGEDIT4

[HKEY_CLASSES_ROOT\AllFileSystemObjects\shell\Create Playlist]
@="Create Playlist"

[HKEY_CLASSES_ROOT\AllFileSystemObjects\shell\Create Playlist\command]
@="\"x:\\path to exe\\create m3u.exe\" \"%1\""

Uncompiled:

REGEDIT4

[HKEY_CLASSES_ROOT\AllFileSystemObjects\shell\Create Playlist]
@="Create Playlist"

[HKEY_CLASSES_ROOT\AllFileSystemObjects\shell\Create Playlist\command]
@="\"C:\\Program Files\\AutoHotkey\\AutoHotkey.exe\" \"x:\\create playlist.ahk\" \"%1\""

"Anything worth doing is worth doing slowly." - Mae West
Posted Image

sociableorg
  • Guests
  • Last active:
  • Joined: --
Hi,

First off, thanks for posting the wonderful script. I was trying to use the registry entry script you posted for the shell extensions, but am having a problem running that script. I have saved the following into a file called playlistregedit.reg:
--------------------------------------------------------------
REGEDIT4

[HKEY_CLASSES_ROOT\AllFileSystemObjects\shell\Create Playlist]
@="Create Playlist"

[HKEY_CLASSES_ROOT\AllFileSystemObjects\shell\Create Playlist\command]
@="\"x:\\path to exe\\create m3u.exe\" \"%1\""

--------------------------------------------------------------
I have changed the path in the script to point to m3u.exe.

Now I execute regedit /s playlistregedit.reg

I am getting an error "Cannot import playlistregedit.reg: Error opening file".

Appreciate your help!

reg
  • Guests
  • Last active:
  • Joined: --
Good stuff!!
Now, how to delete the reg entry please?
(only for test, the script is really good) :D

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Technically, that's not an Explorer shell menu extension, real one require to do a Com DLL...
That doesn't remove the usefulness of your script, of course.

I can't answer sociableorg, except to double-check the format of the file. Perhaps ensure it is pure Ascii, not encoded in Unicode.

reg, to delete a reg entry, just put a minus sign (a dash, an hyphen) after the opening brace:
REGEDIT4

[-HKEY_CLASSES_ROOT\AllFileSystemObjects\shell\Create Playlist]

Mmm, I didn't knew this AllFileSystemObjects, this is useful to know.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

reg
  • Guests
  • Last active:
  • Joined: --
Thank you, PhiLho!
Maybe you know also how to create in the Explorer shell menu the initial underlined, like
&createMp3....
createMp3...
Thanks in advance.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
Well, you gave the answer yourself:
[HKEY_CLASSES_ROOT\AllFileSystemObjects\shell\Create Playlist]
@="Create &Playlist"

Put the & wherever you want.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

reg
  • Guests
  • Last active:
  • Joined: --
Thank you, PhiLho.
I'm prudent with .reg! :D

insert an icon in the con
  • Guests
  • Last active:
  • Joined: --
Last but not least, is there any way to insert an icon in the context menu (appskey)?
Thanks in advance.

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
No, you have to write a real shell extension for that (AFAIK).
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

pandoRa
  • Guests
  • Last active:
  • Joined: --
it's nothing major, just - when I select several files at once and then try to create a playlist it crashes the Explorer :)

Is there any possibilitie to work around that?
I realy like that script, it'd be nice for selections to work

Andras
  • Guests
  • Last active:
  • Joined: --
Hi there folks,

I really like this solution,

But could you tell me if there is a possibility to make submenus under a shell extension in the explorer menu?

Just like WinZIP does have more options.

Thanx,
Andras

PhiLho
  • Moderators
  • 6850 posts
  • Last active: Jan 02 2012 10:09 PM
  • Joined: 27 Dec 2005
AFAIK, just by playing with the registry, no.
WinZip and others create real shell extensions, ie. plug-ins relying on Com interface (the ActiveX kind, not the com port!) to communicate with the shell (Explorer). This is beyond current AHK capabilities.
Posted Image vPhiLho := RegExReplace("Philippe Lhoste", "^(\w{3})\w*\s+\b(\w{3})\w*$", "$1$2")

Andras
  • Guests
  • Last active:
  • Joined: --
I thought it would be easier.

Thanks for the answer anyway :)
bye

cracksloth
  • Guests
  • Last active:
  • Joined: --
does anyone know how to tweak this script so that the playlist is randomized?

Newb42
  • Guests
  • Last active:
  • Joined: --
I am relatively new to autohotkey but even so, for the life of me I cannot get this script to work correctly. Every time I launch the create playlist option on a music folder it does nothing. It probably is something stupidly simple that I am overlooking but any help would be appreciated.