{"id":18019905,"url":"https://github.com/vpaliy/last.fm-api","last_synced_at":"2025-09-02T22:33:10.122Z","repository":{"id":97269441,"uuid":"99430155","full_name":"vpaliy/last.fm-api","owner":"vpaliy","description":"Last.fm API wrapped into a bunch of classes. Built with OkHttp, Retrofit2, RxJava2.","archived":false,"fork":false,"pushed_at":"2018-09-30T22:30:51.000Z","size":184,"stargazers_count":40,"open_issues_count":0,"forks_count":5,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-03-22T11:24:36.386Z","etag":null,"topics":["api-wrapper","lastfm-api","retrofit2","rxjava2"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/vpaliy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2017-08-05T15:10:21.000Z","updated_at":"2024-12-15T16:13:53.000Z","dependencies_parsed_at":null,"dependency_job_id":"2bda2aef-499d-4958-aabd-d8cfc730c0c4","html_url":"https://github.com/vpaliy/last.fm-api","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2Flast.fm-api","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2Flast.fm-api/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2Flast.fm-api/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/vpaliy%2Flast.fm-api/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/vpaliy","download_url":"https://codeload.github.com/vpaliy/last.fm-api/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":245731487,"owners_count":20663198,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["api-wrapper","lastfm-api","retrofit2","rxjava2"],"created_at":"2024-10-30T05:12:52.802Z","updated_at":"2025-03-26T20:31:34.699Z","avatar_url":"https://github.com/vpaliy.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# last.fm  API\n[![](https://jitpack.io/v/vpaliyX/Last.fm-API.svg)](https://jitpack.io/#vpaliyX/Last.fm-API)\n\n\nThis project is a wrapper for the [Last.fm API](https://www.last.fm/api/). \nThe last.fm API allows anyone to build their applications using the last.fm data. \n\nHere's the list of the most useful things you can do with this API:\n\n- **get** artists, tags, albums, users, tracks, charts\n- **get** the most popular items (artists,tracks,albums,tags)\n- **get** info of an item.\n- **get** a list of the most popular artists or tracks by a country name.\n- **add/remove** a tag to/from an artist, track, album\n- **like/unlike** a track \n- **retrieve** data from a user (favorite items,tracks, albums, info, recent tracks, charts)\n- **search** for an item.\n- **log in/log out**\n\n## How do I use this wrapper? ##\n\n### Step 1 ###  \n\nAdd this to your root `build.gradle` file:\n\n``` gradle\nallprojects {\n  repositories {\n     maven { url 'https://jitpack.io' }\n  }\n}\n```\n### Step 2 ###\n\nAdd the dependency\n\n``` gradle\ndependencies {\n     compile 'com.github.vpaliyX:Last.fm-API:v1.2.0'\n}\n\n```\n\n## Nuts and Bolts ##\n\nThis wrapper is built with Retrofit2 and RxJava2. Basically, the wrapper is divided into 3 main abstractions:\n- **Authentication** - authentication of a user, provides a session key.\n- **Update Service** - all write requests (POST).\n- **Last.fm Service** - all read requests (GET).\n\nRegardless of which request you want to make, you will need to have an API_KEY and a SECRET_KEY. You can obtain this [here](https://www.last.fm/api/account/create), it takes only 2 min to get it.\n\n**Note** \nDue to the complex structure of JSON data returned by the web service, all requests are using a wrapper called [Response](https://github.com/vpaliyX/Last.fm-API/blob/master/last-fm-api/src/main/java/com/vpaliy/last_fm_api/model/Response.java) which is the response of a request. Just access the [Response.result](https://github.com/vpaliyX/Last.fm-API/blob/master/last-fm-api/src/main/java/com/vpaliy/last_fm_api/model/Response.java#L13) field of that object, and you will get your desired data. \n\n## Authentication ## \n\nIt's super simple. \n\nFirst of all, **last.fm** provides you with a **session key** which *never expires*.\nThis way you don't have to refresh this at all. Once you have obtained you session key, you can do any of the POST requests.\n\nSecondly, if you don't want to do POST requests, then you don't need a session key. You can skip this step since you won't need to have a session key for GET requests.\n\nThe [LastFmAuth](https://github.com/vpaliyX/Last.fm-API/blob/master/last-fm-api/src/main/java/com/vpaliy/last_fm_api/auth/LastFmAuth.java) class is responsible for the authorization, it encapsulates some additional steps, you just need to provide a **username** and **password**. Once you've done that, \nyou will receive a session key.\n\nHere's how it should work:\n\n```java\nLastFmAuth.create(Config.API_KEY,Config.API_SECRET)\n      .auth(context,\"username\",\"password\")\n      .subscribeOn(Schedulers.io())\n      .observeOn(AndroidSchedulers.mainThread())\n      .subscribe(response -\u003e {\n          Session session=response.result;\n       });\n\n```\n\n**Note**\nThe [Session](https://github.com/vpaliyX/Last.fm-API/blob/master/last-fm-api/src/main/java/com/vpaliy/last_fm_api/model/Session.java) object, which has been provided after the call, will be needed to perform POST requests, \nso you can just save it in the shared preferences with one helper method:\n\n```java\n   SharedPreferences.Editor editor=pref.edit();\n   editor.putString(\"key\",Session.convertToString(session)).apply();\n```\nAnd if you need this again, you can just retrieve from your shared preferences:\n\n```java\n\nSession session=Session.convertFromString(pref.getString(\"key\",null));\n\n```\n\n## Update Service ## \n\nHere you need to provide only a `Context` and a `Session` object. You can access the write calls with the [LastFmUpdate](https://github.com/vpaliyX/Last.fm-API/blob/master/last-fm-api/src/main/java/com/vpaliy/last_fm_api/auth/LastFmUpdate.java) class, here is an example:\n\n```java\n  LastFmUpdate.create(context,session)\n      .addTagsToAlbum(\"artist\",\"album\",\"tag1\",\"tag2\",\"tag3\")\n      .subscribeOn(Schedulers.io())\n      .observeOn(AndroidSchedulers.mainThread())\n      .subscribe(()-\u003e{},Throwable::printStackTrace);\n```\n\nAlso, you can use chains, so you can make a few requests at the same time:\n\n```java\nLastFmUpdate.create(this,session)\n       .startChain()\n       .addTagsToAlbum(\"Imagine Dragons\",\"Evolve\",\"#favorite\",\"#album\")\n       .addTagsToArtist(\"Imagine Dragons\",\"#favorite\",\"#lovely\")\n       .unloveTrack(\"Imagine Dragons\",\"Demons\")\n       .loveTrack(\"Imagine Dragons\",\"Whatever It Takes\")\n       .addTagsToTrack(\"Imagine Dragons\",\"Rise Up\",\"#summer2017\")\n       .addTagsToTrack(\"Imagine Dragons\",\"Walking the Wire\",\"#summer2017\")\n       .stop()\n       .subscribeOn(Schedulers.io())\n       .observeOn(AndroidSchedulers.mainThread())\n       .subscribe(()-\u003e{},Throwable::printStackTrace);\n```\n\nUse the `startChain()` method to create a chain, and the `stop()` method to stop it.\n\nAll POST requests return a [Completable](http://reactivex.io/RxJava/2.x/javadoc/io/reactivex/Completable.html) object, which represents a deferred computation without any value but only indication for completion or exception. It's either success or failure when you subscribe to it.\n\n## Last.fm Service ##\n\nYou can access this service without any Session object. It just works.\n\nUse the [LastFm](https://github.com/vpaliyX/Last.fm-API/blob/master/last-fm-api/src/main/java/com/vpaliy/last_fm_api/LastFm.java) class to create the service:\n\n```java\n //get the service\n LastFmService service=LastFm.create(Config.API_KEY)\n            .createService(this);\n            \n//request an artist      \nservice.fetchArtist(\"name of an artist\")\n      .subscribeOn(Schedulers.io())\n      .observeOn(AndroidSchedulers.mainThread())\n      .subscribe(response -\u003e {\n            Artist artist=response.result;\n       });\n```\n\n## Additional Documentation And Support ##\n- The [Last.fm API Documentation](https://www.last.fm/api/intro).\n- If you have any questions or you have found some issues, feel free to write in the [Issue Section](https://github.com/vpaliyX/Last-fm-API/issues).\n\n\n\n## The End. ##\n\n``````\nMIT License\n\nCopyright (c) 2017 Vasyl Paliy\n\nPermission is hereby granted, free of charge, to any person obtaining a copy\nof this software and associated documentation files (the \"Software\"), to deal\nin the Software without restriction, including without limitation the rights\nto use, copy, modify, merge, publish, distribute, sublicense, and/or sell\ncopies of the Software, and to permit persons to whom the Software is\nfurnished to do so, subject to the following conditions:\n\nThe above copyright notice and this permission notice shall be included in all\ncopies or substantial portions of the Software.\n\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR\nIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,\nFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE\nAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER\nLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,\nOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE\nSOFTWARE.\n``````\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpaliy%2Flast.fm-api","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fvpaliy%2Flast.fm-api","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fvpaliy%2Flast.fm-api/lists"}