darthbatman / billboard-top-100

:chart_with_upwards_trend: Node.js API to retrieve the top songs, albums, and artists from Billboard's charts
MIT License
97 stars 30 forks source link

Pull highest resolution cover for images #32

Closed Komsomol closed 5 years ago

Komsomol commented 5 years ago

This code will cycle through the results to find and send the highest resolution image from the source set. For example, the images have an src set like this.

srcset="https://charts-static.billboard.com/img/2019/01/post-malone-tp6-53x53.jpg 53w, https://charts-static.billboard.com/img/2019/01/post-malone-tp6-106x106.jpg 106w, https://charts-static.billboard.com/img/2019/01/post-malone-tp6-87x87.jpg 87w, https://charts-static.billboard.com/img/2019/01/post-malone-tp6-174x174.jpg 174w"

The code will try to pull the 174x174 if it exists, then 87x87 and so on. If there is a fail the cover is returned '' "

This also fixes some covers not returning the Billboard Top 100 placeholder https://assets.billboard.com/assets/1556291827/images/charts/bb-placeholder-new.jpg