Traceback (most recent call last):
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\uvicorn\protocols\http\h11_impl.py", line 403, in run_asgi
result = await app(self.scope, self.receive, self.send)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\uvicorn\middleware\proxy_headers.py", line 78, in __call__
return await self.app(scope, receive, send)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\fastapi\applications.py", line 269, in
__call__
await super().__call__(scope, receive, send)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\applications.py", line 124, in __call__
await self.middleware_stack(scope, receive, send)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\middleware\errors.py", line 184, in __call__
raise exc
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\middleware\errors.py", line 162, in __call__
await self.app(scope, receive, _send)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\exceptions.py", line 93, in __call__
raise exc
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\exceptions.py", line 82, in __call__
await self.app(scope, receive, sender)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py",
line 21, in __call__
raise e
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\fastapi\middleware\asyncexitstack.py",
line 18, in __call__
await self.app(scope, receive, send)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\routing.py", line 670, in __call__
await route.handle(scope, receive, send)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\routing.py", line 266, in handle
await self.app(scope, receive, send)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\routing.py", line 65, in app
response = await func(request)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\fastapi\routing.py", line 227, in app
raw_response = await run_endpoint_function(
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\fastapi\routing.py", line 162, in run_endpoint_function
return await run_in_threadpool(dependant.call, **values)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\starlette\concurrency.py", line 41, in
run_in_threadpool
return await anyio.to_thread.run_sync(func, *args)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\anyio\to_thread.py", line 31, in run_sync
return await get_asynclib().run_sync_in_worker_thread(
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 937, in run_sync_in_worker_thread
return await future
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\anyio\_backends\_asyncio.py", line 867, in run
result = context.run(func, *args)
File "C:\Users\vizzy\Desktop\program\testapi\bot\app_video\main.py", line 19, in create_video
yt = YouTube(l)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\pytube\__main__.py", line 71, in __init__
self.video_id = extract.video_id(url)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\pytube\extract.py", line 133, in video_id
return regex_search(r"(?:v=|\/)([0-9A-Za-z_-]{11}).*", url, group=1)
File "C:\Users\vizzy\Desktop\program\testapi\venv\lib\site-packages\pytube\helpers.py", line 129, in regex_search
raise RegexMatchError(caller="regex_search", pattern=pattern)
pytube.exceptions.RegexMatchError: regex_search: could not find match for (?:v=|\/)([0-9A-Za-z_-]{11}).*
@app.post('/video')
def create_video(item: Video):
videos = []
links= item.link
for l in links:
yt = YouTube(l)
try:
stream = yt.streams.filter(progressive=True, res="720p")[0]
name = f"{yt.title.replace('.', '')}.mp4"
stream.download()
videos.append(name.replace(':', '').replace('\'', '').replace('\\', '').replace('\"', '').replace('/', '').replace('#', ''))
except IndexError:
stream = yt.streams.filter(progressive=True)[0]
name = f"{yt.title}.mp4"
stream.download()
videos.append(name.replace(':', '').replace('\'', '').replace('\\', '').replace('\"', '').replace('/', ''))
except RegexMatchError: # не работает, разобраться почему
return "Загрузка не удалась, проверьте ссылки, либо повторите попытку позже"
@dp.message_handler(state=StorageLink.links)
async def input_links(message: types.Message, state: FSMContext):
async with state.proxy() as data:
data['links'] = message.text.split('\n')
test = data["links"]
header = {"link": test}
print(header)
response = requests.post("http://127.0.0.1:8000/video", data=header)
await bot.send_message(message.chat.id, response.status_code)
def download_videos(self, links: list):
for l in links:
self.yt = YouTube(l)
try:
self.stream = self.yt.streams.filter(progressive=True, res="720p")[0]
self.yt.title = self.yt.title.replace('.', '').replace(':', '').replace('\'', '').replace('\\', '').replace('\"', '')
self.stream.download(output_path = MAIN_FOLDER)
self.name = f"{self.yt.title}.mp4"
self.videos.append(self.name)
except IndexError:
self.stream = self.yt.streams.filter(progressive=True)[0]
self.yt.title = self.yt.title.replace('.', '').replace(':', '').replace('\'', '').replace('\\', '').replace('\"', '')
self.stream.download(output_path = MAIN_FOLDER)
self.name = f"{self.yt.title}.mp4"
self.videos.append(self.name)
def read_playlist(self, link):
pl = Playlist(link)
links = [i for i in pl]
return links
def concat_video(self, name, args: list):
r_videos = []
for video in args:
r_v = VideoFileClip(video)
r_videos.append(r_v)
try:
final_clip = concatenate_videoclips(r_videos)
final_clip.write_videofile(f"{name}.mp4")
for video in args:
path = os.path.join(os.path.abspath(video))
os.remove(path)
except Exception as ex:
print("Ничего не вышло :(")
print(ex)
POST 127.0.0.1:5000/res 400 (BAD REQUEST)