Jump to content

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

Create Media Player Classic Playlist for Videos in Folder


  • Please log in to reply
13 replies to this topic
EdwardATeller
  • Members
  • 3 posts
  • Last active: Feb 18 2008 03:55 AM
  • Joined: 16 Apr 2007
Here is a script that creates a Media Player Classic playlist for all the videos in a particular directory. I know it is pretty rough and has many extra lines, but it seems to work fine.

Probably should have an array with the file types in it, and then loop over the array, but I don't know exactly how to do that yet.

BTW, the blank lines in the FileAppend command are crucial.


`::  ; writes a Media Player Classic Playlist file for all video files in chosen directory.  Accent key launches the script.

SetBatchLines, -1  ; Make the operation run at maximum speed.

;FileSelectFolder, WhichFolder,::{20d04fe0-3aea-1069-a2d8-08002b30309d}  ; Ask the user to pick a folder, My Computer option

FileSelectFolder, WhichFolder,%A_MyDocuments%  ; Ask the user to pick a folder, My Documents option

if (StrLen(WhichFolder) = 0)
	return ; No folder picked, so stop

SetWorkingDir, %WhichFolder%

FileAppend,
(
MPCPLAYLIST ; next blank line is crucial, don't delete

), play.mpcpl ; this is the name of the playlist file

count=1

If ErrorLevel <> 1
{
Loop, %WhichFolder%\*.mov, , 1 ; Quicktime
{

FileAppend,
(
%count%,type,0
%count%,filename,%A_LoopFileFullPath%

), play.mpcpl

count := count + 1	

}

}
Else
Exit

If ErrorLevel <> 1
{
Loop, %WhichFolder%\*.mpg, , 1 ; MPG
{

FileAppend,
(
%count%,type,0
%count%,filename,%A_LoopFileFullPath%

), play.mpcpl

count := count + 1	

}

}
Else
Exit

If ErrorLevel <> 1
{
Loop, %WhichFolder%\*.avi, , 1 ; AVI
{

FileAppend,
(
%count%,type,0
%count%,filename,%A_LoopFileFullPath%

), play.mpcpl

count := count + 1	

}

}
Else
Exit

If ErrorLevel <> 1
{
Loop, %WhichFolder%\*.wmv, , 1 ; Windows Media
{

FileAppend,
(
%count%,type,0
%count%,filename,%A_LoopFileFullPath%

), play.mpcpl

count := count + 1	

}

}
Else
Exit

If ErrorLevel <> 1
{
Loop, %WhichFolder%\*.mpeg, , 1 ; MPEG
{

FileAppend,
(
%count%,type,0
%count%,filename,%A_LoopFileFullPath%

), play.mpcpl

count := count + 1	

}

}
Else
Exit

return


HuBa
  • Members
  • 175 posts
  • Last active: Feb 13 2012 09:51 AM
  • Joined: 24 Feb 2007
The idea is very good, but be careful with the blocks.
Use indentation to make your script more readable if you post here on the Scripts & Functions topic.

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
I recall someone once made a script to tidy up ahk code. Probably Rajat, but I could be remembering wrong.

Rajat
  • Members
  • 1904 posts
  • Last active: Jul 17 2015 07:45 AM
  • Joined: 28 Mar 2004

I recall someone once made a script to tidy up ahk code. Probably Rajat, but I could be remembering wrong.

I worked on it very long ago and its development wasn't continuous... toralf has done it very nicely here

MIA

CleanNews.in : Bite sized latest news headlines from India with zero bloat


danalec
  • Members
  • 225 posts
  • Last active: Oct 03 2014 05:31 PM
  • Joined: 20 Jul 2006
very nice, thanks for sharing

dont forget to include mkv ;D

BrianTokyo
  • Guests
  • Last active:
  • Joined: --
Hi, I made a windows app for this, you can just drag a folder to the exe or use SendTo with right-click on it:

http://techsuki.net/...tokyo-playlist/

  • Guests
  • Last active:
  • Joined: --
ahh sorry forgot to add, works for these extensions:

.avi
.mpg
.mp4
.rmbv
.mkv
.mov
.ogm
.divx
.vob
.wmv

abrogard
  • Guests
  • Last active:
  • Joined: --
Script wouldn't run for me. I don't really know what to do. I put it in C:\ with a .vbs extension and tried to run it from Start/Run.

The system tried but said there was an invalid character in Line 2, Char 1.

I've got WinXP SP2.

regards,

ab :)

engunneer
  • Moderators
  • 9162 posts
  • Last active: Sep 12 2014 10:36 PM
  • Joined: 30 Aug 2005
since it is not a .vbs script, I can't see how it could work that way. Have you installed the program Autohotkey?

abrogard
  • Members
  • 2 posts
  • Last active: Jun 03 2008 11:02 AM
  • Joined: 02 Jun 2008
Well that explains a lot. Excuse my ignorance. It all falls into place. That's why the forum's called 'Autohotkey', yes? And it is a script for that piece of software.

I better go look for it.

........... short break.....................

Got it. Installed it. Renamed the script so's it ended in .ahk

Clicked on the script. Now I've got an icon "H" at the bottom of the screen.

Clicking on it brings up a screen that seems to be all about Autohotkey - I can get the User Manual from it, for instance - but no talk of a playlist for mpc anywhere.

I also tried that Tokyo thing and it appears as a choice for 'send to' but after sending stuff there... nothing.

I'm lost agin.....

:)


regards,

ab :)

Z Gecko
  • Guests
  • Last active:
  • Joined: --
the first line of the code
`::
indicates that the action will start when you press the "`"- key.
Yould change this to something else, if you want. Look at the Hotkey-Section in the help.

abrogard
  • Members
  • 2 posts
  • Last active: Jun 03 2008 11:02 AM
  • Joined: 02 Jun 2008
Yes, indeed. I finally found the key in question. Top left of my keyboard. I was thinking it was that other one - next to the semicolon - and I tried it and a couple of other guesses and got nowhere...

I should be okay now. Very interesting thing this autohotkey. If I can get the time from the family duties I'll look into it.

Thanks for your help.

regards,

ab :)

  • Guests
  • Last active:
  • Joined: --

I also tried that Tokyo thing and it appears as a choice for 'send to' but after sending stuff there... nothing.


The playlist file is inside the folder after you use the sendto.

Frankies
  • Members
  • 1 posts
  • Last active: Feb 15 2008 01:38 PM
  • Joined: 15 Feb 2008
Hi EdwardATeller

i tried to enhance your script (it will create a playlist for every sub-dir below the chosen one), maybe is useful for you too.

;
; MPC Playlist Generator Original by EdwardATeller (see http://www.autohotkey.com/forum/topic18393.html)
; enhanced by zx48 5/09
;
; v0.01 Original Version by EdwardATeller
; v0.02 added Sub-dir Routine
; v0.03 added more file extensions
;
prog_name = MPC Playlist Generator v0.03  ; name and version of the program
#NoEnv                    ; be compatible to new AHK versions in 2007 :)
#SingleInstance, force    ; only one program instance allowed
SetBatchLines, -1         ; Make the operation run at maximum speed.

IfExist, Blinky.ico
  Menu, Tray, Icon, Blinky.ico                    ; if exist, show my favorite Simpson icon (try google 4 it :)
Menu, Tray, Tip, %prog_name% (be patient :)       ; show program info
ini_name = MPC_Playlist_creator.ini               ; settings file name
iniread, SourcePath, %ini_name%, settings, SourcePath, .\    ; save last dir for next use

LOG_File = %A_ScriptDir%\MPC_Playlist_Creator_log.txt
LogShow = 0                                       ; if true -> show logfile on exit
LogLevel = 2                                      ; 0 -> 3 log more information (higher value, more information)
PlayList = playlist.mpcpl                         ; playlist filename

if LogLevel > 1
  {
  text = Program Started
  Log2File(text)      ; log text message 2 file
  }
fileselectfolder,SRCRootFolder,*%SourcePath%,1, ; choose main directory
if ErrorLevel  ; exit on empty source
  {
  if LogLevel > 0
    {
    text = ERROR: program closed "source dir selection aborted"
    Log2File(text)      ; log text message 2 file
    } 
  goto end
  }
iniwrite, %SRCRootFolder%, %ini_name%, settings, SourcePath    ; save path selection 4 next use
Loop, %SRCRootFolder%\*.*, 2, 1  ; only Folders but recursive
 DirList = %DirList%%A_LoopFileFullPath%`n
 Sort, DirList, C  ; sort Case sensitive
Loop, Parse, DirList,`n
{
if A_Loopfield =    ; exit if empty dir :)
  break
FileList =                      ; reset var for next iteration
SetWorkingDir, %A_Loopfield%    ; set actual dir for playlist generation
ifNotExist, %PlayList%          ; create playlist only if doesn't exist
 {
 Loop, %A_Loopfield%\*.avi, 0, 0  ; retrieve all AVI Files in current dir
   FileList = %FileList%%A_LoopFileName%`n
 Loop, %A_Loopfield%\*.wmv, 0, 0  ; retrieve all WMV Files in current dir
   FileList = %FileList%%A_LoopFileName%`n
 Loop, %A_Loopfield%\*.mpg, 0, 0  ; retrieve all Mpeg Files in current dir
   FileList = %FileList%%A_LoopFileName%`n
 Loop, %A_Loopfield%\*.mpeg, 0, 0  ; retrieve all MPEG Files in current dir
   FileList = %FileList%%A_LoopFileName%`n
 Loop, %A_Loopfield%\*.mov, 0, 0  ; retrieve all Quicktime Files in current dir
   FileList = %FileList%%A_LoopFileName%`n
 Sort, FileList, C  ; sort Case sensitive
  FileAppend, MPCPLAYLIST`n, %PlayList%    ; this is the header of the playlist file
  FileCounter = 1
  LoopCounter = 1
  Loop, parse, FileList,`n
  {
  if A_Loopfield =    ; exit if no file found
     break
  FileAppend,
(
%FileCounter%,type,0
%FileCounter%,filename,%A_LoopField%

), %PlayList%
  FileCounter += 1
  LoopCounter += 1
  }
  if LogLevel > 2
    {
    text = Playlist for directory %A_Loopfield% created
    Log2File(text)      ; log text message 2 file
    } 
  if LoopCounter <= 2    ; remove single file playlist's
    {
    if LogLevel > 1
       {
       text = single File Playlist for directory %A_Loopfield% erased
       Log2File(text)      ; log text message 2 file
       } 
     FileDelete, %PlayList% 
    }
 }
}

End:
if LogLevel > 1
  {
  text = Program ended
  Log2File(text)      ; log text message 2 file
  }
if LogShow
  run, notepad.exe %Log_File%  ; show log
ExitApp,

return

Log2File(TextToLog)  ; Function Log Text 2 File
{
	global Log_File  ; This global variable was previously given a value somewhere outside this function.
	FileAppend, %A_DD%.%A_MM%.%A_YYYY% %A_HOUR%:%A_MIN%:%A_SEC% -> %TextToLog% `n, %Log_File%
}

regards zx48