Skip to content

Instantly share code, notes, and snippets.

@emir
Created December 26, 2015 21:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save emir/25245d678c9a828f29e5 to your computer and use it in GitHub Desktop.
Save emir/25245d678c9a828f29e5 to your computer and use it in GitHub Desktop.
class TTNETMuzik
@@page
@@section
def initialize(parser, json)
@parser = parser
@json = json
end
##
# Copy to request as a curl
# change --data part with these:
# navPage=#{@@page}&id=#{id}&name=#{name}&submenu=#{@@section}
def source (id, name)
return ``
end
def getAlbums (id, name)
@@page = 'artist'
@@section = 'albums'
doc = @parser::HTML(source(id, name))
data = {}
doc.css('a.album').each do |el|
title = el['title']
details = el['onclick']
values = details.split("(")
values = values[1].split(")")
values = values[0].split(",")
ttnetMuzikId = values[0].tr('\'', '')
ttnetMuzikAlbumSlug = values[1].tr('\'', '')
data["album_" + ttnetMuzikId] = {
"id" => ttnetMuzikId,
"title" => title,
"slug" => ttnetMuzikAlbumSlug,
"links" => [
"album" => "/songs/" + ttnetMuzikId + "/" + name
]
}
end
doc.css('a.videoGorsel > img').each do |el|
thumb = el['src']
cover = thumb.gsub! '100', '300'
data[el['id']][:cover] = cover
end
return data
end
def getSongs (id, name)
@@page = 'album'
@@section = 'album'
doc = @parser::HTML(source(id, name))
data = {}
doc.css('ul.ArtistList li .musicListPlay').each do |el|
details = @json.parse(el['data-json'])
songId = details["ID"].to_i
lyrics = doc.css('ul.ArtistList li .musicListCont')[0]['rel']
data[songId] = {
"id" => details["ID"],
"title" => details["title"],
"performerId" => details["performer"]["ID"],
"performerName" => details["performer"]["name"],
"albumId" => details["albumId"],
"albumName" => details["albumName"],
"lyrics" => lyrics
}
end
return data
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment