Skip to content

Commit

Permalink
Updated tests and Metadata
Browse files Browse the repository at this point in the history
New tests for metadata identification were created and the downloader one was updated for avoiding import errors
  • Loading branch information
Javinator9889 committed Jun 1, 2020
1 parent b96346c commit c298afa
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 5 deletions.
15 changes: 14 additions & 1 deletion YouTubeMDBot/metadata/MetadataIdentifier.py
Expand Up @@ -114,14 +114,27 @@ def identify_audio(self) -> bool:
self.release_id = \
recording["releasegroups"][0]["releases"][0]["id"]
self.album = recording["releasegroups"][0]["title"]
self.cover = musicbrainzngs.get_image_front(self.release_id)
self.cover = musicbrainzngs.get_image_front(
self.release_id)
self.recording_id = recording["id"]
self.duration = recording["duration"]
is_valid = True
break
break
return is_valid

def __str__(self):
return f"Title: {self.title}\n" \
f"Artist: {self.artist}\n" \
f"Release ID: {self.release_id}\n" \
f"Recording ID: {self.recording_id}\n" \
f"Score: {self.score}\n" \
f"Cover [length]: {len(self.cover)}\n" \
f"Album: {self.album}\n" \
f"Duration: {self.duration}\n" \
f"Is YT data?: {self.youtube_data}\n" \
f"YT ID: {self.youtube_id}"


class YouTubeMetadataIdentifier(MetadataIdentifier):
"""
Expand Down
10 changes: 6 additions & 4 deletions YouTubeMDBot/tests/download_test.py
@@ -1,13 +1,15 @@
import unittest
import logging

from time import sleep
from threading import Lock

from YouTubeMDBot.downloader import YouTubeDownloader
from YouTubeMDBot.downloader import M4AYouTubeDownloader
from YouTubeMDBot.downloader import MultipleYouTubeDownloader

log = logging.basicConfig()
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)


class DownloadTest(unittest.TestCase):
Expand Down Expand Up @@ -59,12 +61,12 @@ def _test_download(self, downloader: YouTubeDownloader):
self.assertEqual(io.read(), data)

def _download_finished_callback(self, data):
log.info("Video download finished")
log.debug(type(data))
logging.info("Video download finished")
logging.debug(type(data))
self.finished += 1

def _download_failed_callback(self, err):
log.error(f"Captured error: {err}")
logging.error(f"Captured error: {err}")


if __name__ == '__main__':
Expand Down
44 changes: 44 additions & 0 deletions YouTubeMDBot/tests/identification_test.py
@@ -0,0 +1,44 @@
# YouTubeMDBot
# Copyright (C) 2020 - Javinator9889
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import unittest
import logging

from YouTubeMDBot.downloader import YouTubeDownloader
from YouTubeMDBot.metadata import YouTubeMetadataIdentifier


logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
level=logging.INFO)


class IdentificationTest(unittest.TestCase):
def test_knwon_identification(self):
downloader = YouTubeDownloader(
url="https://www.youtube.com/watch?v=YQHsXMglC9A"
)
_, data = downloader.download()
identifier = YouTubeMetadataIdentifier(data)
identifier.identify_audio()
logging.info(identifier)

def test_unknown_identification(self):
downloader = YouTubeDownloader(
url="https://www.youtube.com/watch?v=BL4dnvBytLA"
)
_, data = downloader.download()
identifier = YouTubeMetadataIdentifier(data, downloader)
identifier.identify_audio()
logging.info(identifier)

0 comments on commit c298afa

Please sign in to comment.