Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9229783
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T05:39:28+00:00 2026-06-18T05:39:28+00:00

I am working with the last.fm-API. I have a problem with the currently playing

  • 0

I am working with the last.fm-API.

I have a problem with the currently playing song.
Here is an example of a JSON-output:

{"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"}}}

As you can see, the first song, which is currently playing has an @attribute

"@attr":{"nowplaying":"true"}

Here is some code:

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']

Everything works fine except for np!
Is it because of the @?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T05:39:30+00:00Added an answer on June 18, 2026 at 5:39 am

    Not all tracks have a @attr key, test for it first:

    np = track['@attr']['nowplaying'] if '@attr' in track else ''
    

    In fact, only the very first entry has that key, probably because you only play one track at a time, the topmost one in the list of tracks played.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im trying to append some JSON data from the last.fm API, I have been
I'm working on developing an API. Started with a concept last year and have
This was working last night, but I must have accidentally changed something, because it
I have a fantasy football league rails app that was working last year and
Real problem with an existing webapp which has been working for the last couple
I have been working on a Facebook app for the last couple of weeks.
Hi i'm working on facebook api. i have gone through facebook documentation and coded
I have a demo of gcm working here: http://leobee.com/android/push/login/gcm/updateusers.php If you refresh the page,
I have a problem. I've been working with Android in Eclipse for the past
I have wasted 1 hour on api.jquery.com and my script to identify the problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.