From c298afa2cd79c1b749c516dab17bec090314a646 Mon Sep 17 00:00:00 2001 From: Javinator9889 Date: Mon, 1 Jun 2020 10:41:57 +0200 Subject: [PATCH] Updated tests and Metadata New tests for metadata identification were created and the downloader one was updated for avoiding import errors --- YouTubeMDBot/metadata/MetadataIdentifier.py | 15 ++++++- YouTubeMDBot/tests/download_test.py | 10 +++-- YouTubeMDBot/tests/identification_test.py | 44 +++++++++++++++++++++ 3 files changed, 64 insertions(+), 5 deletions(-) create mode 100644 YouTubeMDBot/tests/identification_test.py diff --git a/YouTubeMDBot/metadata/MetadataIdentifier.py b/YouTubeMDBot/metadata/MetadataIdentifier.py index 7786350..bbe93e7 100755 --- a/YouTubeMDBot/metadata/MetadataIdentifier.py +++ b/YouTubeMDBot/metadata/MetadataIdentifier.py @@ -114,7 +114,8 @@ 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 @@ -122,6 +123,18 @@ def identify_audio(self) -> bool: 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): """ diff --git a/YouTubeMDBot/tests/download_test.py b/YouTubeMDBot/tests/download_test.py index 9391c82..29ee750 100644 --- a/YouTubeMDBot/tests/download_test.py +++ b/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): @@ -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__': diff --git a/YouTubeMDBot/tests/identification_test.py b/YouTubeMDBot/tests/identification_test.py new file mode 100644 index 0000000..cd7edf2 --- /dev/null +++ b/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 . +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)