Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
First metadata approach
  • Loading branch information
Javinator9889 committed Sep 21, 2019
1 parent 8c9fab7 commit 919fe62
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 11 deletions.
7 changes: 0 additions & 7 deletions YouTubeMDBot/__init__.py
Expand Up @@ -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
16 changes: 16 additions & 0 deletions YouTubeMDBot/audio/__init__.py
@@ -0,0 +1,16 @@
# 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
38 changes: 38 additions & 0 deletions YouTubeMDBot/audio/audio_utils.py
@@ -0,0 +1,38 @@
# 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
4 changes: 2 additions & 2 deletions YouTubeMDBot/commands/StartHandler.py
Expand Up @@ -13,12 +13,12 @@
#
# 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):
def __init__(self):
self._user_data = {}

def start(self, bot, update):
self._user_data[]
pass
# TODO
1 change: 0 additions & 1 deletion YouTubeMDBot/decorators/decorators.py
Expand Up @@ -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
18 changes: 17 additions & 1 deletion YouTubeMDBot/metadata/MetadataIdentifier.py
Expand Up @@ -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())
1 change: 1 addition & 0 deletions YouTubeMDBot/requirements.txt
@@ -1,3 +1,4 @@
SoundFile
youtube_dl
pyacoustid
python-telegram-bot

0 comments on commit 919fe62

Please sign in to comment.