Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix artist.get_bio_content() to return None if bio is empty #326

Merged
merged 3 commits into from May 10, 2020

Conversation

hugovk
Copy link
Member

@hugovk hugovk commented Apr 16, 2020

Fixes #325.

Changes proposed in this pull request:

  • artist.get_bio_content() causes an exception for an artist with no biography, because it tries to get data from an empty <content/>
  • Instead, if it is None, return None
  • Will also fix for other artist.get_bio_X() functions, and other things that call _extract_cdata_from_request

This happens because there's no biography for this artist.

The XML from the API has an empty <content/>:

<lfm status="ok">
<artist>
<name>Mr Sizef Unquote</name>
<url>https://www.last.fm/music/Mr+Sizef+++Unquote</url>
<image size="small"/>
<image size="medium"/>
<image size="large"/>
<image size="extralarge"/>
<image size="mega"/>
<image size=""/>
<streamable>0</streamable>
<ontour>0</ontour>
<stats>
<listeners>6</listeners>
<playcount>8</playcount>
</stats>
<similar/>
<tags/>
<bio>
<links>
<link rel="original" href="https://last.fm/music/Mr+Sizef+++Unquote/+wiki"/>
</links>
<published>01 Jan 1970, 00:00</published>
<summary>
<a href="https://www.last.fm/music/Mr+Sizef+++Unquote">Read more on Last.fm</a>
</summary>
<content/>
</bio>
</artist>
</lfm>

https://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Mr%20Sizef%20+%20Unquote&api_key=YOUR_API_KEY

Compare with Cher:

<lfm status="ok">
<artist>
<name>Cher</name>
<mbid>bfcc6d75-a6a5-4bc6-8282-47aec8531818</mbid>
<url>https://www.last.fm/music/Cher</url>
<image size="small">
https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="medium">
https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="large">
https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="extralarge">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="mega">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<streamable>0</streamable>
<ontour>0</ontour>
<stats>
<listeners>1171339</listeners>
<playcount>17392745</playcount>
</stats>
<similar>
<artist>
<name>Sonny & Cher</name>
<url>https://www.last.fm/music/Sonny+&+Cher</url>
<image size="small">
https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="medium">
https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="large">
https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="extralarge">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="mega">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
</artist>
<artist>
<name>Kylie Minogue</name>
<url>https://www.last.fm/music/Kylie+Minogue</url>
<image size="small">
https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="medium">
https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="large">
https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="extralarge">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="mega">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
</artist>
<artist>
<name>Madonna</name>
<url>https://www.last.fm/music/Madonna</url>
<image size="small">
https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="medium">
https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="large">
https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="extralarge">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="mega">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
</artist>
<artist>
<name>Céline Dion</name>
<url>https://www.last.fm/music/C%C3%A9line+Dion</url>
<image size="small">
https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="medium">
https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="large">
https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="extralarge">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="mega">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
</artist>
<artist>
<name>Barbra Streisand</name>
<url>https://www.last.fm/music/Barbra+Streisand</url>
<image size="small">
https://lastfm.freetls.fastly.net/i/u/34s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="medium">
https://lastfm.freetls.fastly.net/i/u/64s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="large">
https://lastfm.freetls.fastly.net/i/u/174s/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="extralarge">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="mega">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
<image size="">
https://lastfm.freetls.fastly.net/i/u/300x300/2a96cbd8b46e442fc41c2b86b821562f.png
</image>
</artist>
</similar>
<tags>
<tag>
<name>pop</name>
<url>https://www.last.fm/tag/pop</url>
</tag>
<tag>
<name>female vocalists</name>
<url>https://www.last.fm/tag/female+vocalists</url>
</tag>
<tag>
<name>80s</name>
<url>https://www.last.fm/tag/80s</url>
</tag>
<tag>
<name>dance</name>
<url>https://www.last.fm/tag/dance</url>
</tag>
<tag>
<name>rock</name>
<url>https://www.last.fm/tag/rock</url>
</tag>
</tags>
<bio>
<links>
<link rel="original" href="https://last.fm/music/Cher/+wiki"/>
</links>
<published>17 Feb 2006, 22:09</published>
<summary>
Cher (born Cherilyn Sarkisian; May 20, 1946) is an Oscar- and Grammy-winning American singer and actress. A major figure for over five decades in the world of popular culture, she is often referred to as the Goddess of Pop for having first brought the sense of female autonomy and self-actualization into the entertainment industry. She is known for her distinctive contralto and for having worked extensively across media, as well as for continuously reinventing both her music and image, the latter of which has been known to induce controversy. <a href="https://www.last.fm/music/Cher">Read more on Last.fm</a>
</summary>
<content>
Cher (born Cherilyn Sarkisian; May 20, 1946) is an Oscar- and Grammy-winning American singer and actress. A major figure for over five decades in the world of popular culture, she is often referred to as the Goddess of Pop for having first brought the sense of female autonomy and self-actualization into the entertainment industry. She is known for her distinctive contralto and for having worked extensively across media, as well as for continuously reinventing both her music and image, the latter of which has been known to induce controversy. Cher was born Cherilyn Sarkisian in El Centro, California, on May 20, 1946. She is of Armenian-American, Irish, English, German, and Cherokee ancestry. Cher first caught the eye and ear of the public in 1965 as one-half of the pop rock duo Sonny & Cher, which popularized a peculiar smooth sound that competed successfully with the predominant British Invasion and Motown Sound of the era. After a period in which the duo became obsolete, she re-emerged in the 1970's as a television personality with her shows The Sonny & Cher Comedy Hour and Cher, which attained great popularity. At the same time, she established herself as a solo artist with hits such as "Bang Bang (My Baby Shot Me Down)", "Gypsys, Tramps & Thieves", "Half-Breed", and "Dark Lady", which dealt with taboo subjects in mainstream popular music. Throughout, she cemented her status as a fashion trendsetter with her daring outfits, and was noted as being the first woman to expose her navel on television. Cher's impact at that time, as described by Phill Marder from Goldmine magazine, "led the way to advance feminine rebellion in the rock world," as she was "the prototype of the female rock star, setting the standard for appearance and [...] attitude[.]" In 1983 Cher made a critically acclaimed appearance on Broadway and starred in the film Silkwood, which earned her a nomination for the Academy Award for Best Supporting Actress. In the following years, she became an acclaimed film actress by starring in a string of hit films, including Mask, The Witches of Eastwick, and Moonstruck, for which she won the Academy Award for Best Actress in 1988. At the same time, she established herself as a "serious rock and roller" by releasing a series of rock albums and hit singles such as "I Found Someone", "If I Could Turn Back Time", and "The Shoop Shoop Song (It's in His Kiss)". She made her directing debut with the film If These Walls Could Talk in 1996 and released the biggest-selling single of her career thus far, "Believe", which revolutionized the recording industry because of its pioneer use of Auto-Tune (also known as the "Cher effect"). Throughout the 2000's she embarked on a series of concert tours that were among the highest-grossing of all-time. Cher has won an Academy Award, a Grammy Award, an Emmy Award, three Golden Globe Awards, and the Best Actress Award at the Cannes Film Festival for her work in film, music and television. She is the only person to receive all of these awards. She is also the only artist to have notched a number-one single on a Billboard chart in each of the past six decades. Recognized as one of the best-selling music artists of all time, she has sold more than 100 million solo albums worldwide and 40 million records as part of Sonny & Cher. Official website: http://www.cher.com/ <a href="https://www.last.fm/music/Cher">Read more on Last.fm</a>. User-contributed text is available under the Creative Commons By-SA License; additional terms may apply.
</content>
</bio>
</artist>
</lfm>

https://ws.audioscrobbler.com/2.0/?method=artist.getinfo&artist=Cher&api_key=YOUR_API_KEY

@hugovk hugovk added bug Something isn't working changelog: Fixed For any bug fixes labels Apr 16, 2020
@codecov
Copy link

codecov bot commented Apr 16, 2020

Codecov Report

Merging #326 into master will increase coverage by 0.48%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##           master     #326      +/-   ##
==========================================
+ Coverage   94.43%   94.92%   +0.48%     
==========================================
  Files           1        1              
  Lines        1258     1261       +3     
==========================================
+ Hits         1188     1197       +9     
+ Misses         70       64       -6     
Impacted Files Coverage Δ
src/pylast/__init__.py 94.92% <100.00%> (+0.48%) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 2aaa594...925cae2. Read the comment docs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working changelog: Fixed For any bug fixes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

get_bio_content() throws an unexpected exception on edge case artists
1 participant