Najeebsk

PLAYLIST-SEARCH-M3U.ahk

May 14th, 2024 (edited)
129
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. ; Add Search Field
  14. Gui, Add, Edit, x5 y620 w300 vSearch gSearchPlaylist, Search...
  15. ; Set button layout to horizontal
  16. Gui, Add, Button, x310 y620 w100 gLoadPlaylist, Load Playlist
  17. Gui, Add, Button, x+5 y620 w100 gSaveAllURLs, Save All URLs
  18. Gui, Add, Button, x+5 y620 w100 gOpenInVLC, Open VLC
  19. Gui, Add, Button, x+5 y620 w100 gExitScript, Exit
  20.  
  21. Gui, Show, , Playlist Viewer
  22. return
  23.  
  24. LoadPlaylist:
  25.    FileSelectFile, PlaylistFile, 3, , Select a playlist file (*.m3u;*.m3u8)
  26.     if (ErrorLevel || PlaylistFile = "")
  27.     {
  28.         MsgBox, 16, Error, Unable to load the playlist file.
  29.         return
  30.     }
  31.  
  32.     FileRead, PlaylistContent, %PlaylistFile%
  33.     if ErrorLevel
  34.     {
  35.         MsgBox, 16, Error, Unable to read the contents of the playlist file.
  36.         return
  37.     }
  38.  
  39.     GuiControl,, Playlist, ; Clear existing playlist
  40.     URLList := ""  ; Initialize an empty string to hold the URLs
  41.     Loop, Parse, PlaylistContent, `n
  42.     {
  43.         if (RegExMatch(A_LoopField, "^(?!#EXTM3U|#EXTINF:-1|#.*\.(png|jpg|bmp)).*$", URL))
  44.         {
  45.             URLList .= URL "`n"  ; Append the URL to the list
  46.         }
  47.     }
  48.     GuiControl,, Playlist, %URLList%  ; Display the list of URLs
  49. return
  50.  
  51. SearchPlaylist:
  52.    GuiControlGet, SearchText,, Search
  53.     GuiControl,, Playlist, ; Clear existing playlist
  54.     if (SearchText = "") ; If no search text is entered, display the original playlist
  55.     {
  56.         GuiControl,, Playlist, %URLList%
  57.         return
  58.     }
  59.     FilteredList := "" ; Initialize an empty string to hold the filtered URLs
  60.     Loop, Parse, URLList, `n
  61.     {
  62.         if (InStr(A_LoopField, SearchText))
  63.         {
  64.             FilteredList .= A_LoopField "`n"  ; Append the URL to the filtered list
  65.         }
  66.     }
  67.     GuiControl,, Playlist, %FilteredList%  ; Display the filtered list of URLs
  68. return
  69.  
  70. ExitScript:
  71.    ExitApp
  72. return
  73.  
  74. OpenInVLC:
  75.    ControlGet, outputvar, Selected,,Edit1,
  76.     Run, %VLC% "%outputvar%"
  77.     ;Sleep, 5000 ; 5-second delay
  78.     ;Send, ^v
  79. return
  80.  
  81. SaveAllURLs:
  82.    GuiControlGet, PlaylistContent,, Playlist
  83.     FileDelete, Playlist.txt
  84.     FileAppend, %PlaylistContent%, Playlist.txt
  85.     MsgBox, Playlist URLs saved to Playlist.txt
  86. return
  87.  
  88. GuiContextMenu(playlist) {
  89.     Menu, ContextMenu, Add, Save Selected URL, SaveSelectedURL
  90.     Menu, ContextMenu, Show
  91.     return
  92. }
  93.  
  94. SaveSelectedURL:
  95.    GuiControlGet, SelectedItem,, Playlist
  96.     FileAppend, %SelectedItem%, Playlist.txt
  97.     MsgBox, Selected URL saved to Playlist.txt
  98. return
Add Comment
Please, Sign In to add comment