Minor fixes and .part detection
This commit is contained in:
@@ -15,3 +15,5 @@ class Bot(discord.Bot):
|
||||
async def on_ready(self):
|
||||
print(f'Zalogowano jako {self.user} (ID: {self.user.id})')
|
||||
print(f' Pycord {discord.__version__} | Bot v{__version__}')
|
||||
activity = discord.Activity(type=discord.ActivityType.listening, name='audiobooka Biblii po śląsku')
|
||||
await self.change_presence(activity=activity)
|
||||
|
||||
+3
-3
@@ -1,5 +1,5 @@
|
||||
import discord
|
||||
from ..utils import helpers
|
||||
from ..utils import ytdlp_helpers as helpers
|
||||
from discord.ext import commands
|
||||
|
||||
|
||||
@@ -17,9 +17,9 @@ class Simp(commands.Cog):
|
||||
await ctx.respond(f'Błąd pobierania: {result["message"]}')
|
||||
return
|
||||
|
||||
print(f'Wysyłanie "{result["title"]}" na kanał {ctx.channel.name} ({ctx.guild.name})')
|
||||
print(f'Wysyłanie "{result["title"]}" na kanał #{ctx.channel.name} ({ctx.guild.name})')
|
||||
await ctx.respond(file=discord.File(result['filename']))
|
||||
print(f'Wysyłano "{result["title"]}" na kanał {ctx.channel.name} ({ctx.guild.name})')
|
||||
print(f'Wysyłano "{result["title"]}" na kanał #{ctx.channel.name} ({ctx.guild.name})')
|
||||
|
||||
|
||||
def setup(bot: discord.Bot):
|
||||
|
||||
@@ -24,7 +24,7 @@ def rotate_downloads(downloads_dir: str):
|
||||
|
||||
|
||||
def download_video(yt_url: str) -> dict:
|
||||
yt_url = yt_url.split('&')[0]
|
||||
yt_url = yt_url.split('/?')[0].split('&')[0]
|
||||
MAX_DUR = os.getenv('MAX_DURATION')
|
||||
if not MAX_DUR.isnumeric():
|
||||
return {'status': 'error', 'message': f'MAX_DUR: "{MAX_DUR}" - nie jest cyfrą.'}
|
||||
@@ -37,6 +37,10 @@ def download_video(yt_url: str) -> dict:
|
||||
|
||||
existing = [f for f in os.listdir(DOWNLOADS) if url_hash in f]
|
||||
if existing:
|
||||
if existing[0].split('.')[-1] != 'mp4':
|
||||
os.remove(os.path.join(DOWNLOADS, existing[0]))
|
||||
return {'status': 'error', 'message': f'Błędnie pobrany plik - został usunięty.'}
|
||||
|
||||
print(f'Znaleziono plik "{existing[0]}" ({yt_url})')
|
||||
return {
|
||||
'status': 'success',
|
||||
@@ -51,14 +55,15 @@ def download_video(yt_url: str) -> dict:
|
||||
info = ydl.extract_info(yt_url, download=False)
|
||||
except Exception as e:
|
||||
print(f'Nie można pobrać metadanych: {e}')
|
||||
return {'status': 'error', 'message': f'Nie można pobrać metadanych: {e}'}
|
||||
return {'status': 'error', 'message': f'Nie można pobrać metadanych - {e}'}
|
||||
|
||||
duration = info.get('duration', 0)
|
||||
if duration > MAX_DUR:
|
||||
print(f'Wideo jest za długie ({duration // 60}m {duration % 60}s). Maksymalnie {MAX_DUR // 60}m {MAX_DUR % 60}s.')
|
||||
|
||||
if duration > MAX_DUR or duration == 0:
|
||||
print(f'Błędna długość wideo ({duration // 60}m {duration % 60}s). Maksymalnie {MAX_DUR // 60}m {MAX_DUR % 60}s.')
|
||||
return {
|
||||
'status': 'error',
|
||||
'message': f'Wideo jest za długie ({duration // 60}m {duration % 60}s). Maksymalnie {MAX_DUR // 60}m {MAX_DUR % 60}s.'
|
||||
'message': f'Błędna długość wideo ({duration // 60}m {duration % 60}s). Maksymalnie {MAX_DUR // 60}m {MAX_DUR % 60}s.'
|
||||
}
|
||||
|
||||
rotate_downloads(DOWNLOADS)
|
||||
@@ -68,16 +73,20 @@ def download_video(yt_url: str) -> dict:
|
||||
'merge_output_format': 'mp4',
|
||||
'outtmpl': os.path.join(DOWNLOADS, f'%(title)s_{url_hash}.%(ext)s'),
|
||||
'quiet': True,
|
||||
'http_headers': {
|
||||
'User-Agent': 'Mozilla/5.0'
|
||||
}
|
||||
}
|
||||
|
||||
with yt_dlp.YoutubeDL(ydl_opts) as ydl:
|
||||
try:
|
||||
info = ydl.extract_info(yt_url, download=True)
|
||||
filename = ydl.prepare_filename(info)
|
||||
print(filename)
|
||||
print(f'Pobrano "{info.get("title")}" ({yt_url})')
|
||||
except Exception as e:
|
||||
print(f'Błąd pobierania: {e}')
|
||||
return {'status': 'error', 'message': f'Błąd pobierania: {e}'}
|
||||
return {'status': 'error', 'message': f'{e}'}
|
||||
|
||||
return {
|
||||
'status': 'success',
|
||||
Reference in New Issue
Block a user