is there an API to get tracklists from your player ?
gordielachance opened this issue · comments
Hi !
I'm working on a music player project that has similar features to yours, but would not be exclusive to Reddit.
Since I would like to parse Reddit tracklists too, I was wondering if you had an API to build custom tracklists based on a subreddit (get a list of tracks with artist/title/image/link...), or if you could help me understand how to do that without having to reinvent the wheel.
Thanks !
Hey there
You can just get the JSON data from Reddit: http://reddit.com/r/listentothis.json
See the Reddit API for details: https://www.reddit.com/dev/api/
To know if a link is playable, I do the following check: https://github.com/Illyism/musicplayer/blob/master/src/modules/playlist/util/isPlayable.ts
Ok... So you don't extract the artist / tile out of the reddit posts ? I need a clean way to get them (no genre/year/text...)
@gordielachance No, I just show the Reddit title. Let me know if you find a solution! I'd love to see it too.
well, I had worked on some piece of code but of course, it's not perfect.
The goal is to extract the track artist and track name out of the node title.
artist regex pattern:
(?:(?:.*), +by +(.*))|(?:(.*)(?: +[-|–|—]+ +)(?:.*))
title regex pattern:
(?:(.*), +by +(?:.*))|(?:(?:.*)(?: +[-|–|—]+ +)(.*))
then I try to clean those strings the best I can (here in Ruby) :
def clean_string(str)
#remove quotation marks
ignore_wrappers = ['"','\'']
ignore_wrappers.each do |wrapper|
str.delete_prefix(wrapper).delete_suffix(wrapper)
end
#remove some specific strings
ignore_words = [
'(Audio)',
'(Official)',
'(Official Video)',
'(Official Audio)',
'(Official Videoclip)',
'(Clip officiel)',
'(Lyric Video)',
'(Official Music Video)',
'(HD)',
'(Music Video)',
'(High Quality)',
' HD',
' HQ',
]
ignore_words.each do |word|
str.gsub! word, ''
end
#remove some regexes
ignore_regexes = [
'\[.*\]', #eg [Hip-Hop]
'\(\d{4}\)', #dates - eg. (1968)
'\d{4} ?$', #dates (end of string) eg. 2005
'[-|–|—] *$' #dash (end of string)
]
ignore_regexes.each do |regex|
pattern = Regexp.new(regex)
str = str.gsub(pattern, '')
end
str.strip
end
Of course, this is completely arbitrary. But it sometimes work quite well.