Skip to content

Instantly share code, notes, and snippets.

@onigetoc
Forked from christopherlovell/m3u-2-JSON.R
Created October 28, 2018 14:48
Show Gist options
  • Save onigetoc/ed876cebf0fabf82354c0e45fef04422 to your computer and use it in GitHub Desktop.
Save onigetoc/ed876cebf0fabf82354c0e45fef04422 to your computer and use it in GitHub Desktop.
m3u to JSON converter
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"))
Copy link

ghost commented Sep 30, 2020

Hi there, May I ask how to run this script?

@onigetoc
Copy link
Author

onigetoc commented Oct 1, 2020

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