mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
New: Top albums and period interval options for Last.fm User lists
This commit is contained in:
parent
803c2dd66b
commit
95043a2768
4 changed files with 98 additions and 9 deletions
|
@ -10,6 +10,7 @@ namespace NzbDrone.Core.ImportLists.LastFm
|
||||||
public class LastFmArtistResponse
|
public class LastFmArtistResponse
|
||||||
{
|
{
|
||||||
public LastFmArtistList TopArtists { get; set; }
|
public LastFmArtistList TopArtists { get; set; }
|
||||||
|
public LastFmAlbumList TopAlbums { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
public class LastFmArtist
|
public class LastFmArtist
|
||||||
|
@ -17,4 +18,16 @@ namespace NzbDrone.Core.ImportLists.LastFm
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
public string Mbid { get; set; }
|
public string Mbid { get; set; }
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class LastFmAlbumList
|
||||||
|
{
|
||||||
|
public List<LastFmAlbum> Album { get; set; }
|
||||||
|
}
|
||||||
|
|
||||||
|
public class LastFmAlbum
|
||||||
|
{
|
||||||
|
public LastFmArtist Artist { get; set; }
|
||||||
|
public string Name { get; set; }
|
||||||
|
public string Mbid { get; set; }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -29,6 +29,23 @@ namespace NzbDrone.Core.ImportLists.LastFm
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (jsonResponse.TopArtists == null)
|
||||||
|
{
|
||||||
|
foreach (var item in jsonResponse.TopAlbums.Album)
|
||||||
|
{
|
||||||
|
// Last.fm does provide an album MusicBrainzId, but it's
|
||||||
|
// for a specific release rather than a group like
|
||||||
|
// Lidarr wants. Matching on the name works well enough.
|
||||||
|
items.AddIfNotNull(new ImportListItemInfo
|
||||||
|
{
|
||||||
|
Artist = item.Artist.Name,
|
||||||
|
ArtistMusicBrainzId = item.Artist.Mbid,
|
||||||
|
Album = item.Name
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
foreach (var item in jsonResponse.TopArtists.Artist)
|
foreach (var item in jsonResponse.TopArtists.Artist)
|
||||||
{
|
{
|
||||||
items.AddIfNotNull(new ImportListItemInfo
|
items.AddIfNotNull(new ImportListItemInfo
|
||||||
|
@ -37,6 +54,7 @@ namespace NzbDrone.Core.ImportLists.LastFm
|
||||||
ArtistMusicBrainzId = item.Mbid
|
ArtistMusicBrainzId = item.Mbid
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return items;
|
return items;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,33 @@ namespace NzbDrone.Core.ImportLists.LastFm
|
||||||
|
|
||||||
private IEnumerable<ImportListRequest> GetPagedRequests()
|
private IEnumerable<ImportListRequest> GetPagedRequests()
|
||||||
{
|
{
|
||||||
yield return new ImportListRequest(string.Format("{0}&user={1}&limit={2}&api_key={3}&format=json", Settings.BaseUrl.TrimEnd('/'), Settings.UserId, Settings.Count, Settings.ApiKey), HttpAccept.Json);
|
var method = Settings.Method switch
|
||||||
|
{
|
||||||
|
(int)LastFmUserMethodList.TopAlbums => "user.gettopalbums",
|
||||||
|
_ => "user.gettopartists"
|
||||||
|
};
|
||||||
|
|
||||||
|
var period = Settings.Period switch
|
||||||
|
{
|
||||||
|
(int)LastFmUserTimePeriod.LastWeek => "7day",
|
||||||
|
(int)LastFmUserTimePeriod.LastMonth => "1month",
|
||||||
|
(int)LastFmUserTimePeriod.LastThreeMonths => "3month",
|
||||||
|
(int)LastFmUserTimePeriod.LastSixMonths => "6month",
|
||||||
|
(int)LastFmUserTimePeriod.LastTwelveMonths => "12month",
|
||||||
|
_ => "overall"
|
||||||
|
};
|
||||||
|
|
||||||
|
var request = new HttpRequestBuilder(Settings.BaseUrl)
|
||||||
|
.AddQueryParam("api_key", Settings.ApiKey)
|
||||||
|
.AddQueryParam("method", method)
|
||||||
|
.AddQueryParam("user", Settings.UserId)
|
||||||
|
.AddQueryParam("period", period)
|
||||||
|
.AddQueryParam("limit", Settings.Count)
|
||||||
|
.AddQueryParam("format", "json")
|
||||||
|
.Accept(HttpAccept.Json)
|
||||||
|
.Build();
|
||||||
|
|
||||||
|
yield return new ImportListRequest(request);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -15,12 +15,14 @@ namespace NzbDrone.Core.ImportLists.LastFm
|
||||||
|
|
||||||
public class LastFmUserSettings : IImportListSettings
|
public class LastFmUserSettings : IImportListSettings
|
||||||
{
|
{
|
||||||
private static readonly LastFmSettingsValidator Validator = new LastFmSettingsValidator();
|
private static readonly LastFmSettingsValidator Validator = new ();
|
||||||
|
|
||||||
public LastFmUserSettings()
|
public LastFmUserSettings()
|
||||||
{
|
{
|
||||||
BaseUrl = "https://ws.audioscrobbler.com/2.0/?method=user.gettopartists";
|
BaseUrl = "https://ws.audioscrobbler.com/2.0/";
|
||||||
ApiKey = "204c76646d6020eee36bbc51a2fcd810";
|
ApiKey = "204c76646d6020eee36bbc51a2fcd810";
|
||||||
|
Method = (int)LastFmUserMethodList.TopArtists;
|
||||||
|
Period = (int)LastFmUserTimePeriod.Overall;
|
||||||
Count = 25;
|
Count = 25;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -30,7 +32,13 @@ namespace NzbDrone.Core.ImportLists.LastFm
|
||||||
[FieldDefinition(0, Label = "Last.fm UserID", HelpText = "Last.fm UserId to pull artists from")]
|
[FieldDefinition(0, Label = "Last.fm UserID", HelpText = "Last.fm UserId to pull artists from")]
|
||||||
public string UserId { get; set; }
|
public string UserId { get; set; }
|
||||||
|
|
||||||
[FieldDefinition(1, Label = "Count", HelpText = "Number of results to pull from list (Max 1000)", Type = FieldType.Number)]
|
[FieldDefinition(1, Label = "List", Type = FieldType.Select, SelectOptions = typeof(LastFmUserMethodList))]
|
||||||
|
public int Method { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(2, Label = "Period", Type = FieldType.Select, SelectOptions = typeof(LastFmUserTimePeriod), HelpText = "The time period over which to retrieve top artists for")]
|
||||||
|
public int Period { get; set; }
|
||||||
|
|
||||||
|
[FieldDefinition(3, Label = "Count", HelpText = "Number of results to pull from list (Max 1000)", Type = FieldType.Number)]
|
||||||
public int Count { get; set; }
|
public int Count { get; set; }
|
||||||
|
|
||||||
public NzbDroneValidationResult Validate()
|
public NzbDroneValidationResult Validate()
|
||||||
|
@ -38,4 +46,28 @@ namespace NzbDrone.Core.ImportLists.LastFm
|
||||||
return new NzbDroneValidationResult(Validator.Validate(this));
|
return new NzbDroneValidationResult(Validator.Validate(this));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public enum LastFmUserMethodList
|
||||||
|
{
|
||||||
|
[FieldOption(Label = "Top Artists")]
|
||||||
|
TopArtists = 0,
|
||||||
|
[FieldOption(Label = "Top Albums")]
|
||||||
|
TopAlbums = 1
|
||||||
|
}
|
||||||
|
|
||||||
|
public enum LastFmUserTimePeriod
|
||||||
|
{
|
||||||
|
[FieldOption(Label = "Overall")]
|
||||||
|
Overall = 0,
|
||||||
|
[FieldOption(Label = "Last Week")]
|
||||||
|
LastWeek = 1,
|
||||||
|
[FieldOption(Label = "Last Month")]
|
||||||
|
LastMonth = 2,
|
||||||
|
[FieldOption(Label = "Last 3 Months")]
|
||||||
|
LastThreeMonths = 3,
|
||||||
|
[FieldOption(Label = "Last 6 Months")]
|
||||||
|
LastSixMonths = 4,
|
||||||
|
[FieldOption(Label = "Last 12 Months")]
|
||||||
|
LastTwelveMonths = 5
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue