Browse Source

Fix False->None, add tests

master
Felix 4 years ago
parent
commit
93bdf3cff4
3 changed files with 54 additions and 5 deletions
  1. +1
    -1
      .gitignore
  2. +4
    -4
      tangoinfo.py
  3. +49
    -0
      tests.py

+ 1
- 1
.gitignore View File

@ -1,2 +1,2 @@
*.pyc
test.py
.cache

+ 4
- 4
tangoinfo.py View File

@ -243,20 +243,20 @@ class TangoInfoTagger:
re.split('<|>', trackinfo[3])[2].title(), 'utf8'
)
else:
genre = False
genre = None
# Get date
if trackinfo[6] and not trackinfo[6] == "-":
date = unicode(re.split('<|>', trackinfo[6])[2], 'utf8')
else:
date = False
date = None
# Get singers
if trackinfo[5] == "-" or not trackinfo[5]:
vocal = False
vocal = None
elif trackinfo[5]:
# Catch and strip <a> tags
vocal = unicode(re.sub("<[^>]*>", "", trackinfo[5]), 'utf8')
else:
vocal = False
vocal = None
# expected format in HTML: <a href="/002390...">...
tint = trackinfo[8].split("\"")[1][1:]


+ 49
- 0
tests.py View File

@ -0,0 +1,49 @@
#!/bin/env python2
# -*- coding: utf-8 -*-
# To run this:
# - Disable these two calls in tangoinfo.py:
# from picard.metadata import register_track_metadata_processor
# register_track_metadata_processor(TangoInfoTagger().add_tangoinfo_data)
# - Fix path:
# import sys
# sys.path.insert(0, '/usr/lib/picard')
# Messing around:
#
# class Metadata():
# @staticmethod
# def register_track_metadata_processor(dummy):
# return True
#
# import picard
# picard.metadata = Metadata()
import tangoinfo
try:
from urllib.request import urlopen # python3
except ImportError:
from urllib2 import urlopen # python2
# Test album:
# http://musicbrainz.org/release/65617e20-d445-41a3-a476-9868e6154317
# Barcode: 7798145106390
# tango.info: https://tango.info/07798145106390
# Metadata:
# 23 tracks, genre and performance date given but no vocalists
def test_barcode_process_metadata():
taggerclass = tangoinfo.TangoInfoTagger()
barcode = '7798145106390'
url = 'https://tango.info/07798145106390'
page = urlopen(url).read()
albuminfo = taggerclass.barcode_process_metadata(barcode, page)
assert albuminfo['07798145106390-1-19'].get('date') == u'1937-12-09'
assert len(albuminfo.keys()) == 23
#if __name__ == '__main__':
# test_barcode_process_metadata()

Loading…
Cancel
Save