2018-12-16 19:52:13 +03:00
import urllib
2019-02-20 23:10:58 +03:00
import database
2019-04-30 18:23:09 +03:00
from malojatime import today , thisweek , thismonth , thisyear
2018-12-16 19:52:13 +03:00
2019-03-29 21:44:42 +03:00
2019-02-21 11:43:35 +03:00
def instructions ( keys ) :
2019-03-12 13:39:36 +03:00
from utilities import getArtistImage
2019-06-13 17:56:41 +03:00
from htmlgenerators import artistLink , artistLinks , link_address
2019-04-08 14:04:31 +03:00
from urihandler import compose_querystring , uri_to_internal
2019-04-23 19:08:37 +03:00
from htmlmodules import module_pulse , module_performance , module_trackcharts , module_scrobblelist
2018-12-16 19:52:13 +03:00
2019-04-08 14:04:31 +03:00
filterkeys , _ , _ , _ = uri_to_internal ( keys , forceArtist = True )
2019-04-23 18:55:59 +03:00
artist = filterkeys . get ( " artist " )
2019-03-12 13:39:36 +03:00
imgurl = getArtistImage ( filterkeys [ " artist " ] , fast = True )
2019-02-17 16:25:40 +03:00
pushresources = [ { " file " : imgurl , " type " : " image " } ] if imgurl . startswith ( " / " ) else [ ]
2019-03-29 21:44:42 +03:00
2019-02-20 23:10:58 +03:00
data = database . artistInfo ( filterkeys [ " artist " ] )
scrobbles = str ( data [ " scrobbles " ] )
pos = " # " + str ( data [ " position " ] )
2019-03-29 21:44:42 +03:00
2019-04-02 17:53:57 +03:00
html_medals = " "
if " medals " in data and data [ " medals " ] is not None :
if " gold " in data [ " medals " ] :
for y in data [ " medals " ] [ " gold " ] :
2019-06-17 16:24:11 +03:00
html_medals + = " <a title= ' Best Artist in " + str ( y ) + " ' class= ' hidelink medal shiny gold ' href= ' /charts_artists?in= " + str ( y ) + " ' ><span> " + str ( y ) + " </span></a> "
2019-04-02 17:53:57 +03:00
if " silver " in data [ " medals " ] :
for y in data [ " medals " ] [ " silver " ] :
2019-06-17 16:24:11 +03:00
html_medals + = " <a title= ' Second Best Artist in " + str ( y ) + " ' class= ' hidelink medal shiny silver ' href= ' /charts_artists?in= " + str ( y ) + " ' ><span> " + str ( y ) + " </span></a> "
2019-04-02 17:53:57 +03:00
if " bronze " in data [ " medals " ] :
for y in data [ " medals " ] [ " bronze " ] :
2019-06-17 16:24:11 +03:00
html_medals + = " <a title= ' Third Best Artist in " + str ( y ) + " ' class= ' hidelink medal shiny bronze ' href= ' /charts_artists?in= " + str ( y ) + " ' ><span> " + str ( y ) + " </span></a> "
2019-04-02 17:53:57 +03:00
2019-06-13 17:56:41 +03:00
html_cert = " "
for track in database . get_tracks ( artist = artist ) :
info = database . trackInfo ( track )
if info . get ( " certification " ) is not None :
img = " /media/record_ {cert} .png " . format ( cert = info [ " certification " ] )
trackname = track [ " title " ] . replace ( " ' " , " ' " )
tracklink = link_address ( track )
tooltip = " {title} has reached {cert} status " . format ( title = trackname , cert = info [ " certification " ] . capitalize ( ) )
html_cert + = " <a href= ' {link} ' ><img class= ' certrecord_small ' src= ' {img} ' title= ' {tooltip} ' /></a> " . format ( tooltip = tooltip , img = img , link = tracklink )
2019-06-27 11:40:38 +03:00
html_topweeks = " "
if data . get ( " topweeks " ) not in [ 0 , None ] :
link = " /performance?artist= " + urllib . parse . quote ( keys [ " artist " ] ) + " &trail=1&step=week "
title = str ( data [ " topweeks " ] ) + " weeks on #1 "
html_topweeks = " <a title= ' " + title + " ' href= ' " + link + " ' ><img class= ' star ' src= ' /media/star.png ' /> " + str ( data [ " topweeks " ] ) + " </a> "
2019-02-20 23:10:58 +03:00
credited = data . get ( " replace " )
2018-12-17 01:56:30 +03:00
includestr = " "
if credited is not None :
2018-12-22 14:47:49 +03:00
includestr = " Competing under " + artistLink ( credited ) + " ( " + pos + " ) "
2018-12-17 01:56:30 +03:00
pos = " "
2019-04-26 18:27:23 +03:00
else :
credited = artist
2019-02-20 23:10:58 +03:00
included = data . get ( " associated " )
2018-12-17 01:56:30 +03:00
if included is not None and included != [ ] :
includestr = " associated: "
2018-12-27 05:09:29 +03:00
includestr + = artistLinks ( included )
2019-02-20 20:22:45 +03:00
2019-03-29 21:44:42 +03:00
html_tracks , _ = module_trackcharts ( * * filterkeys , max_ = 15 )
2019-04-02 17:53:57 +03:00
2019-04-23 18:55:59 +03:00
html_scrobbles , _ , _ = module_scrobblelist ( artist = artist , max_ = 10 , earlystop = True )
2019-03-29 21:44:42 +03:00
2019-04-30 18:23:09 +03:00
# pulse and rankings
html_pulse_days = module_pulse ( * * filterkeys , max_ = 7 , since = today ( ) . next ( - 6 ) , step = " day " , trail = 1 )
html_pulse_weeks = module_pulse ( * * filterkeys , max_ = 12 , since = thisweek ( ) . next ( - 11 ) , step = " week " , trail = 1 )
html_pulse_months = module_pulse ( * * filterkeys , max_ = 12 , since = thismonth ( ) . next ( - 11 ) , step = " month " , trail = 1 )
html_pulse_years = module_pulse ( * * filterkeys , max_ = 10 , since = thisyear ( ) . next ( - 9 ) , step = " year " , trail = 1 )
2019-05-01 12:29:28 +03:00
html_performance_days = module_performance ( artist = credited , max_ = 7 , since = today ( ) . next ( - 6 ) , step = " day " , trail = 1 )
html_performance_weeks = module_performance ( artist = credited , max_ = 12 , since = thisweek ( ) . next ( - 11 ) , step = " week " , trail = 1 )
html_performance_months = module_performance ( artist = credited , max_ = 12 , since = thismonth ( ) . next ( - 11 ) , step = " month " , trail = 1 )
html_performance_years = module_performance ( artist = credited , max_ = 10 , since = thisyear ( ) . next ( - 9 ) , step = " year " , trail = 1 )
2018-12-16 19:52:13 +03:00
2019-04-23 18:55:59 +03:00
replace = {
2019-04-30 18:23:09 +03:00
# info
2019-04-23 18:55:59 +03:00
" KEY_ARTISTNAME " : keys [ " artist " ] ,
" KEY_ENC_ARTISTNAME " : urllib . parse . quote ( keys [ " artist " ] ) ,
2019-04-26 18:27:23 +03:00
" KEY_ENC_CREDITEDARTISTNAME " : urllib . parse . quote ( credited ) ,
2019-04-23 18:55:59 +03:00
" KEY_IMAGEURL " : imgurl ,
" KEY_DESCRIPTION " : " " ,
2019-04-30 18:23:09 +03:00
" KEY_SCROBBLES " : scrobbles ,
" KEY_POSITION " : pos ,
" KEY_ASSOCIATED " : includestr ,
2019-04-23 18:55:59 +03:00
" KEY_MEDALS " : html_medals ,
2019-06-13 17:56:41 +03:00
" KEY_CERTS " : html_cert ,
2019-06-27 11:40:38 +03:00
" KEY_TOPWEEKS " : html_topweeks ,
2019-04-30 18:23:09 +03:00
# tracks
2019-04-23 18:55:59 +03:00
" KEY_TRACKLIST " : html_tracks ,
2019-04-30 18:23:09 +03:00
# pulse
" KEY_PULSE_MONTHS " : html_pulse_months ,
" KEY_PULSE_YEARS " : html_pulse_years ,
" KEY_PULSE_DAYS " : html_pulse_days ,
" KEY_PULSE_WEEKS " : html_pulse_weeks ,
# performance
" KEY_PERFORMANCE_MONTHS " : html_performance_months ,
" KEY_PERFORMANCE_YEARS " : html_performance_years ,
" KEY_PERFORMANCE_DAYS " : html_performance_days ,
" KEY_PERFORMANCE_WEEKS " : html_performance_weeks ,
# scrobbles
2019-04-23 18:55:59 +03:00
" KEY_SCROBBLELIST " : html_scrobbles ,
" KEY_SCROBBLELINK " : compose_querystring ( keys ) ,
2019-04-30 18:23:09 +03:00
2019-04-23 18:55:59 +03:00
}
2019-03-29 21:44:42 +03:00
2019-02-17 16:25:40 +03:00
return ( replace , pushresources )