Git Product home page Git Product logo

apple_music's Introduction

AppleMusic

This is a ruby wrapper for the Apple Music API.

Installation

Add this line to your application's Gemfile:

gem 'apple_music'

And then execute:

$ bundle

Or install it yourself as:

$ gem install apple_music

Usage

AppleMusic gem was designed with usability as its primary goal:

e.g. Search Artists

artist = AppleMusic::Artist.search('Men I Trust').first # AppleMusic::Artist object
artist.genre_names # ['Electronic']
artist.id # "886240553"
albums = AppleMusic::Artist.related_albums(886240553).map(&:name) # ["Oncle Jazz", "Headroom"...

e.g. Search Albums

albums = AppleMusic::Album.search('BILL EVANS') # AppleMusic::Album object
tracks = AppleMusic::Album.related_tracks(albums[0].id)
tracks.first.name # "Waltz for Debby"

e.g. Search Songs

songs = AppleMusic::Song.search('Document', storefront: :jp) # AppleMusic::Song object
songs[0].artist_name # "TENDRE"
songs[0].album_name # "NOT IN ALMIGHTY"

Features

Currently, it work in progress, so it can use apis which does not need user token.

Albums

Feature Status Docs Code
Get a Catalog Album โœ… ๐Ÿ”— :octocat:
Get a Catalog Album's Relationship Directly by Name โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Albums โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Albums by UPC โœ… ๐Ÿ”— :octocat:
Get a Library Album โ›” ๐Ÿ”—
Get a Library Album's Relationship Directly by Name โ›” ๐Ÿ”—
Get Multiple Library Albums โ›” ๐Ÿ”—
Get All Library Albums โ›” ๐Ÿ”—

Artists

Feature Status Docs Code
Get a Catalog Artist โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Artists โœ… ๐Ÿ”— :octocat:
Get a Catalog Artist's Relationship Directly by Name โœ… ๐Ÿ”— :octocat:
Get a Library Artist โ›” ๐Ÿ”—
Get All Library Artists โ›” ๐Ÿ”—
Get Multiple Library Artists โ›” ๐Ÿ”—
Get a Library Artist's Relationship Directly by Name โ›” ๐Ÿ”—

Songs

Feature Status Docs Code
Get a Catalog Song โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Songs by ID โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Songs by ISRC โœ… ๐Ÿ”— :octocat:
Get a Catalog Song's Relationship Directly by Name โœ… ๐Ÿ”— :octocat:
Get a Library Song โ›” ๐Ÿ”—
Get All Library Songs โ›” ๐Ÿ”—
Get Multiple Library Songs โ›” ๐Ÿ”—
Get a Library Song's Relationship Directly by Name โ›” ๐Ÿ”—

Music Videos

Feature Status Docs Code
Get a Catalog Music Video โœ… ๐Ÿ”— :octocat:
Get a Catalog Music Video's Relationship Directly by Name โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Music Videos by ID โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Music Videos by ISRC โœ… ๐Ÿ”— :octocat:
Get a Library Music Video โ›” ๐Ÿ”—
Get a Library Music Video's Relationship Directly by Name โ›” ๐Ÿ”—
Get Multiple Library Music Videos โ›” ๐Ÿ”—
Get All Library Music Videos โ›” ๐Ÿ”—

Playlists

Feature Status Docs Code
Get a Catalog Playlist โœ… ๐Ÿ”— :octocat:
Get a Catalog Playlist's Relationship Directly by Name โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Playlists โœ… ๐Ÿ”— :octocat:
Get a Library Playlist โ›” ๐Ÿ”—
Get a Library Playlist's Relationship Directly by Name โ›” ๐Ÿ”—
Get Multiple Library Playlists โ›” ๐Ÿ”—
Get All Library Playlists โ›” ๐Ÿ”—

Apple Music Stations

Feature Status Docs Code
Get a Catalog Station โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Stations โœ… ๐Ÿ”— :octocat:

Search

Feature Status Docs Code
Search for Catalog Resources โœ… ๐Ÿ”— :octocat:
Get Catalog Search Hints โœ… ๐Ÿ”— :octocat:
Search for Library Resources โ›” ๐Ÿ”—

Ratings

Feature Status Docs Code
Get a Personal Album Rating โ›” ๐Ÿ”—
Get a Personal Music Video Rating โ›” ๐Ÿ”—
Get a Personal Playlist Rating โ›” ๐Ÿ”—
Get a Personal Song Rating โ›” ๐Ÿ”—
Get a Personal Station Rating โ›” ๐Ÿ”—
Get Multiple Personal Album Ratings โ›” ๐Ÿ”—
Get Multiple Personal Music Video Ratings โ›” ๐Ÿ”—
Get Multiple Personal Playlist Ratings โ›” ๐Ÿ”—
Get Multiple Personal Song Ratings โ›” ๐Ÿ”—
Get Multiple Personal Station Ratings โ›” ๐Ÿ”—
Add a Personal Album Rating โ›” ๐Ÿ”—
Add a Personal Music Video Rating โ›” ๐Ÿ”—
Add a Personal Playlist Rating โ›” ๐Ÿ”—
Add a Personal Song Rating โ›” ๐Ÿ”—
Add a Personal Station Rating โ›” ๐Ÿ”—
Delete a Personal Album Rating โ›” ๐Ÿ”—
Delete a Personal Music Video Rating โ›” ๐Ÿ”—
Delete a Personal Playlist Rating โ›” ๐Ÿ”—
Delete a Personal Song Rating โ›” ๐Ÿ”—
Delete a Personal Station Rating โ›” ๐Ÿ”—
Get a Personal Library Music Video Rating โ›” ๐Ÿ”—
Get a Personal Library Playlist Rating โ›” ๐Ÿ”—
Get a Personal Library Song Rating โ›” ๐Ÿ”—
Get Multiple Personal Library Music Video Ratings โ›” ๐Ÿ”—
Get Multiple Personal Library Playlist Ratings โ›” ๐Ÿ”—
Get Multiple Personal Library Songs Ratings โ›” ๐Ÿ”—
Add a Personal Library Music Video Rating โ›” ๐Ÿ”—
Add a Personal Library Playlist Rating โ›” ๐Ÿ”—
Add a Personal Library Song Rating โ›” ๐Ÿ”—
Delete a Personal Library Music Video Rating โ›” ๐Ÿ”—
Delete a Personal Library Playlist Rating โ›” ๐Ÿ”—
Delete a Personal Library Song Rating โ›” ๐Ÿ”—

Charts

Feature Status Docs Code
Get Catalog Charts โœ… ๐Ÿ”— :octocat:

Music Genres

Feature Status Docs Code
Get a Catalog Genre โœ… ๐Ÿ”— :octocat:
Get a Catalog Genre's Relationship Directly by Name โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Genres โœ… ๐Ÿ”— :octocat:
Get Catalog Top Charts Genres โœ… ๐Ÿ”— :octocat:

Curators

Feature Status Docs Code
Get a Catalog Curator โœ… ๐Ÿ”— :octocat:
Get a Catalog Curator's Relationship Directly by Name โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Curators โœ… ๐Ÿ”— :octocat:
Get a Catalog Apple Curator โ›” ๐Ÿ”—
Get a Catalog Apple Curator's Relationship Directly by Name โ›” ๐Ÿ”—
Get Multiple Catalog Apple Curators โ›” ๐Ÿ”—

Recommendations

Feature Status Docs Code
Get a Recommendation โ›” ๐Ÿ”—
Get Multiple Recommendations โ›” ๐Ÿ”—
Get Default Recommendations โ›” ๐Ÿ”—

Activities

Feature Status Docs Code
Get a Catalog Activity โœ… ๐Ÿ”— :octocat:
Get a Catalog Activity's Relationship Directly by Name โœ… ๐Ÿ”— :octocat:
Get Multiple Catalog Activities โœ… ๐Ÿ”— :octocat:

History

Feature Status Docs Code
Get Heavy Rotation Content โ›” ๐Ÿ”—
Get Recently Played Resources โ›” ๐Ÿ”—
Get Recently Played Stations โ›” ๐Ÿ”—
Get Recently Added Resources โ›” ๐Ÿ”—

Storefronts and Localization

Feature Status Docs Code
Get a User's Storefront โœ… ๐Ÿ”— :octocat:
Get a Storefront โœ… ๐Ÿ”— :octocat:
Get Multiple Storefronts โœ… ๐Ÿ”— :octocat:
Get All Storefronts โœ… ๐Ÿ”— :octocat:

Configuration

NOTE It's necessary to prepare an TEAM_ID, MUSIC_ID, and a secret file in advance. Please confirm Apple Developer Website.

It can be set by either an ENV variable or an config/initializers/apple_music.rb:

AppleMusic.configure do |config|
  config.secret_key_path = './AuthKey_MUSIC_ID.p8' # or ENV['APPLE_MUSIC_SECRET_KEY_PATH']
  config.team_id         = 'YOUR TEAM_ID'          # or ENV['APPLE_MUSIC_TEAM_ID']
  config.music_id        = 'YOUR MUSIC_ID'         # or ENV['APPLE_MUSIC_MUSIC_ID']
  config.storefront      = 'jp'                    # or ENV['APPLE_MUSIC_STOREFRONT'] ('us' by default)
end

License

MIT

apple_music's People

Contributors

dependabot[bot] avatar homologist avatar shiroemons avatar sjaveed avatar yhirano55 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

apple_music's Issues

undefined method `configure' for AppleMusic:Module

I have added gem in rails 6 app.
& created a file in config/initializers named apple_music.rb with settings

AppleMusic.configure do |config|
  config.secret_key_path = ENV['APPLE_MUSIC_SECRET_KEY_PATH']
  config.team_id         = ENV['APPLE_MUSIC_TEAM_ID']
  config.music_id        = ENV['APPLE_MUSIC_MUSIC_ID']
  config.storefront      = 'us' 
end

but gives error saying

undefined method `configure' for AppleMusic:Module

Handle re-intializing a new client when the auth token expires

Problem:
I was seeing that after having my server running a while, search results for songs that had been returning results were suddenly an empty array. Inspecting the API's results before the gem returned them showed a 401 error.

Looking at the gem's connection.rb, the client is being memoized with the config.authentication_token which expires after a day.

One suggestion is to improve the handling of API responses to alert when the request is no longer authenticated. This would have helped me see the real problem immediately.

Another suggestion is to check if the token is expired and initialize a new client with a fresh token.

TypeError: no implicit conversion of nil into String

TypeError: no implicit conversion of nil into String
  from apple_music (c78cf4ffa6fe) lib/apple_music/song/attributes.rb:30:in `parse'
  from apple_music (c78cf4ffa6fe) lib/apple_music/song/attributes.rb:30:in `initialize'
  from apple_music (c78cf4ffa6fe) lib/apple_music/resource.rb:37:in `new'
  from apple_music (c78cf4ffa6fe) lib/apple_music/resource.rb:37:in `initialize'
  from apple_music (c78cf4ffa6fe) lib/apple_music/resource.rb:27:in `new'
  from apple_music (c78cf4ffa6fe) lib/apple_music/resource.rb:27:in `build'
  from apple_music (c78cf4ffa6fe) lib/apple_music/relationship.rb:20:in `block in build_list'
  from apple_music (c78cf4ffa6fe) lib/apple_music/relationship.rb:20:in `map'
  from apple_music (c78cf4ffa6fe) lib/apple_music/relationship.rb:20:in `build_list'
  from apple_music (c78cf4ffa6fe) lib/apple_music/relationship.rb:11:in `initialize'
  from apple_music (c78cf4ffa6fe) lib/apple_music/search_result.rb:16:in `new'
  from apple_music (c78cf4ffa6fe) lib/apple_music/search_result.rb:16:in `initialize'
  from apple_music (c78cf4ffa6fe) lib/apple_music/search.rb:20:in `new'
  from apple_music (c78cf4ffa6fe) lib/apple_music/search.rb:20:in `search'
  from apple_music (c78cf4ffa6fe) lib/apple_music.rb:35:in `search'
  from apple_music (c78cf4ffa6fe) lib/apple_music/song.rb:74:in `search'

ArgumentError: wrong number of arguments (given 3, expected 2) when calling relationships

Context:
ruby: 3.0.4
rails: 6.1

the issue

ArgumentError: wrong number of arguments (given 3, expected 2)
from /usr/local/bundle/gems/apple_music-0.3.1/lib/apple_music/album.rb:47:in `get_relationship'

Same happens when calling ::Apple::Artist.related_albums(artist.id) for instance

PS: If you need that feature now you can call
AppleMusic::Album.get_relationship(raw.id, :artists) to get the related artists of an album for instance

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.