createPlaylist(m3u,pls)

Veröffentliche deine funktionierenden Skripte und Funktionen

Moderator: jNizM

BoBo
Posts: 6564
Joined: 13 May 2014, 17:15

createPlaylist(m3u,pls)

Post by BoBo » 22 Mar 2022, 06:21

Gerade auf einem verwaisten GoogleDrive gefunden. Ist nicht wirklich Raketentechnik und ließe sich sicher noch nachbessern.

Ein Auszug zur Funktionalität...


  • createPlaylist("c:\users\user\downloads")
    process all mp3-files found within "C:\users\user\downloads" and create a m3u-playlist at the same location
  • createPlaylist("C:\users\user\downloads","D:\myMusic")
    process all mp3-files found within "C:\users\user\downloads" and create a m3u-playlist within "D:\myMusic"
  • createPlaylist("C:\users\user\downloads","D:\myMusic","ogg")
    process all ogg-files found within "C:\users\user\downloads" and create a m3u-playlist within "D:\myMusic"
  • createPlaylist("C:\users\user\downloads","D:\myMusic","ogg","pls")
    process all ogg-files found within "C:\users\user\downloads" and create a pls-playlist within "D:\myMusic"
  • createPlaylist("C:\users\user\downloads","D:\myMusic","ogg","pls",222)
    process as much ogg-files found within "C:\users\user\downloads" to create a pls-playlist within "D:\myMusic" with an estimated runtime of about 222 seconds
  • createPlaylist("C:\users\user\downloads","D:\myMusic","ogg","pls","All","rnd")
    process all ogg-files found within "C:\users\user\downloads" and create a randomly sorted pls-playlist within "D:\myMusic".


Code: Select all

#SingleInstance, Force
#Include wma.ahk                                    ; http://trubbleguy.com/wma.ahk
                                                    ; https://autohotkey.com/board/topic/98218-libahk-l-readwrite-any-tags-with-wmplayerocx7/
SetBatchLines, -1

If (A_ScriptName = "createPlaylist().ahk"){         ; test section
      MediaFileExt      := "mp3"
      PlaylistExtension := "pls"
      sourcePath        :=  UserProfile . "\Downloads"
      destinationPath   :=  ""
      runTime           :=  "A"
      SortOrder         :=  "rnd"
      createPlaylist(sourcePath,destinationPath,MediaFileExt,PlaylistExtension,runTime,SortOrder)
      createPlaylist(sourcePath)
      ; RegWrite, REG_SZ, HKEY_CLASSES_ROOT\.m3u, PerceivedType, text		; ermöglicht eine m3u-datei im preview pane anzuzeigen
      }
/*
      createPlaylist("c:\users\user\downloads")
      process all mp3-files found within "C:\users\user\downloads" and create a m3u-playlist at the same location
      
      createPlaylist("C:\users\user\downloads","D:\myMusic")
      process all mp3-files found within "C:\users\user\downloads" and create a m3u-playlist within "D:\myMusic"
      
      createPlaylist("C:\users\user\downloads","D:\myMusic","ogg")
      process all ogg-files found within "C:\users\user\downloads" and create a m3u-playlist within "D:\myMusic"
      
      createPlaylist("C:\users\user\downloads","D:\myMusic","ogg","pls")
      process all ogg-files found within "C:\users\user\downloads" and create a pls-playlist within "D:\myMusic"
      
      createPlaylist("C:\users\user\downloads","D:\myMusic","ogg","pls",222)
      process as much ogg-files found within "C:\users\user\downloads" to create a pls-playlist within "D:\myMusic" with an estimated runtime of about 222 seconds
      
      createPlaylist("C:\users\user\downloads","D:\myMusic","ogg","pls","All","rnd")
      process all ogg-files found within "C:\users\user\downloads" and create a randomly sorted pls-playlist within "D:\myMusic".
*/
 
createPlaylist(srcPath,destPath="",fExt="mp3",pExt="m3u",rTime="All",order=""){
      destPath:=  destPath = "" ? srcPath : destPath
      rTime   := rTime  = "All"  ? "A" 
              : rTime   = "A"    ? "A"
              : rTime*60
      If FileExist(destPath "\playlist." pExt)
        FileDelete,% destPath "\playlist." pExt
      Loop, Files,% srcPath "\*." fExt
          fIndex .= A_LoopFileName "|"
      fIndex  :=  SubStr(fIndex,1,-1)
      sort    :=  order = "rnd" ? "Random"
              :   order = "rev" ? "R"
              :   order  
      Sort, fIndex,% "D| U " sort
      create%pExt%(fIndex,srcPath,destPath,rTime)
      SoundBeep
      }
      
createM3U(fIndex,srcPath,destPath,rTime){
      pDuration := 0
      FileAppend, % "#EXTM3U`n",% destPath . "\playlist.m3u"
      Loop, Parse, % fIndex, |
      {
        ToolTip % "[" . A_Index . "]"
        sDuration  :=  wma_Get(srcPath . "\" . A_LoopField,"Duration")
          SetFormat, Float, 0.0
          sDuration += 0
          sDuration := (sDuration = "") ? 0 : sDuration
          pDuration += sDuration
            pDuration :=  (rTime = "A") ? sDuration : pDuration+sDuration
        sTitle     :=  wma_Get(srcPath . "\" . A_LoopField,"Title")
        FileAppend, % "#EXTINF:" . sDuration . "," . sTitle . "`n" . srcPath . "\" . A_LoopField . "`n",% destPath . "\playList.m3u"
        If (pDuration > rTime)
          Break
        }
      ToolTip
      }

createPLS(fIndex,srcPath,destPath,rTime){
      i         := 0
      pDuration := 0      
      Loop, Parse, % fIndex, |
      {
        ToolTip % "[" . A_Index . "]"
        sDuration  :=  wma_Get(srcPath . "\" . A_LoopField,"Duration")
          SetFormat, Float, 0.0
          sDuration += 0
          sDuration :=  (sDuration = "")  ? "-1" : sDuration
          pDuration :=  (rTime = "A")     ? sDuration : pDuration+sDuration
        sTitle :=  wma_Get(srcPath . "\" . A_LoopField,"Title")

        IniWrite,% srcPath . "\" . A_LoopField ,% destPath . "\playlist.pls", playlist,% "File"A_Index
        IniWrite,% sTitle                      ,% destPath . "\playlist.pls", playlist,% "Title"A_Index
        IniWrite,% sDuration                   ,% destPath . "\playlist.pls", playlist,% "Length"A_Index
        i++
        If (pDuration > rTime)
          Break
        }
      IniWrite,%  i ,% destPath . "\playlist.pls", playlist, % "NumberOfEntries"
      IniWrite,% "2",% destPath . "\playlist.pls", playlist, % "Version"
      ToolTip
      }
Das Script sollte unter AHK 1.1. gelaufen sein (?) Etwaige Anpassungen an nachfolgende AHK Versionen stehen dem Nutzer offen :mrgreen:


Die zu inkludierende wma.ahk gibt es zum Download unter: http://trubbleguy.com/wma.ahk
oder hier (Download vom 22/03/2022)
Spoiler
Have phun 8-)

Return to “Skripte und Funktionen”