projectgoav / E.Deezer

Unoffical asynchronous Deezer .NET API
16 stars 11 forks source link

Get playlist, artist, track and user by id #65

Closed filipkristo closed 5 years ago

filipkristo commented 5 years ago

I didn't see API methods for getting above resources by id. Is there any of that? If not I can implement that?

projectgoav commented 5 years ago

They should be there? Either that or I have implemented them locally and not pushed those changes...

filipkristo commented 5 years ago

I really can't find them. Can you please check, and if you have locally commit them? Thanks

Leiyiliro commented 5 years ago

From what I can see the API methods are there, it's the endpoint that is not exposing the API for them. I believe it has been removed in #47 . Would love to know why it was removed since I cannot find a good alternative for getting that information anymore.

projectgoav commented 5 years ago

That must have been a mistake! I'll take a look at this asap.

projectgoav commented 5 years ago

I've had a look at the code and the PR you had linked.

TL;DR This is going to be quite hard. It might take me a few weeks to find some time and a solution to this (See below for a little more detail).

If you require an implementation right away and manage one, then please feel free tto submit a PR! :)

Deezer Developers Website

The developer website I used to use (https://developers.deezer.com) no longer lets me sign in. My account doesn't get past the login screen and trying to register does nothing for me.

I tried my old laptop I originally developed this code on but that browser is no longer signed in.

Deezer have recently undergone quite a serious re-brand. The developer website is using their old branding so I'm wondering if it has been left to rot... The offical developer twitter and dev link on their website still redirect here so there's nothing really to suggest this is the case.

If you can find active/working documentation then please let me know!

Responses

I found some saved postman queries so had a little play around getting single items from the API. I've found the reponses for single items can come in a number of different forms

By far the most common is structed like that below. This mirrors what 99% of the API is like and how E.Deezer expects things to be returned.

{
  "data": 
    [
      ... 
    ],
    "error":
    {
      ...
  }

However, I've also found some items in the following formats:

{
  ...
}
{
   "error":
    {
      ...
    }
}
{
  ...
  "error_code": 800,
  "error_message": "some deezer error message"
}

When I originally wrote this library I knew very little C# so the code isn't the most flexible or well structured. I've done my best to fix bits as I touch them but it's still not the best quality. I think fair bits could and should be re-written (but that's another task).

I did find a local dev branch where it appears I've hit a similiar pattern with some user methods I was implementing. Having not done much custom parsing in .NET I came up with the following code:

 internal class PostResponseJsonConverter : JsonConverter
    {        public override bool CanRead => true;

        public override bool CanWrite => false;

        public override bool CanConvert(Type objectType) =>  objectType == typeof(PostResponse);

        public override object ReadJson(JsonReader reader, Type objectType, object existingValue, JsonSerializer serializer)
        {
            bool wasSuccess = false;
            IResponseError error = null;

            if (reader.TokenType == JsonToken.Boolean)
            {
                wasSuccess = (bool)reader.Value;
            }
            else
            {
                JObject value = JObject.Load(reader);
                JObject errorJObject = value.Value<JObject>("error");

                error = new ResponseError()
                {
                    Code = errorJObject.Value<int>("code"),
                    Type = errorJObject.Value<string>("type"),
                    Message = errorJObject.Value<string>("message"),
                };
            }

            return new PostResponse(wasSuccess, error);
        }

        public override void WriteJson(JsonWriter writer, object value, JsonSerializer serializer)
        {
            throw new NotImplementedException();
        }
    }

This would require a few modifications to support all types of items to parse. There would likely need to be some careful thinking in the already complex inheritance chain of API objects to make it generic enough for methods to throw correct exceptions or return the correct type of item but I think this could work.

Any thoughts?

filipkristo commented 5 years ago

I have implementation for get playlist, artist and track. Using everyday on my smarthouse deezer player and it's working great. I will make pull request, so we can talk about it after.

projectgoav commented 5 years ago

Please see #68 for initial support of getting items by id.

I'd like to write some more tests for this and get some tests going against the live API before I merge the code in. It'll be a wee while before this is merged and available in Nuget.

If you have some time and wish to try it out then feel free to try the branch byId. I'll also upload some binaries on the pull request for a simple drop-in replacement for testing. Please let me know if you find any bugs or issues and if possible the id of the item you were trying to fetch!