Advertisement
OgreVorbis

m3u8 Video Downloader

Jan 21st, 2023
3,096
-1
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Dim RealLines.s(0)
  2. #TempFile = "temp.m3u"
  3.  
  4. InitNetwork()
  5. OpenConsole("m3u8 Video Downloader")
  6.  
  7. tmpFile.s = GetTemporaryDirectory() + #TempFile
  8.  
  9. PrintN("This program will let you download full vids given the m3u8 link.")
  10. PrintN("You get this link by loading a vid in your browser with the inspect panel open.")
  11. PrintN("In the network tab of the inspect panel, you will find the m3u8 link.")
  12. PrintN("You may need to refresh the page.")
  13. PrintN("")
  14. PrintN("Paste your m3u8 URL here:")
  15. theURL.s = Input()
  16. PrintN("")
  17. PrintN("Type your output file name (path or not):")
  18. outputFile.s = Input()
  19.  
  20. If outputFile = ""
  21.     PrintN("ERROR: Bad file name!")
  22.     Print("Press ENTER to terminate. . .")
  23.     Input()
  24.     CloseConsole()
  25.     End
  26. EndIf
  27. If Right(outputFile, 4) <> ".mp4": outputFile + ".mp4": EndIf
  28. If Mid(outputFile, 2, 1) <> ":": outputFile = GetTemporaryDirectory() + outputFile: EndIf
  29.  
  30. If ReceiveHTTPFile(theURL, tmpFile)
  31.     Delay(2000)
  32.     OpenFile(0, tmpFile)
  33.     lines = 0
  34.     Repeat
  35.         tmpLine.s = ReadString(0, #PB_UTF8)
  36.         If Left(tmpLine, 1) <> "#"
  37.             RealLines(lines) = tmpLine
  38.             lines + 1
  39.             ReDim RealLines.s(lines)
  40.         EndIf
  41.     Until Eof(0) = #True
  42.     lines - 1
  43.     CloseFile(0)
  44.     Delay(500)
  45.     DeleteFile(tmpFile, #PB_FileSystem_Force)
  46.    
  47.     lastSlash = Len(theURL) - FindString(ReverseString(theURL), "/") + 1 ; get the last slash in URL
  48.     stubURL.s = Left(theURL, lastSlash)
  49.     PrintN("Stub URL: " + stubURL)
  50.     PrintN("======================")
  51.     OpenFile(0, outputFile)
  52.     For i = 0 To lines
  53.         *buffer = ReceiveHTTPMemory(stubURL + RealLines(i))
  54.         If *buffer
  55.             size = MemorySize(*buffer)
  56.             PrintN("Writing chunk " + Str(i) + " of " + Str(lines))
  57.             PrintN(RealLines(i))
  58.             WriteData(0, *buffer, size)
  59.             FreeMemory(*buffer)
  60.         Else
  61.             PrintN("ERROR: Memory problem for this chunk.")
  62.         EndIf
  63.         Delay(500)
  64.     Next
  65.     CloseFile(0)
  66.     PrintN("")
  67.     PrintN("DONE!")
  68. Else
  69.     PrintN("")
  70.     PrintN("ERROR: Could not download m3u8 file!")
  71. EndIf
  72.  
  73. Print("Press ENTER to terminate. . .")
  74. Input()
  75. CloseConsole()
  76. End
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement