Access Soundcloud Charts with API

前端 未结 2 516
清酒与你
清酒与你 2021-02-02 04:21

Is there an way to access the new charts https://soundcloud.com/charts/top (top 50) with the soundcloud api? Or is there an other way?

Maybe with an crawl with php or so

2条回答
  •  遥遥无期
    2021-02-02 05:03

    To found parameters that you can use with HTTP API Request, you can do this:

    • Go to "https://soundcloud.com/charts/" and open Console (F12 on Chrome).
    • Go inside Network Tab of Console and Refresh page (F5).
    • Clear Console.

    Now for example if you want know parameters for retrive "TOP 50 - Dance & EDM":

    • Change values inside the filter box
    • Check in the console, the request that start with: "charts?kind="
    • Search inside this url the parameters.

    Some example:

    TOP | Dance & EDM

    https ://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Ageneres%3Adanceedm&client_id=...

    TOP | Deep House

    https ://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Agenres%3Adeephouse&client_id=...

    New & Hot

    Country https ://api-v2.soundcloud.com/charts?kind=trending&genre=soundcloud%3Agenres%3Acountry&client_id=...


    All Parameters:

    kind:

    • top <- Top 50
    • trending <- New & Hot

    genre:

    • soundcloud:genres:all-music
    • soundcloud:genres:all-audio
    • soundcloud:genres:alternativerock
    • soundcloud:genres:ambient
    • soundcloud:genres:classical
    • soundcloud:genres:country
    • soundcloud:genres:danceedm
    • soundcloud:genres:dancehall
    • soundcloud:genres:deephouse
    • soundcloud:genres:disco
    • soundcloud:genres:drumbass
    • soundcloud:genres:dubstep
    • soundcloud:genres:electronic
    • soundcloud:genres:folksingersongwriter
    • soundcloud:genres:hiphoprap
    • soundcloud:genres:house
    • soundcloud:genres:indie
    • soundcloud:genres:jazzblues
    • soundcloud:genres:latin
    • soundcloud:genres:metal
    • soundcloud:genres:piano
    • soundcloud:genres:pop
    • soundcloud:genres:rbsoul
    • soundcloud:genres:reggae
    • soundcloud:genres:reggaeton
    • soundcloud:genres:rock
    • soundcloud:genres:soundtrack
    • soundcloud:genres:techno
    • soundcloud:genres:trance
    • soundcloud:genres:trap
    • soundcloud:genres:triphop
    • soundcloud:genres:world
    • soundcloud:genres:audiobooks
    • soundcloud:genres:business
    • soundcloud:genres:comedy
    • soundcloud:genres:entertainment
    • soundcloud:genres:learning
    • soundcloud:genres:newspolitics
    • soundcloud:genres:religionspirituality
    • soundcloud:genres:science
    • soundcloud:genres:sports
    • soundcloud:genres:storytelling
    • soundcloud:genres:technology

    Example in php to get a json response of TOP50 - Country:

    URL: https ://api-v2.soundcloud.com/charts?kind=top&genre=soundcloud%3Agenres%3Acountry&client_id=XXXXXXXXXXX&limit=10&linked_partitioning=1

    URL Parameters:
    Kind: Top
    Genre: soundcloud:genres:country
    client_id: XXXXXXXXXXX
    limit: 10
    linked_partitioning: 1

    limit: how many songs you want to receive in response.
    linked_partitioning: page number, according to the limit.

    e.g. linked_partitioning with Limit = 10:

    • 1 get song from 0 to 9
    • 2 get song from 10 to 19
    • ...

    e.g. linked_partitioning with Limit = 20:

    • 1 get song from 0 to 19
    • 2 get song from 20 to 39
    • ...

    Now that you have URL, if you want retrive JSON response with PHP
    you have to write for example:

    Example Json Response:

    {
        "genre":"soundcloud:genres:country",
        "kind":"top",
        "last_updated":"2016-03-24T09:50:02Z",
        "collection":[
            {
                "track":{
                    "commentable":true,
                    "comment_count":211,
                    "downloadable":true,
                    "download_count":80,
                    "duration":251060,
                    .
                    .
                    .
                    "kind":"track",
                    .
                    .
                    .
                    .
                    "license":"all-rights-reserved",
                    "streamable":true,
                    "title":"Award winning Falling Star",
                    "uri":"https://api.soundcloud.com/tracks/245170733",
                    .                
                    .
                    .
                    "country_code":"US"
                }
                "score":1093171.0
            },
            {
                ...
            },
            OTHER TRACKS HERE...
        ],
        "query_urn":"soundcloud:charts:bc9b903f2cee44e7bca955bc2fc4601d",
        "next_href":"https://api-v2.soundcloud.com/charts?genre=soundcloud%3Agenres%3Acountry&query_urn=soundcloud%3Acharts%3Abc9b903f2cee44e7bca955bc2fc4601d&offset=20&kind=top&limit=20"
        }
    }
    

    If you want read JSON content of response:

        // Read Json taking for example Name, Title and SoundCloud URI of song.
        foreach ($objectJSON["collection"] as $key => $value) {
            echo 'user: ' . $value['track']['user']['full_name'] . "
    "; echo 'title: ' . $value['track']['title'] . "
    "; echo 'url: ' . $value['track']['uri'] . "

    "; } echo $response; ?>

    Result of this PHP:

    user: ...
    title: ...
    url: ...
    
    user: ...
    title: ...
    url: ...
    
    ...
    

    Example of this code


    I hope I have helped you and sorry for my english.

    EDIT:

    I think that SoundCloud has changed the way to get the next page. Now you need to change the "offset" param.

    Like this:

    Page 1: ....&limit=20&offset=0
    Page 2: ....&limit=20&offset=20
    Page 3: ....&limit=20&offset=40
    

    ANSWER FOR @VietHung QUESTION.

    Q: Can you explore system playlists? (Eg: soundcloud:system-playlists charts-top:all-music)

    To find system playlist, I have used Charles Web Debugging Proxy.
    The idea is to sniff network package sent by SoundClound App from iOS device (in my case).

    After that you configure Charles to sniff SSL packages correctly, you can use you pc as proxy for your smartphone.
    (You must install Charles cert on Windows and on iOS device to sniff SSL packages correctly, for more information search on google).

    Now, open SoundCloud App and click on every playlists (TOP, NEWS) inside the app. Below a screenshot (Quality powered by paint, sorry ahah):

    Now inside Charles we can see something like this:

    I set the focus only on the SoundCloud host for better reading of incoming packages.
    Charles is smart and puts all similar requests into a subfolder, in our case we have to look at all the requests within 'system-playlist'.

    Now from all requests you can retrieve all system playlists values.

    I have not listed all playlist song because currently I do not have much time.
    As soon as I can, I edit this post with the complete list of possible system playlists vales.

提交回复
热议问题