Advertisement
xX-AAAAAAAAAA-Xx

Untitled

Sep 1st, 2024 (edited)
42
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.56 KB | None | 0 0
  1. -- Function to run a shell command
  2. local function runShellCommand(command)
  3. local success, result = pcall(shell.run, command)
  4. if success then
  5. print(result)
  6. else
  7. print("Error executing command: " .. (result or "Unknown error"))
  8. end
  9. end
  10.  
  11. -- Function to download and convert audio to .dfpwm
  12. local function downloadAndConvert(youtubeURL)
  13. -- Command to download audio and convert to .dfpwm format
  14. -- This assumes you have a script or tool capable of handling the download and conversion
  15. local downloadCommand = string.format(
  16. 'wget "%s" -O "audio.wav" && wav2dfpwm audio.wav audio.dfpwm',
  17. youtubeURL
  18. )
  19. runShellCommand(downloadCommand)
  20. end
  21.  
  22. -- Function to write .dfpwm file to tape
  23. local function writeToTape(filename)
  24. -- Ensure the file exists
  25. if not fs.exists(filename) then
  26. print("Error: File not found.")
  27. return
  28. end
  29.  
  30. -- Run the tape write command
  31. local tapeCommand = string.format('tape write %s', filename)
  32. runShellCommand(tapeCommand)
  33.  
  34. -- Optionally delete the file after writing
  35. if fs.exists(filename) then
  36. fs.delete(filename)
  37. print("File " .. filename .. " deleted from disk.")
  38. end
  39. end
  40.  
  41. -- Main function
  42. local function main()
  43. -- Get YouTube URL from user
  44. print("Enter the YouTube URL:")
  45. local youtubeURL = read()
  46.  
  47. -- Download and convert the audio
  48. downloadAndConvert(youtubeURL)
  49.  
  50. -- Write the converted audio to tape
  51. writeToTape("audio.dfpwm")
  52. end
  53.  
  54. -- Run the main function
  55. main()
  56.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement