jeffharbert

Edit playlist and copy its songs to an Android device

Apr 6th, 2013
216
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.21 KB | None | 0 0
  1. Const ForReading = 1
  2. Const ForWriting = 2
  3.  
  4. ' Set your constants.
  5. ' The path to the M3U playlist saved from Winamp running on Windows.
  6. Const strPlaylist = "C:\Users\Jeff\Documents\Faves.m3u"
  7. ' The path to the folder that will hold the songs of the playlist on the Android device.
  8. Const strPlaylistLocation = "E:\Music\Faves\"
  9. ' Same as above, but just the folder name itself.
  10. Const strFileLocation = "Faves\"
  11. ' The path to the playlist that will end up on the Android device.
  12. Const strNewPlaylist = "E:\Music\Faves.m3u"
  13.  
  14. strEditedPlaylist = ""
  15. strEditedPlaylistTemp = ""
  16.  
  17. Set objFSO = CreateObject("Scripting.FileSystemObject")
  18.  
  19. If Not objFSO.FolderExists(strPlaylistLocation) Then
  20. objFSO.CreateFolder strPlaylistLocation
  21. End If
  22.  
  23. Set objPlaylist = objFSO.OpenTextFile(strPlaylist, ForReading)
  24.  
  25. Do Until objPlaylist.AtEndOfStream
  26. strLine = objPlaylist.ReadLine
  27. ' We only need to grab lines from the M3U file that contain file paths.
  28. ' I use "\\" below because Winamp on my PC monitors a UNC path, so that's what ends up in the M3U file.
  29. ' You can change this to "c:" or other drive letter as needed.
  30. If Left(strLine,2) = "\\" Then
  31. strSourceFilePath = strLine
  32. ' Isolate the file name from the full path
  33. arrFields = Split(strLine, "\")
  34. i = UBound(arrFields)
  35. strDestFileName = arrFields(i)
  36. ' Use the file name to construct a path to the Android device,
  37. ' using the defined strPlaylistLocation variable.
  38. strDestFilePath = strPlaylistLocation + strDestFileName
  39. ' If the file already exists at the destination, skip copying it.
  40. If Not objFSO.FileExists(strDestFilePath) Then
  41. wScript.Echo strDestFileName
  42. objFSO.CopyFile strSourceFilePath, strDestFilePath
  43. End If
  44. ' Build the new M3U file in RAM.
  45. strEditedPlaylistTemp = strEditedPlaylist + strFileLocation + strDestFileName + VbCrLf
  46. strEditedPlayList = strEditedPlayListTemp
  47. End If
  48. Loop
  49. objPlaylist.Close
  50.  
  51. ' Create a blank M3U file if it doesn't already exist
  52. If Not objFSO.FileExists(strNewPlaylist) Then
  53. objFSO.CreateTextFile strNewPlaylist
  54. End If
  55.  
  56. ' Write the new M3U file to the Android device
  57. Set objNewPlaylist = objFSO.OpenTextFile(strNewPlaylist, ForWriting)
  58. objNewPlaylist.Write strEditedPlaylist
  59. objNewPlaylist.close
Advertisement
Add Comment
Please, Sign In to add comment