Skip to content

Commit

Permalink
Fix TrackMethods.
Browse files Browse the repository at this point in the history
- Fixed TrackMethods.getTags()
- Added new track example.
  • Loading branch information
Nebulino committed Apr 16, 2020
1 parent 834f8e8 commit fdf8e2e
Show file tree
Hide file tree
Showing 2 changed files with 126 additions and 1 deletion.
124 changes: 124 additions & 0 deletions example/applied_methods_example/track_methods_example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
/**
* Scrobblenaut - A deadly simple Last.FM API Wrapper for Dart.
* Copyright (c) 2020 Nebulino
*/

import 'package:scrobblenaut/lastfm.dart';
import 'package:scrobblenaut/scrobblenaut.dart';
import 'package:scrobblenaut/scrobblenaut_helpers.dart';

import '../api_values.dart';

// Just an example of use.
void main() async {
print('####################################################################');

final lastFMAuth = await LastFM.authenticate(
apiKey: APIValues.API,
apiSecret: APIValues.secret,
username: APIValues.username,
password: APIValues.password,
sessionKey: APIValues.sessionKey,
);

final scrobblenaut = Scrobblenaut(lastFM: lastFMAuth);

final trackInstance = (await scrobblenaut.track.getInfo(
track: 'Tomoyo',
artist: 'Zekk',
autoCorrect: true,
));

print('##########################track.addTags#############################');

// track.addTags
print('Result of addTag request: ' +
(await trackInstance.addTags(tags: ['anime'])).toString());

print('######################track.getCorrection###########################');

// track.getCorrection
(await trackInstance.getCorrection())?.forEach((Track track) {
print('Track Correction Name: ${track.name} |'
' Track Correction URL: ${track.url}');
});

print('#########################track.getInfo##############################');

// track.getInfo
final trackGetInfo = (await trackInstance.getInfo(
username: 'nebulino',
autoCorrect: true,
));

print('Track Info Name: ${trackGetInfo.name} '
'| Track URL: ${trackGetInfo.url} '
'| Track Duration: ${trackGetInfo.duration}');

print('#########################track.getSimilar###########################');

// track.getSimilar
(await trackInstance.getSimilar())?.forEach((Track track) {
print('Similar Track Name: ${track.name}');
});

print('###########################track.getTags############################');

// track.getTags
(await trackInstance.getTags(user: 'nebulino'))?.forEach((Tag tag) {
print('Tag name: ${tag.name} | Tag url: ${tag.url}');
});

print('#########################track.getTopTags###########################');

// track.getTopTags
(await trackInstance.getTopTags())?.forEach((Tag tag) {
print('Tag name: ${tag.name} | Tag url: ${tag.url}');
});

print('#############################track.love#############################');

// track.love
print('Result of love request: ' + (await trackInstance.love()).toString());

print('########################track.removeTag#############################');

// track.removeTag
print('Result of removeTag request: ' +
(await trackInstance.removeTag(tag: 'anime')).toString());

print('#########################track.scrobble#############################');

// track.scrobble
final scrobbleResponse =
await trackInstance.scrobble(timestamp: DateTime.now());
// YAY. IT WORKS!

scrobbleResponse.scrobbleResponses?.forEach((ScrobbledTrack scrobbledTrack) {
print('Scrobbled Title: ${scrobbledTrack.track}');
});

print('###########################track.search#############################');

// track.search
(await trackInstance.search()).tracks?.forEach((Track track) {
print('Track Name from search: ${track.name}');
});

print('##########################track.unlove##############################');

// track.unlove
print(
'Result of unlove request: ' + (await trackInstance.unLove()).toString());

print('#####################track.updateNowPlaying#########################');

// track.updateNowPlaying
final nowPlayingResponse = await trackInstance.updateNowPlaying();
// YAY. IT WORKS!

print('Result of updateNowPlaying request: ${nowPlayingResponse.status} | '
'${nowPlayingResponse.track}');

print('####################################################################');
}
3 changes: 2 additions & 1 deletion lib/src/methods/track_methods.dart
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,8 @@ class TrackMethods {

return tags['tag'] == null
? null
: List.generate((tags as List).length, (i) => Tag.fromJson(tags[i]));
: List.generate(
(tags['tag'] as List).length, (i) => Tag.fromJson(tags['tag'][i]));
}

/// Get the top tags for this track on Last.fm, ordered by tag count.
Expand Down

0 comments on commit fdf8e2e

Please sign in to comment.