Created
November 1, 2015 21:49
-
-
Save christopherlovell/9db2bdd81088cf673219 to your computer and use it in GitHub Desktop.
m3u to JSON converter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(rjson) | |
trim <- function (x) gsub("^\\s+|\\s+$", "", x) | |
data_dir = 'Documents/playlists/' | |
play_list = list() | |
for(i in list.files(data_dir,"^.*\\.(m3u)$")){ | |
year = substr(i,1,4) # record file specific information, in this case year from playlist group | |
d = data.frame() | |
for(j in readLines(paste0(data_dir,i),encoding = 'latin1')){ | |
if(substr(j,1,8) == "#EXTINF:"){ # track line | |
extract = trim(strsplit(x = substr(j,9,nchar(j)), split = c(" - |,"))[[1]][-1]) | |
d <- rbind(d,data.frame(extract[1],extract[2])) | |
} | |
} | |
colnames(d) <- c("artist", "song") | |
play_list[[i]] = list(name=i,year=year,tracks=d) | |
} | |
write(toJSON(play_list),paste0(data_dir,"playlists.json")) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How can I use this dear?
Please help me! I was using a site droidvision and was doing the job well to convert my m3u playlist to Json, but the site is not responding and it possibly down for long.
After searching in google on how to convert an m3u to Json I found this script but no documentation or tip. Can you please tell us how to use it?
Many thanks.