Send cached V1.0.8
This commit is contained in:
+1
-1
@@ -1,6 +1,6 @@
|
|||||||
import discord
|
import discord
|
||||||
|
|
||||||
__version__ = '1.0.7'
|
__version__ = '1.0.8'
|
||||||
__author__ = 'Kartoniarz'
|
__author__ = 'Kartoniarz'
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+11
-2
@@ -26,12 +26,22 @@ def rotate_downloads(downloads_dir: str):
|
|||||||
def download_video(yt_url: str) -> dict:
|
def download_video(yt_url: str) -> dict:
|
||||||
MAX_DUR = os.getenv('MAX_DURATION')
|
MAX_DUR = os.getenv('MAX_DURATION')
|
||||||
if not MAX_DUR.isnumeric():
|
if not MAX_DUR.isnumeric():
|
||||||
return {'status': 'error', 'message': f'MAX_DUR: \"{MAX_DUR}\" - nie jest cyfrą.'}
|
return {'status': 'error', 'message': f'MAX_DUR: "{MAX_DUR}" - nie jest cyfrą.'}
|
||||||
|
|
||||||
MAX_DUR = int(MAX_DUR)
|
MAX_DUR = int(MAX_DUR)
|
||||||
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
|
||||||
DOWNLOADS = os.path.join(BASE_DIR, 'downloads')
|
DOWNLOADS = os.path.join(BASE_DIR, 'downloads')
|
||||||
os.makedirs(DOWNLOADS, exist_ok=True)
|
os.makedirs(DOWNLOADS, exist_ok=True)
|
||||||
|
url_hash = hashlib.sha1(yt_url.encode()).hexdigest()[:10]
|
||||||
|
|
||||||
|
existing = [f for f in os.listdir(DOWNLOADS) if url_hash in f]
|
||||||
|
if existing:
|
||||||
|
print(f'Znaleziono plik "{url_hash}" ({yt_url})')
|
||||||
|
return {
|
||||||
|
"status": "success",
|
||||||
|
"filename": os.path.join(DOWNLOADS, existing[0]),
|
||||||
|
"cached": True,
|
||||||
|
}
|
||||||
|
|
||||||
with yt_dlp.YoutubeDL({'quiet': True}) as ydl:
|
with yt_dlp.YoutubeDL({'quiet': True}) as ydl:
|
||||||
try:
|
try:
|
||||||
@@ -50,7 +60,6 @@ def download_video(yt_url: str) -> dict:
|
|||||||
}
|
}
|
||||||
|
|
||||||
rotate_downloads(DOWNLOADS)
|
rotate_downloads(DOWNLOADS)
|
||||||
url_hash = hashlib.sha1(yt_url.encode()).hexdigest()[:10]
|
|
||||||
|
|
||||||
ydl_opts = {
|
ydl_opts = {
|
||||||
'format': 'bestvideo+bestaudio/best',
|
'format': 'bestvideo+bestaudio/best',
|
||||||
|
|||||||
Reference in New Issue
Block a user