Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Possible metadata method - need to be tested with concurrent video do…
…wnlaod
- Loading branch information
1 parent
919fe62
commit 07ce535
Showing
13 changed files
with
216 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -102,3 +102,6 @@ venv.bak/ | |
|
||
# mypy | ||
.mypy_cache/ | ||
|
||
# keys folder | ||
keys/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
# YouTubeMDBot | ||
# Copyright (C) 2019 - 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/>. | ||
from io import BytesIO | ||
from subprocess import PIPE | ||
from subprocess import Popen | ||
|
||
|
||
def ffmpeg_available() -> bool: | ||
try: | ||
proc = Popen(["ffmpeg", "-version"], | ||
stdout=PIPE, | ||
stderr=PIPE) | ||
except OSError: | ||
return False | ||
else: | ||
proc.wait() | ||
return proc.returncode == 0 | ||
|
||
|
||
class FFmpegOpener(object): | ||
def __init__(self, data: bytes): | ||
io = BytesIO(data) | ||
self.__ffmpeg_proc = Popen(["ffmpeg", "-i", "-", "-f", "s16le", "-"], | ||
stdout=PIPE, stderr=PIPE, stdin=io) | ||
self.__out = None | ||
self.__err = None | ||
|
||
def open(self) -> int: | ||
self.__out, self.__err = self.__ffmpeg_proc.communicate() | ||
return self.__ffmpeg_proc.returncode | ||
|
||
def get_output(self) -> bytes: | ||
return self.__out | ||
|
||
def get_extra(self) -> bytes: | ||
return self.__err |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# YouTubeMDBot | ||
# Copyright (C) 2019 - 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 re | ||
from subprocess import PIPE | ||
from subprocess import Popen | ||
|
||
from ..constants import FPCALC | ||
|
||
|
||
def is_fpcalc_available() -> bool: | ||
try: | ||
proc = Popen(["fpcalc", "-v"], stdout=PIPE, stderr=PIPE) | ||
except OSError: | ||
return False | ||
else: | ||
proc.wait() | ||
|
||
|
||
class FPCalc(object): | ||
def __init__(self, audio: bytes): | ||
fpcalc = Popen(FPCALC, stdout=PIPE, stdin=PIPE) | ||
out, _ = fpcalc.communicate(audio) | ||
res = out.decode("utf-8") | ||
|
||
duration_pattern = "[^=]\\d+\\n" | ||
fingerprint_pattern = "[^=]*$" | ||
duration = re.search(duration_pattern, res) | ||
fingerprint = re.search(fingerprint_pattern, res) | ||
|
||
self.__duration: int = int(duration.group(0)) | ||
self.__fp: str = str(fingerprint.group(0)) | ||
|
||
def duration(self) -> int: | ||
return self.__duration | ||
|
||
def fingerprint(self) -> str: | ||
return self.__fp |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
SoundFile | ||
musicbrainzngs | ||
ujson | ||
youtube_dl | ||
pyacoustid | ||
python-telegram-bot |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import unittest | ||
from pprint import pprint | ||
|
||
from YouTubeMDBot.downloader import YouTubeDownloader | ||
from YouTubeMDBot.metadata import MetadataIdentifier | ||
|
||
|
||
class IdentifierTest(unittest.TestCase): | ||
def test_identification(self): | ||
url = "https://www.youtube.com/watch?v=YQHsXMglC9A" | ||
downloader = YouTubeDownloader(url=url) | ||
audio, data = downloader.download() | ||
with open("hello.m4a", "wb") as song: | ||
song.write(data) | ||
identifier = MetadataIdentifier(audio=data) | ||
|
||
results = identifier.identify_audio() | ||
print("{0} by {1} - score: {2} / 1\n" | ||
"\thttps://musicbrainz.org/recording/{3}\n" | ||
"\thttps://musicbrainz.org/release/{4}\n\n" | ||
.format(identifier.get_title(), identifier.get_artist(), | ||
identifier.get_score(), | ||
identifier.get_recording_id(), identifier.get_release_id())) | ||
with open("cover.jpg", "wb") as cover: | ||
cover.write(identifier.get_cover()) | ||
|
||
pprint(results) | ||
|
||
|
||
if __name__ == '__main__': | ||
unittest.main() |