私は last.fm-API を使用しています。
現在再生中の曲に問題があります。JSON 出力の例を次に示します。
{"recenttracks":{"track":[{"artist":{"#text":"Gorillaz","mbid":"e21857d5-3256-4547-afb3-4b6ded592596"},"name":"Feel Good Inc - Single Edit","streamable":"0","mbid":"","album":{"#text":"","mbid":""},"url":"http:\/\/www.last.fm\/music\/Gorillaz\/_\/Feel+Good+Inc+-+Single+Edit","image":[{"#text":"","size":"small"},{"#text":"","size":"medium"},{"#text":"","size":"large"},{"#text":"","size":"extralarge"}],"@attr":{"nowplaying":"true"}},{"artist":{"#text":"Infected Mushroom","mbid":"eab76c9f-ff91-4431-b6dd-3b976c598020"},"name":"Muse Breaks RMX","streamable":"1","mbid":"","album":{"#text":"IM the Supervisor","mbid":"34ffab65-62d4-3cab-a6f6-043dd798fec7"},"url":"http:\/\/www.last.fm\/music\/Infected+Mushroom\/_\/Muse+Breaks+RMX","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/64129101.jpg","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/64129101.jpg","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/64129101.jpg","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/64129101.jpg","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 17:48","uts":"1360000129"}},{"artist":{"#text":"Eminem","mbid":"b95ce3ff-3d05-4e87-9e01-c97b66af13d4"},"name":"Lose Yourself","streamable":"0","mbid":"047a94b1-c42e-4867-8aa5-36d8c1f57d00","album":{"#text":"Lose Yourself","mbid":"0dc7d254-c4bf-4101-8f90-27a2f721722e"},"url":"http:\/\/www.last.fm\/music\/Eminem\/_\/Lose+Yourself","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/82366349.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/82366349.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/82366349.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/82366349.png","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 17:43","uts":"1359999789"}},{"artist":{"#text":"Eminem","mbid":"b95ce3ff-3d05-4e87-9e01-c97b66af13d4"},"name":"Mockingbird","streamable":"0","mbid":"0f530514-9275-45f4-a5d5-0264374c1261","album":{"#text":"Curtain Call","mbid":""},"url":"http:\/\/www.last.fm\/music\/Eminem\/_\/Mockingbird","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/81765923.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/81765923.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/81765923.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/81765923.png","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 17:38","uts":"1359999537"}},{"artist":{"#text":"Macklemore & Ryan Lewis","mbid":""},"name":"Thrift Shop - feat. Wanz","streamable":"0","mbid":"","album":{"#text":"Thrift Shop","mbid":""},"url":"http:\/\/www.last.fm\/music\/Macklemore+&+Ryan+Lewis\/_\/Thrift+Shop+-+feat.+Wanz","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/85090943.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/85090943.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/85090943.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/85090943.png","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 17:34","uts":"1359999255"}},{"artist":{"#text":"Macklemore & Ryan Lewis","mbid":""},"name":"Thrift Shop - feat. Wanz","streamable":"0","mbid":"","album":{"#text":"Thrift Shop","mbid":""},"url":"http:\/\/www.last.fm\/music\/Macklemore+&+Ryan+Lewis\/_\/Thrift+Shop+-+feat.+Wanz","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/85090943.png","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/85090943.png","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/85090943.png","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/85090943.png","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 17:29","uts":"1359998975"}},{"artist":{"#text":"Callejon","mbid":"97501ef9-b868-4d05-89d8-6161ccdf8d3f"},"name":"Alles nur geklaut","streamable":"1","mbid":"","album":{"#text":"Man spricht Deutsch","mbid":"d57af610-0996-41ff-9493-b6c5bff5da3e"},"url":"http:\/\/www.last.fm\/music\/Callejon\/_\/Alles+nur+geklaut","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/85713183.jpg","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/85713183.jpg","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/85713183.jpg","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/85713183.jpg","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 16:24","uts":"1359995076"}},{"artist":{"#text":"Callejon","mbid":"97501ef9-b868-4d05-89d8-6161ccdf8d3f"},"name":"Ein Kompliment","streamable":"1","mbid":"","album":{"#text":"Man spricht Deutsch","mbid":"d57af610-0996-41ff-9493-b6c5bff5da3e"},"url":"http:\/\/www.last.fm\/music\/Callejon\/_\/Ein+Kompliment","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/85713183.jpg","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/85713183.jpg","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/85713183.jpg","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/85713183.jpg","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 16:18","uts":"1359994723"}},{"artist":{"#text":"Callejon","mbid":"97501ef9-b868-4d05-89d8-6161ccdf8d3f"},"name":"Mein Block","streamable":"1","mbid":"","album":{"#text":"Man spricht Deutsch","mbid":"d57af610-0996-41ff-9493-b6c5bff5da3e"},"url":"http:\/\/www.last.fm\/music\/Callejon\/_\/Mein+Block","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/85713183.jpg","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/85713183.jpg","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/85713183.jpg","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/85713183.jpg","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 16:14","uts":"1359994490"}},{"artist":{"#text":"Callejon","mbid":"97501ef9-b868-4d05-89d8-6161ccdf8d3f"},"name":"Durch den Monsun","streamable":"1","mbid":"","album":{"#text":"Man spricht Deutsch","mbid":"d57af610-0996-41ff-9493-b6c5bff5da3e"},"url":"http:\/\/www.last.fm\/music\/Callejon\/_\/Durch+den+Monsun","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/85713183.jpg","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/85713183.jpg","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/85713183.jpg","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/85713183.jpg","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 16:11","uts":"1359994270"}},{"artist":{"#text":"Callejon","mbid":"97501ef9-b868-4d05-89d8-6161ccdf8d3f"},"name":"Ich Find Dich Schei\u00dfe","streamable":"1","mbid":"","album":{"#text":"Man spricht Deutsch","mbid":"d57af610-0996-41ff-9493-b6c5bff5da3e"},"url":"http:\/\/www.last.fm\/music\/Callejon\/_\/Ich+Find+Dich+Schei%C3%9Fe","image":[{"#text":"http:\/\/userserve-ak.last.fm\/serve\/34s\/85713183.jpg","size":"small"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/64s\/85713183.jpg","size":"medium"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/126\/85713183.jpg","size":"large"},{"#text":"http:\/\/userserve-ak.last.fm\/serve\/300x300\/85713183.jpg","size":"extralarge"}],"date":{"#text":"4 Feb 2013, 16:08","uts":"1359994098"}}],"@attr":{"user":"xxxx","page":"1","perPage":"10","totalPages":"2029","total":"20285"}}}
ご覧のとおり、現在再生中の最初の曲には @attribute があります
"@attr":{"nowplaying":"true"}
ここにいくつかのコードがあります:
info = last.read('user.getRecentTracks', user='xxxx')
for track in info['recenttracks']['track']:
title = track['name']
url = track['url']
by = track['artist']['#text']
form = '#np ' + by + ' - ' + title + ' ' + url
np = track['@attr']['nowplaying']
np
!を除いてすべて正常に動作します。のせい@
ですか?