TheM4hd1 / SwiftyInsta

Instagram Private API Swift
MIT License
225 stars 51 forks source link

avatar arbitrarily picks the first available entry in hdProfilePicVersions #130

Closed mycroftcanner closed 4 years ago

mycroftcanner commented 4 years ago

avatar arbitrarily picks the first available entry in hdProfilePicVersions

    public var avatar: URL? {
        return rawResponse.hdProfilePicVersions
            .array?
            .first?
            .url
    }

The main issue is that it can be the lowest available quality :

image
mycroftcanner commented 4 years ago

This will select the profile picture url that has the highest quality:


    public var avatar: URL? {
        return rawResponse.hdProfilePicVersions
            .array?.sorted(
        by: {
            guard case .number(let lhs) = $0["width"], case .number(let rhs) = $1["width"] else { return false }
            return lhs.intValue > rhs.intValue
        }
        ).first?["url"].url
sbertix commented 4 years ago

It does, you're right 💪
I was under the impression avatars were sorted like generic Media by size, but apparently they're not.
Definitely fixing it in #96.