Commit 919fe624 authored by Javinator9889's avatar Javinator9889 🎼

First metadata approach

parent 8c9fab79
Pipeline #64 failed with stage
in 1 minute and 47 seconds
......@@ -13,11 +13,4 @@
#
# 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 .bot import PROGRAM_ARGS
from .bot import main
from .logging_utils import LoggingHandler
from .logging_utils import setup_logging
from .decorators import send_action
from .decorators import restricted
# 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 ..audio.audio_utils import AudioUtils
# 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
import soundfile
class AudioUtils(object):
def __init__(self, audio: BytesIO):
self.__audio = soundfile.SoundFile(audio)
def get_audio_samplerate(self) -> int:
return self.__audio.samplerate
def get_audio_channels(self) -> int:
return self.__audio.channels
def get_audio_duration(self) -> float:
return self.__audio.frames / self.get_audio_samplerate()
def get_audio_name(self) -> str:
return self.__audio.name
def get_audio_format(self) -> str:
return self.__audio.format
......@@ -13,7 +13,6 @@
#
# 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 .. import LoggingHandler
class StartHandler(object):
......@@ -21,4 +20,5 @@ class StartHandler(object):
self._user_data = {}
def start(self, bot, update):
self._user_data[]
pass
# TODO
......@@ -48,7 +48,6 @@ def restricted(func):
def wrapped(update, context, *args, **kwargs):
user_id = update.effective_user.id
if user_id not in PROGRAM_ARGS["admin"]:
logging.warning("Unauthorized access denied for {}.".format(user_id))
return
return func(update, context, *args, **kwargs)
return wrapped
......@@ -13,8 +13,24 @@
#
# 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
import acoustid
from .. import AudioUtils
class MetadataIdentifier(object):
def __init__(self, filename: str = None, audio: str = None):
def __init__(self, audio: BytesIO, raw: bytes):
self.__audio = raw
self.__audio_info = AudioUtils(audio)
def _calculate_fingerprint(self) -> bytes:
return acoustid.fingerprint(self.__audio_info.get_audio_samplerate(),
self.__audio_info.get_audio_channels(),
iter(self.__audio))
def identify_audio(self) -> list:
fingerprint = self._calculate_fingerprint()
return acoustid.lookup(None, fingerprint,
self.__audio_info.get_audio_duration())
SoundFile
youtube_dl
pyacoustid
python-telegram-bot
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment