tterb / yt2mp3

:arrow_down: Search, Download, and Convert YouTube videos to MP3

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

AttributeError: 'NoneType' object has no attribute 'get_text'

darrensapalo opened this issue · comments

Describe the bug
I was downloading a public playlist from youtube, but it crashed.

I think that it is because I have already downloaded one of the songs (Song number 2) from the said playlist, and then I tried to download the playlist. It crashed on song number 2.

I tried deleting the folders when the songs have downloaded. With an empty result folder, it still caused crashes.

The title of the next song is: L'indécis - Soulful, found here.

To Reproduce
Steps to reproduce the behavior:

  1. Open Terminal.
  2. Type in yt2mp3 -u https://www.youtube.com/watch?v=GgVcgbtHY9k to download song number 2 of the palylist.
  3. Type in yt2mp3 -p https://www.youtube.com/playlist?list=PLZ_03ix9erkpOw9tfAOr9jX2fo6UvCbPp to download the playlist.
  4. See error

Expected behavior
The error crashes with the following error message:

Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/3.6/bin/yt2mp3", line 80, in <module>
    main()
  File "/Library/Frameworks/Python.framework/Versions/3.6/bin/yt2mp3", line 33, in main
    yt2mp3.downloadPlaylist(queue, args.verbose, args.overwrite)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yt2mp3/__init__.py", line 112, in downloadPlaylist
    title = getVideoTitle(url)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/yt2mp3/__init__.py", line 61, in getVideoTitle
    return soup.find('span', {'class':'watch-title'}).get_text().strip()
AttributeError: 'NoneType' object has no attribute 'get_text'

Screenshots
screen shot 2018-08-15 at 3 51 41 pm

Specifications:

  • OS: Mac OSX 10.13.6
  • Python version: Python 2.7.10 or Python 3.6.5
  • Version: yt2mp3 1.0.5

Additional context
None.

Thanks for providing an in-depth overview of the issue! I'll look into this today and see if I'm able to reproduce this error and find the potential cause.

I was able to reproduce the issue and it definitely looks like the issue is occurring when attempting to retrieve the title for the L'indécis - Soulful video.
I assume that this is due to the title containing accented characters that aren't being properly accounting for. Fortunately, the program has been modified to use an more efficient method of retrieving video titles since the last release, which doesn't appear to suffer this issue.

I expect to finish testing and publish the updated release within the next few days. So I'll leave this issue open until then, in case anyone else encounters a similar issue.

Version v1.2.0 has been published to PyPi, but let me know if you run into any issues with the release.

I'm having problems with titles like the following:

  1. *Sonder* - Departure - url
  2. Mariya Takeuchi 竹内 まりや Plastic Love - url

Most likely because it has asterisks and unexpected characters. I forked the repository and took a peek. If I were to attempt to fix this, how might you suggest I do it correctly or properly?

Error description - video title does is not resolved correctly.

The problem is that getVideoData assigns a value of None to result for both cases, which causes the program to ask for a track name and artist.

# Uses the provided data to find a match in iTunes API
def getSongData(data):
  if data['video_url']:
    url = data['video_url']
    result = getVideoData(getVideoTitle(url))
    if not result: 
      data['track_name'] = input(' Track: ')
      data['artist_name'] = input(' Artist: ')

The implementation to fetch the youtube title is done using the following:

# Get YouTube video title
def getVideoTitle(url):
  return pytube.YouTube(url).title

Does this mean that if I wanted to fix the title fetching issue, I need to fork pytube instead and then make a pull-request there?

I believe both of these songs were included in the playlist that I used to reproduce the previous issue and they were both able to download as expected with the changes to the getVideoTitle() function, so I want to make sure that the issue you're currently experiencing is not the expected behavior.

The role of the getVideoData() function is to retrieve keywords from the video title by removing punctuation and nondescript phrases in order to try to find a match within the iTunes Store API, if one exists. So when getVideoData() returns a value of None, it either means that the song isn't in the iTunes Store or the program isn't finding the match due to potential shortcomings in the way that getVideoData() function is processing the video titles.
At which time, the program prompts the user to provide the song title/artist and uses the video thumbnail as the album art.

So if these songs are in the iTunes Store and the getVideoData() isn't finding them, a solution would be submitting a pull request with improvements to how getVideoData() retrieves keywords from the video title so that it's able to find a match.