Frage

I'm still trying to write a function in JavaScript where the user can type in an artist, and it will return a link to that artist's SoundCloud page.

For example,

/artist beyonce --> https://soundcloud.com/beyoncemusic 

But the SoundCloud URLS don't all act the same. For example,

/artist dave matthews band --> https://soundcloud.com/dave-matthews-band. 

For this reason, I can't simply just output scLink/artistName because they all have different URLs. I'm using Node.js, so I looked through a lot of npm packages, but couldn't figure out how to use any for this purpose. Perhaps Soundclouder will work somehow (though I couldn't figure it out myself). Does anyone know how I could write a command like this?

War es hilfreich?

Lösung

You are using the SoundCloud API, right?

A simple HTTP request to the right API should return the data you want. For example:

http://api.soundcloud.com/users.json?q=beyonce

[
  {
    "id": 4293843,
    "kind": "user",
    "permalink": "beyoncemusic",
    "username": "Beyoncé",
    "uri": "http://api.soundcloud.com/users/4293843",
    "permalink_url": "http://soundcloud.com/beyoncemusic",
    "avatar_url": "http://i1.sndcdn.com/avatars-000036935308-a2acxy-large.jpg?435a760",
    "country": "United States",
    "full_name": "Beyoncé",
    "description": "",
    "city": "New York",
    "discogs_name": null,
    "myspace_name": "beyonce",
    "website": "http://www.beyonceonline.com",
    "website_title": "",
    "online": false,
    "track_count": 33,
    "playlist_count": 2,
    "plan": "Pro Plus",
    "public_favorites_count": 0,
    "followers_count": 478783,
    "followings_count": 0,
    "subscriptions": [
      {
        "product": {
          "id": "creator-pro-unlimited",
          "name": "Pro Unlimited"
        }
      }
    ]
  },
  ...
]

...so you could just do results[0].permalink_url.

You can use the request module to make the HTTP request manually, or use soundclouder to handle SoundCloud API's authentication details.


Most of the above does not apply if you want to make the actual requests from a browser. (The question is tagged node.js, but it sounds like you want to do this from a web page.)

If you're doing this from a webpage, use the SoundCloud JS SDK. The data you get back will look like the example above.

Andere Tipps

I don't think you'd be able to get an exact match reliably. Your best bet would be to search for users with the string you are looking for - example: "beyonce" and then to show the results and let them pick the correct link. You may be able to filter out likely results with follower count (high follower count) or something after you've pulled the initial list from soundcloud.

Search code:

users = SC.get('/users', { q: 'beyonce' });

Then iterate over users and display the permalink url. Hope this helps.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top