Skip to content

Commit

Permalink
Merge branch 'main' into main-v49-compat
Browse files Browse the repository at this point in the history
  • Loading branch information
MinmoTech committed Jun 27, 2023
2 parents 54a08bf + e6055e5 commit 7867e4b
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 10 deletions.
23 changes: 20 additions & 3 deletions src/lib/shared/pydub/audio_segment.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,23 @@
StringIO = BytesIO


# Migaku addition to prevent window flashing
class subp:
if hasattr(subprocess, "STARTUPINFO"):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

@classmethod
def Popen(cls, *args, **kwargs):
return subprocess.Popen(*args, **kwargs, startupinfo=cls.startupinfo)

else:

@classmethod
def Popen(cls, *args, **kwargs):
return subprocess.Popen(*args, **kwargs)


class ClassPropertyDescriptor(object):
def __init__(self, fget, fset=None):
self.fget = fget
Expand Down Expand Up @@ -649,7 +666,7 @@ def is_format(f):
log_conversion(conversion_command)

with open(os.devnull, "rb") as devnull:
p = subprocess.Popen(
p = subp.Popen(
conversion_command,
stdin=devnull,
stdout=subprocess.PIPE,
Expand Down Expand Up @@ -828,7 +845,7 @@ def is_format(f):

log_conversion(conversion_command)

p = subprocess.Popen(
p = subp.Popen(
conversion_command,
stdin=stdin_parameter,
stdout=subprocess.PIPE,
Expand Down Expand Up @@ -1062,7 +1079,7 @@ def export(

# read stdin / write stdout
with open(os.devnull, "rb") as devnull:
p = subprocess.Popen(
p = subp.Popen(
conversion_command,
stdin=devnull,
stdout=subprocess.PIPE,
Expand Down
26 changes: 22 additions & 4 deletions src/lib/shared/pydub/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,29 @@
import os
import re
import sys
import subprocess
from subprocess import Popen, PIPE
from math import log, ceil
from tempfile import TemporaryFile


# Migaku addition to prevent window flashing
class subp:
if hasattr(subprocess, "STARTUPINFO"):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

@classmethod
def Popen(cls, *args, **kwargs):
return subprocess.Popen(*args, **kwargs, startupinfo=cls.startupinfo)

else:

@classmethod
def Popen(cls, *args, **kwargs):
return subprocess.Popen(*args, **kwargs)


# TEMPORARY FIX TO PREVENT ERROR POPUPS
# from warnings import warn
def warn(msg, *args, **kwargs):
Expand Down Expand Up @@ -290,7 +308,7 @@ def mediainfo_json(filepath, read_ahead_limit=-1):
file.close()

command = [prober, "-of", "json"] + command_args
res = Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
res = subp.Popen(command, stdin=stdin_parameter, stdout=PIPE, stderr=PIPE)
output, stderr = res.communicate(input=stdin_data)
output = output.decode("utf-8", "ignore")
stderr = stderr.decode("utf-8", "ignore")
Expand Down Expand Up @@ -344,12 +362,12 @@ def mediainfo(filepath):
command_args = ["-v", "quiet", "-show_format", "-show_streams", filepath]

command = [prober, "-of", "old"] + command_args
res = Popen(command, stdout=PIPE)
res = subp.Popen(command, stdout=PIPE)
output = res.communicate()[0].decode("utf-8")

if res.returncode != 0:
command = [prober] + command_args
output = Popen(command, stdout=PIPE).communicate()[0].decode("utf-8")
output = subp.Popen(command, stdout=PIPE).communicate()[0].decode("utf-8")

rgx = re.compile(r"(?:(?P<inner_dict>.*?):)?(?P<key>.*?)\=(?P<value>.*?)$")
info = {}
Expand Down Expand Up @@ -395,7 +413,7 @@ def wrapper():
def get_supported_codecs():
encoder = get_encoder_name()
command = [encoder, "-codecs"]
res = Popen(command, stdout=PIPE, stderr=PIPE)
res = subp.Popen(command, stdout=PIPE, stderr=PIPE)
output = res.communicate()[0].decode("utf-8")
if res.returncode != 0:
return []
Expand Down
2 changes: 1 addition & 1 deletion src/migaku_connection/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
from .audio_condenser import AudioCondenser
from .learning_status_handler import LearningStatusHandler
from .profile_data_provider import ProfileDataProvider
from .ffmpeg_manager import ProgramManager
from .program_manager import ProgramManager
from .info_provider import InfoProvider
from .card_send import CardSender
from .search_handler import SearchHandler
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,23 @@
from .. import config


# Migaku addition to prevent window flashing
class subp:
if hasattr(subprocess, "STARTUPINFO"):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW

@classmethod
def call(cls, *args, **kwargs):
return subprocess.check_call(*args, **kwargs, startupinfo=cls.startupinfo)

else:

@classmethod
def call(cls, *args, **kwargs):
return subprocess.check_call(*args, **kwargs)


class ProgramManager(aqt.qt.QObject):
BASE_DOWNLOAD_URI = "https://migaku-public-data.migaku.com/"
lock = Lock()
Expand Down Expand Up @@ -41,7 +58,7 @@ def is_available(self):

def call(self, *args, **kwargs):
assert self.is_available()
return subprocess.call([self.program_path, *args], **kwargs)
return subp.call([self.program_path, *args], **kwargs)

def make_available(self):
# Attempt global installation
Expand Down Expand Up @@ -156,7 +173,7 @@ def check_set_program_path(self, path):
if not path:
return False
try:
subprocess.call([path, "-version"])
subp.call([path, "-version"])
self.program_path = path
return True
except OSError:
Expand Down

0 comments on commit 7867e4b

Please sign in to comment.