Commit 6e6ade3d authored by Javinator9889's avatar Javinator9889 🎼

pylint improvement - completed API and ffmpeg audio classes & methods

parent e55eb1a7
Pipeline #88 failed with stage
in 27 minutes and 49 seconds
......@@ -21,6 +21,10 @@ from ..constants import FPCALC
def is_fpcalc_available() -> bool:
"""
Checks if ffmpeg is installed in the system.
:return: True if available, else False.
"""
try:
proc = Popen(["fpcalc", "-v"], stdout=PIPE, stderr=PIPE)
except OSError:
......@@ -29,8 +33,16 @@ def is_fpcalc_available() -> bool:
proc.wait()
class FPCalc(object):
class FPCalc:
"""
Calculates audio fingerprint by passing the audio bytes.
It operates with pipes so no file is created.
"""
def __init__(self, audio: bytes):
"""
Creates the FPCalc object.
:param audio: the audio bytes.
"""
fpcalc = Popen(FPCALC, stdout=PIPE, stdin=PIPE)
out, _ = fpcalc.communicate(audio)
res = out.decode("utf-8")
......@@ -44,7 +56,15 @@ class FPCalc(object):
self.__fp: str = str(fingerprint.group(0))
def duration(self) -> int:
"""
Obtains the audio duration in seconds.
:return: duration in seconds.
"""
return self.__duration
def fingerprint(self) -> str:
"""
Obtains the audio fingerprint.
:return: fingerprint in seconds.
"""
return self.__fp
......@@ -17,5 +17,6 @@ from ..constants.app_constants import ACOUSTID_KEY
from ..constants.app_constants import FPCALC
from ..constants.app_constants import YDL_CLI_OPTIONS
from ..constants.app_constants import YOUTUBE
from ..constants.app_constants import PROGRAM_ARGS
from ..constants.app_constants import FFMPEG_OPENER
from ..constants.app_constants import FFMPEG_CONVERTER
......@@ -14,7 +14,9 @@
# 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 os
import sys
PROGRAM_ARGS = sys.argv
# YouTube DL options
YDL_CLI_OPTIONS = ["youtube-dl", "--format", "bestaudio[ext=m4a]", "--quiet", "--output",
"-"]
......
......@@ -15,7 +15,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from functools import wraps
from .. import PROGRAM_ARGS
from ..constants import PROGRAM_ARGS
# logging = LoggingHandler()
......
......@@ -19,13 +19,24 @@ from typing import Tuple
from ..constants.app_constants import YDL_CLI_OPTIONS
class YouTubeDownloader(object):
class YouTubeDownloader:
"""
Download a YouTube video directly into memory.
"""
def __init__(self, url: str):
"""
Creates the YouTubeDownloader object. Call "download" for obtaining the video.
:param url: the video URL.
"""
self.__url: str = url
self.__options: list = YDL_CLI_OPTIONS.copy()
self.__options.append(self.__url)
def download(self) -> Tuple[BytesIO, bytes]:
"""
Downloads the YouTube video directly into memory by using pipes.
:return: a tuple with "BytesIO" and "bytes".
"""
import subprocess
proc = subprocess.Popen(self.__options,
......@@ -40,4 +51,8 @@ class YouTubeDownloader(object):
str(stderr.decode("utf-8")))
def get_url(self) -> str:
"""
Obtains the video URL.
:return: str with the URL.
"""
return self.__url
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