-
Notifications
You must be signed in to change notification settings - Fork 94
/
Copy pathexample.dart
146 lines (128 loc) · 4.84 KB
/
example.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
// Copyright (c) 2017, 2020 rinukkusu, hayribakici. All rights reserved. Use of this source code
// is governed by a BSD-style license that can be found in the LICENSE file.
// ignore_for_file: deprecated_member_use_from_same_package
import 'dart:io';
import 'dart:convert';
import 'package:spotify/spotify.dart';
void main() async {
var keyJson = await File('example/.apikeys').readAsString();
var keyMap = json.decode(keyJson);
var credentials = SpotifyApiCredentials(keyMap['id'], keyMap['secret']);
var spotify = SpotifyApi(credentials);
spotify.enableLogging(enable: true);
print('\nExpannd shortened spotify link of https://spotify.link/hRkBrwub9xb');
var longLink = await spotify.expandLink('https://spotify.link/hRkBrwub9xb');
print(longLink);
print('\nPodcast:');
await spotify.shows
.get('4rOoJ6Egrf8K2IrywzwOMk')
.then((podcast) => print(podcast.name))
.onError(
(error, stackTrace) => print((error as SpotifyException).message));
print('\nPodcast episode:');
var episodes = spotify.shows.episodes('4AlxqGkkrqe0mfIx3Mi7Xt');
await episodes.first().then((first) => print(first.items!.first)).onError(
(error, stackTrace) => print((error as SpotifyException).message));
print('\nArtists:');
var artists = await spotify.artists.list(['0OdUWJ0sBjDrqHygGUXeCF']);
for (var x in artists) {
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();
for (var track in tracks) {
print(track.name);
}
print('\nNew Releases');
var newReleases = await spotify.browse.getNewReleases().first();
for (var album in newReleases.items!) {
print(album.name);
}
print('\nFeatured Playlist:');
var featuredPlaylists = await spotify.playlists.featured.all();
for (var playlist in featuredPlaylists) {
print(playlist.name);
}
print('\nUser\'s playlists:');
var usersPlaylists =
await spotify.playlists.getUsersPlaylists('superinteressante').all();
for (var playlist in usersPlaylists) {
print(playlist.name);
}
print("\nSearching for 'Metallica':");
var search = await spotify.search.get('metallica').first(2);
for (var pages in search) {
if (pages.items == null) {
print('Empty items');
}
for (var item in pages.items!) {
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'
'popularity: ${item.popularity}\n'
'-------------------------------');
}
if (item is Track) {
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'
'popularity: ${item.popularity}\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'
'releaseDate: ${item.releaseDate}\n'
'releaseDatePrecision: ${item.releaseDatePrecision}\n'
'-------------------------------');
}
}
}
var relatedArtists =
await spotify.artists.relatedArtists('0OdUWJ0sBjDrqHygGUXeCF');
print('\nRelated Artists: ${relatedArtists.length}');
credentials = await spotify.getCredentials();
print('\nCredentials:');
print('Client Id: ${credentials.clientId}');
print('Access Token: ${credentials.accessToken}');
print('Credentials Expired: ${credentials.isExpired}');
}