Najeebsk

PLAYLIST-SAVE-M3U.ahk

May 14th, 2024
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;#warn
  2. #NoEnv
  3. #SingleInstance, Force
  4. Process, Priority, , A
  5. SendMode, Input
  6. SetBatchLines, -1
  7. ;#NoTrayIcon
  8. SetWorkingDir %A_ScriptDir%  
  9.  
  10. VLC = %A_programfiles%\VideoLAN\VLC\vlc.exe
  11.  
  12. Gui, Add, Edit, w900 h600 vPlaylist
  13. ; Set button layout to horizontal
  14. Gui, Add, Button, x5 y620 w100 gLoadPlaylist, Load Playlist
  15. Gui, Add, Button, x+5 y620 w100 gSaveAllURLs, Save All URLs
  16. Gui, Add, Button, x+5 y620 w100 gOpenInVLC, Open VLC
  17. Gui, Add, Button, x+5 y620 w100 gExitScript, Exit
  18.  
  19. Gui, Show, , Playlist Viewer
  20. return
  21.  
  22. LoadPlaylist:
  23.    FileSelectFile, PlaylistFile, 3, , Select a playlist file (*.m3u;*.m3u8)
  24.     if (ErrorLevel || PlaylistFile = "")
  25.     {
  26.         MsgBox, 16, Error, Unable to load the playlist file.
  27.         return
  28.     }
  29.  
  30.     FileRead, PlaylistContent, %PlaylistFile%
  31.     if ErrorLevel
  32.     {
  33.         MsgBox, 16, Error, Unable to read the contents of the playlist file.
  34.         return
  35.     }
  36.  
  37.     GuiControl,, Playlist, ; Clear existing playlist
  38.     URLList := ""  ; Initialize an empty string to hold the URLs
  39.     Loop, Parse, PlaylistContent, `n
  40.     {
  41.         if (RegExMatch(A_LoopField, "^(?!#EXTM3U|#EXTINF:-1|#.*\.(png|jpg|bmp)).*$", URL))
  42.         {
  43.             URLList .= URL "`n"  ; Append the URL to the list
  44.         }
  45.     }
  46.     GuiControl,, Playlist, %URLList%  ; Display the list of URLs
  47. return
  48.  
  49. ExitScript:
  50.    ExitApp
  51. return
  52.  
  53. OpenInVLC:
  54.    GuiControlGet, PlaylistContent,, Playlist
  55.     Run, %VLC%  ;"%PlaylistContent%"
  56.     Sleep, 5000 ; 5-second delay
  57.     Send, ^v
  58. return
  59.  
  60. SaveAllURLs:
  61.    GuiControlGet, PlaylistContent,, Playlist
  62.     FileDelete, Playlist.txt
  63.     FileAppend, %PlaylistContent%, Playlist.txt
  64.     MsgBox, Playlist URLs saved to Playlist.txt
  65. return
  66.  
  67. GuiContextMenu(playlist) {
  68.     Menu, ContextMenu, Add, Save Selected URLs, SaveSelectedURLs
  69.     Menu, ContextMenu, Show
  70.     return
  71. }
  72.  
  73. SaveSelectedURLs:
  74.    GuiControlGet, SelectedItem,, Playlist
  75.     FileAppend, %SelectedItem%, Playlist.txt
  76.     MsgBox, Selected URL saved to Playlist.txt
  77. return
Add Comment
Please, Sign In to add comment