unrblt / beets-bandcamp

Plugin for beets (http://beets.io) to use bandcamp as an autotagger source.
GNU General Public License v2.0
63 stars 6 forks source link

AttributeError: 'NoneType' object has no attribute 'text' #14

Open kayila opened 4 years ago

kayila commented 4 years ago

This stacktrace happened while I was using beets to import a collection of mp3 files downloaded from bandcamp. Note that the specific package which these songs were from is no longer available on the bandcamp site. I was importing 'as tracks' instead of 'as album' and the songs themselves are still on the bandcamp.

I'm running using the archlinux install, which is using beets 1.4.9 and beets-bandcamp 0.1.4

It seems that it is successfully processing most of the songs, but dies when it gets to a specific track, even when resuming from an interrupted import.

Sending event: import_task_choice                                                                                                                                                                                  
Sending event: import_task_created                                                                                                                                                                                 
Sending event: import_task_start                                                                                                                                                                                   
Looking up: /home/kayila/Music.bak/Approaching Nirvana/Approaching Nirvana - Approaching Nirvana CD Package - 01 Sugar High.flac                                                                                   
Item search terms: Approaching Nirvana - Sugar High                                                                                                                                                                
Sending event: trackinfo_received
Sending event: trackinfo_received
Sending event: trackinfo_received
Sending event: trackinfo_received
Sending event: trackinfo_received
bandcamp: Searching track, page 1
Traceback (most recent call last):
  File "/usr/bin/beet", line 33, in <module>
    sys.exit(load_entry_point('beets==1.4.9', 'console_scripts', 'beet')())
  File "/usr/lib/python3.8/site-packages/beets/ui/__init__.py", line 1266, in main
    _raw_main(args)
  File "/usr/lib/python3.8/site-packages/beets/ui/__init__.py", line 1253, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python3.8/site-packages/beets/ui/commands.py", line 955, in import_func
    import_files(lib, paths, query)
  File "/usr/lib/python3.8/site-packages/beets/ui/commands.py", line 925, in import_files
    session.run()
  File "/usr/lib/python3.8/site-packages/beets/importer.py", line 329, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/usr/lib/python3.8/site-packages/beets/util/pipeline.py", line 445, in run_parallel
    six.reraise(exc_info[0], exc_info[1], exc_info[2])
  File "/usr/lib/python3.8/site-packages/six.py", line 703, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/beets/util/pipeline.py", line 315, in run
    for msg in _allmsgs(out):
  File "/usr/lib/python3.8/site-packages/beets/util/pipeline.py", line 466, in pull
    out = coro.send(msg)
  File "/usr/lib/python3.8/site-packages/beets/util/pipeline.py", line 194, in coro
    func(*(args + (task,)))
  File "/usr/lib/python3.8/site-packages/beets/importer.py", line 1351, in lookup_candidates
    task.lookup_candidates()
  File "/usr/lib/python3.8/site-packages/beets/importer.py", line 892, in lookup_candidates
    prop = autotag.tag_item(self.item, search_ids=self.search_ids)
  File "/usr/lib/python3.8/site-packages/beets/autotag/match.py", line 513, in tag_item
    for track_info in hooks.item_candidates(item, search_artist, search_title):
  File "/usr/lib/python3.8/site-packages/beets/plugins.py", line 574, in decorated
    for v in generator(*args, **kwargs):
  File "/usr/lib/python3.8/site-packages/beets/autotag/hooks.py", line 640, in item_candidates
    for candidate in plugins.item_candidates(item, artist, title):
  File "/usr/lib/python3.8/site-packages/beets/plugins.py", line 392, in item_candidates
    for item_candidate in plugin.item_candidates(item, artist, title):
  File "/usr/lib/python3.8/site-packages/beetsplug/bandcamp.py", line 96, in item_candidates
    return self.get_tracks(item.title)
  File "/usr/lib/python3.8/site-packages/beetsplug/bandcamp.py", line 166, in get_tracks
    return [self.get_track_info(url) for url in track_urls]
  File "/usr/lib/python3.8/site-packages/beetsplug/bandcamp.py", line 166, in <listcomp>
    return [self.get_track_info(url) for url in track_urls]
  File "/usr/lib/python3.8/site-packages/beetsplug/bandcamp.py", line 174, in get_track_info
    title = name_section.find(attrs={'itemprop': 'name'}).text.strip()
AttributeError: 'NoneType' object has no attribute 'text'

I edited this to add a bit more information. The output above is using the -vv flag.

kayila commented 4 years ago

When running in verbose mode, I also noticed these lines, which seem like they may be related...

bandcamp: Unexpected html while scraping album 'https://hardfloor.bandcamp.com/album/the-business-of-basslines-only-complete-album-2': 'NoneType' object has no attribute 'text'
bandcamp: Unexpected html while scraping album 'https://vivaladirtleague.bandcamp.com/album/viva-la-dirt-league-complete-album': 'NoneType' object has no attribute 'text'
bandcamp: Unexpected html while scraping album 'https://metalforcancer.bandcamp.com/album/the-next-dance-by-ofsoski-complete-album': 'NoneType' object has no attribute 'text'
bandcamp: Unexpected html while scraping album 'https://okazakiwork.bandcamp.com/album/work-complete-volumes-1-6': 'NoneType' object has no attribute 'text'
neilcar commented 4 years ago

The problem seems to be that some (all?) Bandcamp pages don't have the data that's being looked for. I added a bit of ersatz logging in get_track_info and I see this causing the same crash for me.

bandcamp: Getting url https://beesidecassettes.bandcamp.com/track/the-killing-moon
bandcamp: name_section <div id="name-section">
<h2 class="trackTitle">
            Bilge Rat - The Killing Moon

        </h2>
<h3 class="albumTitle">

            from <span>
<a href="/album/kind-of-funny-kind-of-strange-the-only-donnie-darko-companion-tape"><span class="fromAlbum">Kind of Funny, Kind of Strange: the ONLY Donnie Darko Companion Tape</span></a></span> by

            <span>
<a href="https://beesidecassettes.bandcamp.com">Bee Side Cassettes</a>
</span>
</h3>
</div>

(I'm searching for "The Killing Moon" by LYZA JANE.)

theozaurus commented 4 years ago

I'm also running into this for the track: https://newdadofficial.bandcamp.com/track/blue

snejus commented 3 years ago

I had this issue as well. Seeing that the current maintainer isn't very active and since bandcamp is the main place I get music from I got it fixed. I'm not expecting that a PR in this repo would see a response too soon, therefore feel free to use my fork at https://github.com/snejus/beets-bandcamp. Just clone the most recent master branch and install it manually.

Once there's a response from the maintainer, I'll open PR. Until then, let me know (either here or through an issue on my fork) if it breaks for you - that should get sorted in a couple of days max.

chrishoage commented 3 years ago

@snejus Your fork causes this error

bandcamp: Searching album, page 1 None: None
Sending event: albuminfo_received
Candidate: https://amarchitect.bandcamp.com - https://amarchitect.bandcamp.com/album/chroma-variants (A.M. Architect)
Traceback (most recent call last):
  File "/usr/bin/beet", line 11, in <module>
    load_entry_point('beets==1.5.0', 'console_scripts', 'beet')()
  File "/usr/lib/python3.8/site-packages/beets/ui/__init__.py", line 1278, in main
    _raw_main(args)
  File "/usr/lib/python3.8/site-packages/beets/ui/__init__.py", line 1265, in _raw_main
    subcommand.func(lib, suboptions, subargs)
  File "/usr/lib/python3.8/site-packages/beets/ui/commands.py", line 960, in import_func
    import_files(lib, paths, query)
  File "/usr/lib/python3.8/site-packages/beets/ui/commands.py", line 930, in import_files
    session.run()
  File "/usr/lib/python3.8/site-packages/beets/importer.py", line 341, in run
    pl.run_parallel(QUEUE_SIZE)
  File "/usr/lib/python3.8/site-packages/beets/util/pipeline.py", line 445, in run_parallel
    six.reraise(exc_info[0], exc_info[1], exc_info[2])
  File "/usr/lib/python3.8/site-packages/six.py", line 703, in reraise
    raise value
  File "/usr/lib/python3.8/site-packages/beets/util/pipeline.py", line 312, in run
    out = self.coro.send(msg)
  File "/usr/lib/python3.8/site-packages/beets/util/pipeline.py", line 194, in coro
    func(*(args + (task,)))
  File "/usr/lib/python3.8/site-packages/beets/importer.py", line 1365, in lookup_candidates
    task.lookup_candidates()
  File "/usr/lib/python3.8/site-packages/beets/importer.py", line 653, in lookup_candidates
    autotag.tag_album(self.items, search_ids=self.search_ids)
  File "/usr/lib/python3.8/site-packages/beets/autotag/match.py", line 468, in tag_album
    _add_candidate(items, candidates, matched_candidate)
  File "/usr/lib/python3.8/site-packages/beets/autotag/match.py", line 374, in _add_candidate
    mapping, extra_items, extra_tracks = assign_items(items, info.tracks)
  File "/usr/lib/python3.8/site-packages/beets/autotag/match.py", line 102, in assign_items
    row.append(track_distance(item, track))
  File "/usr/lib/python3.8/site-packages/beets/autotag/match.py", line 134, in track_distance
    if track_info.length:
AttributeError: 'str' object has no attribute 'length'
snejus commented 3 years ago

@chrishoage try the dev branch while I get through the last couple todos before merging all changes into master.

chrishoage commented 3 years ago

@snejus Using dev branch nets me this error. Using the linuxserver.io docker container

root@beets:/# pip3 install --no-cache-dir --upgrade https://github.com/snejus/beets-bandcamp/archive/dev.zip
Collecting https://github.com/snejus/beets-bandcamp/archive/dev.zip
  Downloading https://github.com/snejus/beets-bandcamp/archive/dev.zip
     \ 192 kB 689 kB/s
  Installing build dependencies ... error
  ERROR: Command errored out with exit status 1:
   command: /usr/bin/python3 /usr/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-lmfwpspo/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'poetry-core>=1.0.0'
       cwd: None
  Complete output (14 lines):
  Traceback (most recent call last):
    File "/usr/lib/python3.8/runpy.py", line 194, in _run_module_as_main
      return _run_code(code, main_globals, None,
    File "/usr/lib/python3.8/runpy.py", line 87, in _run_code
      exec(code, run_globals)
    File "/usr/lib/python3.8/site-packages/pip/__main__.py", line 23, in <module>
      from pip._internal.cli.main import main as _main  # isort:skip # noqa
    File "/usr/lib/python3.8/site-packages/pip/_internal/cli/main.py", line 5, in <module>
      import locale
    File "/usr/lib/python3.8/locale.py", line 16, in <module>
      import re
    File "/usr/lib/python3.8/re.py", line 145, in <module>
      class RegexFlag(enum.IntFlag):
  AttributeError: module 'enum' has no attribute 'IntFlag'
  ----------------------------------------
ERROR: Command errored out with exit status 1: /usr/bin/python3 /usr/lib/python3.8/site-packages/pip install --ignore-installed --no-user --prefix /tmp/pip-build-env-lmfwpspo/overlay --no-warn-script-location --no-binary :none: --only-binary :none: -i https://pypi.org/simple -- 'poetry-core>=1.0.0' Check the logs for full command output.

Using the master branch succeeds

root@beets:/# pip3 install --no-cache-dir --upgrade https://github.com/snejus/beets-bandcamp/archive/master.zip
Collecting https://github.com/snejus/beets-bandcamp/archive/master.zip
  Downloading https://github.com/snejus/beets-bandcamp/archive/master.zip
     | 18 kB 619 kB/s
Requirement already satisfied, skipping upgrade: beets>=1.4.6 in /usr/lib/python3.8/site-packages (from beets-bandcamp==0.1.5) (1.5.0)
Requirement already satisfied, skipping upgrade: six>=1.9requests in /usr/lib/python3.8/site-packages (from beets-bandcamp==0.1.5) (1.15.0)
Requirement already satisfied, skipping upgrade: beautifulsoup4 in /usr/lib/python3.8/site-packages (from beets-bandcamp==0.1.5) (4.9.1)
Requirement already satisfied, skipping upgrade: isodate in /usr/lib/python3.8/site-packages (from beets-bandcamp==0.1.5) (0.6.0)
Requirement already satisfied, skipping upgrade: unidecode in /usr/lib/python3.8/site-packages (from beets>=1.4.6->beets-bandcamp==0.1.5) (1.1.2)
Requirement already satisfied, skipping upgrade: musicbrainzngs>=0.4 in /usr/lib/python3.8/site-packages (from beets>=1.4.6->beets-bandcamp==0.1.5) (0.7.1)
Requirement already satisfied, skipping upgrade: pyyaml in /usr/lib/python3.8/site-packages (from beets>=1.4.6->beets-bandcamp==0.1.5) (5.3.1)
Requirement already satisfied, skipping upgrade: mediafile>=0.2.0 in /usr/lib/python3.8/site-packages (from beets>=1.4.6->beets-bandcamp==0.1.5) (0.6.0)
Requirement already satisfied, skipping upgrade: confuse>=1.0.0 in /usr/lib/python3.8/site-packages (from beets>=1.4.6->beets-bandcamp==0.1.5) (1.4.0)
Requirement already satisfied, skipping upgrade: munkres>=1.0.0 in /usr/lib/python3.8/site-packages (from beets>=1.4.6->beets-bandcamp==0.1.5) (1.1.2)
Requirement already satisfied, skipping upgrade: jellyfish in /usr/lib/python3.8/site-packages (from beets>=1.4.6->beets-bandcamp==0.1.5) (0.8.2)
Requirement already satisfied, skipping upgrade: soupsieve>1.2 in /usr/lib/python3.8/site-packages (from beautifulsoup4->beets-bandcamp==0.1.5) (2.0.1)
Requirement already satisfied, skipping upgrade: mutagen>=1.43 in /usr/lib/python3.8/site-packages (from mediafile>=0.2.0->beets>=1.4.6->beets-bandcamp==0.1.5) (1.45.1)
Using legacy setup.py install for beets-bandcamp, since package 'wheel' is not installed.
Installing collected packages: beets-bandcamp
    Running setup.py install for beets-bandcamp ... done
Successfully installed beets-bandcamp-0.1.5
snejus commented 3 years ago

@chrishoage it was in active dev at that point so no surprise that it did break.

A big update has been merged into master, so you may want to try again - it's also been tested with python 3.8 so it shouldn't pose any problems.

chrishoage commented 3 years ago

@snejus Sorry for the delay.

I have tried the latest tag, which appears to be the same hash as master and it is working. I tried with the original case I commented on and it no longer errors while searching.

To anyone reading this who may have a similar error to me with IntFlag causing problems in the linuxserver's beets container, you need to uninstall enum34 with pip3 uninstall -y enum34 as it causes an error.

Thanks for your work!