Add logging capability (#175)

* Refactoring and addition of logzero (#172)

* Refactored convert.py and added logging.

* Added logging and refactored.

* Added logzero to requirements.txt

* Added logging to metadata.py

* Created a log in misc.py. Updated slugify import.

* Some general improvement

* Improve message layout

* Improve test mechanism

* Implement debug level logging

* Fix some minor mistakes

* Make pytest happy

* Remove unimplemented --verbose option

* Update ISSUE_TEMPLATE.md

* Rename LICENSE

* Remove obvious from log.debug()

* Show track URL when writing to file (debug)
This commit is contained in:
Ritiek Malhotra
2017-12-15 19:57:57 +05:30
committed by GitHub
parent 8ea89f9d1c
commit df513acc35
12 changed files with 319 additions and 216 deletions

View File

@@ -1,6 +1,7 @@
from mutagen.easyid3 import EasyID3
from mutagen.id3 import ID3, APIC
from mutagen.mp4 import MP4, MP4Cover
from core.logger import log
import urllib.request
@@ -24,23 +25,23 @@ def compare(music_file, metadata):
def embed(music_file, meta_tags):
"""Embed metadata."""
""" Embed metadata. """
if meta_tags is None:
print('Could not find meta-tags')
log.warning('Could not find metadata')
return None
elif music_file.endswith('.m4a'):
print('Fixing meta-tags')
log.info('Applying metadata')
return embed_m4a(music_file, meta_tags)
elif music_file.endswith('.mp3'):
print('Fixing meta-tags')
log.info('Applying metadata')
return embed_mp3(music_file, meta_tags)
else:
print('Cannot embed meta-tags into given output extension')
log.warning('Cannot embed metadata into given output extension')
return False
def embed_mp3(music_file, meta_tags):
"""Embed metadata to MP3 files."""
""" Embed metadata to MP3 files. """
# EasyID3 is fun to use ;)
audiofile = EasyID3(music_file)
audiofile['artist'] = meta_tags['artists'][0]['name']
@@ -81,7 +82,7 @@ def embed_mp3(music_file, meta_tags):
def embed_m4a(music_file, meta_tags):
"""Embed metadata to M4A files."""
""" Embed metadata to M4A files. """
# Apple has specific tags - see mutagen docs -
# http://mutagen.readthedocs.io/en/latest/api/mp4.html
tags = {'album': '\xa9alb',