spotify 0.1.6+3

spotify-dart Pub Build Status

A dart library for interfacing with the Spotify API.

Usage #

A simple usage example:

import 'package:spotify/spotify_io.dart';

main() async {
  var credentials = new SpotifyApiCredentials(clientId, clientSecret);
  var spotify = new SpotifyApi(credentials);

  var artist = await spotify.artists.get('0OdUWJ0sBjDrqHygGUXeCF');
}

For usage in the browser use #

import 'package:spotify/spotify_browser.dart';

Features and bugs #

Please file feature requests and bugs at the issue tracker.

Development #

Generating JSON Serializers #

Run pub run build_runner build to generate JSON serilizers via json_serializable.

Changelog #

0.1.6+3 #

  • fix typo in tracks object
  • move album model switch to model

0.1.5+1 #

  • add external_ids and external_urls

0.1.4 #

  • add related-artists to the artists endpoint

0.1.3+2 #

  • use full Track object in search endpoint

0.1.3+1 #

  • eliminate duplicate code (serializers)

0.1.3 #

  • add currently playing endpoint

0.1.2 #

  • make pub analyzer happy

0.1.1 #

  • add search endpoint

0.0.9 - 0.1.0 #

  • support Dart 2 with switch to json_serializable

0.0.8 #

  • add missing _putImpl implementation to SpotifyMock

0.0.7 #

  • add user's saved tracks endpoints

0.0.6 #

  • add pagination support

0.0.5 #

  • add user and playlist endpoints

0.0.4 #

  • fix typo in artists endpoint
  • add basic unit tests

0.0.3 #

  • add support for albums and artists
  • refactor code a little

0.0.1 #

  • Initial version

example/example.dart

// Copyright (c) 2017, rinukkusu. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.

import 'dart:io';
import 'dart:convert';
import '../lib/spotify_io.dart';

main() async {
  var keyJson = await new File('example/.apikeys').readAsString();
  var keyMap = json.decode(keyJson);

  var credentials = new SpotifyApiCredentials(keyMap['id'], keyMap['secret']);
  var spotify = new SpotifyApi(credentials);

  print("Artists:");
  var artists = await spotify.artists.list(['0OdUWJ0sBjDrqHygGUXeCF']);
  artists.forEach((x) => print(x.name));

  print("\nAlbum:");
  var album = await spotify.albums.get('2Hog1V8mdTWKhCYqI5paph');
  print(album.name);

  print("\nAlbum Tracks:");
  var tracks = await spotify.albums.getTracks(album.id).all();
  tracks.forEach((track) {
    print(track.name);
  });

  print("\nFeatured Playlist:");
  var featuredPlaylists = await spotify.playlists.featured.all();
  featuredPlaylists.forEach((playlist) {
    print(playlist.name);
  });

  print("\nSearching for \'Metallica\':");
  var search = await spotify.search
      .get("metallica")
      .first(2)
      .catchError((err) => print((err as SpotifyException).message));
  if (search == null) {
    return;
  }
  search.forEach((pages) {
    pages.items.forEach((item) {
      if (item is PlaylistSimple) {
        print('Playlist: \n'
            'id: ${item.id}\n'
            'name: ${item.name}:\n'
            'collaborative: ${item.collaborative}\n'
            'href: ${item.href}\n'
            'trackslink: ${item.tracksLink.href}\n'
            'owner: ${item.owner}\n'
            'public: ${item.owner}\n'
            'snapshotId: ${item.snapshotId}\n'
            'type: ${item.type}\n'
            'uri: ${item.uri}\n'
            'images: ${item.images.length}\n'
            '-------------------------------');
      }
      if (item is Artist) {
        print('Artist: \n'
            'id: ${item.id}\n'
            'name: ${item.name}\n'
            'href: ${item.href}\n'
            'type: ${item.type}\n'
            'uri: ${item.uri}\n'
            '-------------------------------');
      }
      if (item is TrackSimple) {
        print('Track:\n'
            'id: ${item.id}\n'
            'name: ${item.name}\n'
            'href: ${item.href}\n'
            'type: ${item.type}\n'
            'uri: ${item.uri}\n'
            'isPlayable: ${item.isPlayable}\n'
            'artists: ${item.artists.length}\n'
            'availableMarkets: ${item.availableMarkets.length}\n'
            'discNumber: ${item.discNumber}\n'
            'trackNumber: ${item.trackNumber}\n'
            'explicit: ${item.explicit}\n'
            '-------------------------------');
      }
      if (item is AlbumSimple) {
        print('Album:\n'
            'id: ${item.id}\n'
            'name: ${item.name}\n'
            'href: ${item.href}\n'
            'type: ${item.type}\n'
            'uri: ${item.uri}\n'
            'albumType: ${item.albumType}\n'
            'artists: ${item.artists.length}\n'
            'availableMarkets: ${item.availableMarkets.length}\n'
            'images: ${item.images.length}\n'
            '-------------------------------');
      }
    });
  });

  var relatedArtists = await spotify.artists.relatedArtists('0OdUWJ0sBjDrqHygGUXeCF');
  print('related Artists: ${relatedArtists.length}');
  exit(0);
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  spotify: ^0.1.6+3

2. Install it

You can install packages from the command line:

with pub:


$ pub get

Alternatively, your editor might support pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:spotify/spotify_browser.dart';
import 'package:spotify/spotify_io.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
69
Health:
Code health derived from static analysis. [more]
68
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
73
Learn more about scoring.

We analyzed this package on Aug 22, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.4.0
  • pana: 0.12.19

Platforms

Detected platforms: web

Platform components identified in package: html, io.

Health suggestions

Fix lib/src/models/track.dart. (-10.89 points)

Analysis of lib/src/models/track.dart reported 23 hints, including:

line 8 col 11: Use ; instead of {} for empty constructor bodies.

line 11 col 3: Prefer using /// for doc comments.

line 17 col 3: Prefer using /// for doc comments.

line 23 col 3: Prefer using /// for doc comments.

line 30 col 3: Prefer using /// for doc comments.

Fix lib/src/models/audio_feature.dart. (-6.78 points)

Analysis of lib/src/models/audio_feature.dart reported 14 hints, including:

line 8 col 18: Use ; instead of {} for empty constructor bodies.

line 12 col 3: Prefer using /// for doc comments.

line 18 col 3: Prefer using /// for doc comments.

line 25 col 3: Prefer using /// for doc comments.

line 41 col 3: Prefer using /// for doc comments.

Fix lib/src/models/album.dart. (-4.89 points)

Analysis of lib/src/models/album.dart reported 10 hints, including:

line 8 col 11: Use ; instead of {} for empty constructor bodies.

line 18 col 3: Prefer using /// for doc comments.

line 30 col 3: Prefer using /// for doc comments.

line 37 col 3: Prefer using /// for doc comments.

line 44 col 3: Prefer using /// for doc comments.

Fix additional 11 files with analysis or formatting issues. (-14.89 points)

Additional issues in the following files:

  • lib/src/endpoints/endpoint_paging.dart (9 hints)
  • lib/src/models/artist.dart (4 hints)
  • lib/src/models/playlist.dart (4 hints)
  • lib/src/models/external_objects.dart (2 hints)
  • lib/src/models/followers.dart (2 hints)
  • lib/src/models/player.dart (2 hints)
  • lib/src/models/token_request.dart (2 hints)
  • lib/src/models/user.dart (2 hints)
  • lib/src/models/error.dart (1 hint)
  • lib/src/models/image.dart (1 hint)
  • lib/src/models/paging.dart (1 hint)

Maintenance issues and suggestions

Support latest dependencies. (-10 points)

The version constraint in pubspec.yaml does not support the latest published versions for 1 dependency (json_annotation).

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0 <3.0.0
http ^0.12.0 0.12.0+2
json_annotation ^2.0.0 2.4.0 3.0.0
Transitive dependencies
async 2.3.0
charcode 1.1.2
collection 1.14.12
http_parser 3.1.3
meta 1.1.7
path 1.6.4
pedantic 1.8.0+1
source_span 1.5.5
string_scanner 1.0.5
term_glyph 1.1.0
typed_data 1.1.6
Dev dependencies
build_runner ^1.1.1
json_serializable ^2.0.0
test ^1.5.1