Fixed cutting end of sound, developing micro restreaming

This commit is contained in:
BarsTiger
2022-12-09 17:46:15 +02:00
parent 4d698235a1
commit 1bf045ced9
12 changed files with 139 additions and 10 deletions

View File

@@ -0,0 +1,31 @@
import pydub
import validators
from urllib.request import urlopen
from io import BytesIO
from rich import print
import pafy
import hashlib
import os
def get_silenced_media(original: str) -> str | None:
if not os.path.isdir('temp'):
os.mkdir('temp')
try:
name = original
namehash = 'temp\\' + hashlib.md5(name.encode('utf-8')).hexdigest()
if not os.path.isfile(namehash):
if validators.url(original):
if 'youtu' in original:
original = pafy.new(original).getbestaudio().url
original = BytesIO(urlopen(original).read())
(pydub.AudioSegment.from_file(original) + pydub.AudioSegment.silent(1500))\
.export(namehash, format='mp3')
return namehash
except Exception as e:
print(e)
raise e
return None