-
-
Save onigetoc/ed876cebf0fabf82354c0e45fef04422 to your computer and use it in GitHub Desktop.
m3u to JSON converter
This file contains hidden or 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")) |
I do not remember about that :(, but on Github i did a php m3u8 parser who working well.
respond is in json.
https://github.com/onigetoc/m3u8-PHP-Parser
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hi there, May I ask how to run this script?