ParseError -> manual input
This commit is contained in:
parent
1728effd97
commit
450421ce0d
1 changed files with 65 additions and 89 deletions
|
@ -83,9 +83,18 @@ def main() -> None:
|
|||
else:
|
||||
if correct != '':
|
||||
title = correct.lower()
|
||||
try:
|
||||
url = search_azurl(title)
|
||||
print(url)
|
||||
parsed = parse_azlyrics(url)
|
||||
except Exception as err:
|
||||
print(err)
|
||||
print(
|
||||
'In most cases, this error means '
|
||||
'the script have received some incorrect data, '
|
||||
'so you should enter song info manually.'
|
||||
)
|
||||
parsed = manual_info_input()
|
||||
|
||||
#print(parsed)
|
||||
tagmp3(file, parsed, copy)
|
||||
|
@ -187,18 +196,14 @@ def parse_azlyrics(link: str) -> ParseResult:
|
|||
|
||||
artist_elem = soup.select_one(f'{LYRICS_ROW}>.lyricsh>h2')
|
||||
if artist_elem is None:
|
||||
print('Unable to parse artist name')
|
||||
result['artist'] = input('Enter the artist name: ')
|
||||
else:
|
||||
raise ParseError('artist name')
|
||||
result['artist'] = artist_elem.get_text() \
|
||||
.removesuffix(' Lyrics') \
|
||||
.strip()
|
||||
|
||||
title_elem = soup.select_one(f'{LYRICS_ROW}>b')
|
||||
if title_elem is None:
|
||||
print('Unable to parse song title')
|
||||
result['title'] = input('Enter the title: ')
|
||||
else:
|
||||
raise ParseError('song title')
|
||||
result['title'] = title_elem.get_text().strip('" ')
|
||||
|
||||
album_blocks = soup.select('.songinalbum_title')
|
||||
|
@ -206,50 +211,21 @@ def parse_azlyrics(link: str) -> ParseResult:
|
|||
|
||||
if len(album_blocks) > 1:
|
||||
album = album_blocks[-2]
|
||||
|
||||
elif len(album_blocks) > 0:
|
||||
album = album_blocks[0]
|
||||
|
||||
if album is None:
|
||||
album_re = None
|
||||
else:
|
||||
raise ParseError('album name')
|
||||
|
||||
album_re = re.search(
|
||||
r'album:\s*"(.+?)"\s*\((\d+)\)',
|
||||
album.get_text()
|
||||
)
|
||||
|
||||
if album_re is None:
|
||||
print('Unable to parse album name')
|
||||
result['album'] = input('Enter the album name: ')
|
||||
result['year'] = input_num('Enter the release year: ')
|
||||
result['track_no'] = input_num('This is the track #')
|
||||
result['tracks'] = input_num('Number of tracks in the album: ')
|
||||
raise ParseError('album name')
|
||||
|
||||
cover = input('Insert an album cover? [Y/n] ')
|
||||
if cover.lower() not in ('n','н'):
|
||||
try:
|
||||
print(
|
||||
'Download the cover and enter its path:',
|
||||
'(relative path is not recommended)',
|
||||
sep='\n',
|
||||
)
|
||||
cover_file = Path(input().strip())
|
||||
|
||||
with cover_file.open('rb') as f:
|
||||
result['cover'] = f.read()
|
||||
|
||||
result['cover_mime'] = (
|
||||
mimetypes.guess_type(cover_file)[0]
|
||||
or 'image/jpeg'
|
||||
)
|
||||
except Exception as err:
|
||||
logging.exception(err)
|
||||
|
||||
else:
|
||||
result['album'] = album_re[1]
|
||||
result['year'] = int(album_re[2])
|
||||
|
||||
assert album is not None
|
||||
cover = album.select_one('img.album-image')
|
||||
|
||||
if cover is not None:
|
||||
|
|
Reference in a new issue