我有一个应用程序,用于zmq与asyncio能够将视频下载youtube-dl到服务器的客户端进行通信。我尝试添加awaittoyoutube_dl的下载功能,但它给了我一个错误,因为它不是协程。我现在的代码只是看起来像这样:
import asyncio
import youtube_dl
async def networking_stuff():
download = True
while True:
if download:
print("Received a request for download")
await youtube_to_mp3("https://www.youtube.com/watch?v=u9WgtlgGAgs")
download = False
print("Working..")
await asyncio.sleep(2)
async def youtube_to_mp3(url):
ydl_opts = {
'format': 'bestaudio/best',
'postprocessors': [{
'key': 'FFmpegExtractAudio',
'preferredcodec': 'mp3',
'preferredquality': '192',
}]
}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([url])
loop = asyncio.get_event_loop()
loop.create_task(networking_stuff())
loop.run_forever()
Run Code Online (Sandbox Code Playgroud)
这给出了以下输出:
Received a request for download
[youtube] u9WgtlgGAgs: Downloading webpage
[youtube] u9WgtlgGAgs: Downloading video …Run Code Online (Sandbox Code Playgroud) 我正在尝试用圆圈创建倒计时.该圆圈将显示与给定的时间量相比已经过了多少时间.因此,如果倒计时是10秒并且已经过了5,那么将绘制半圈.我想出了这段代码:
from math import pi
import pygame
pygame.init()
(x, y) = (800, 600)
screen = pygame.display.set_mode((x, y))
clock = pygame.time.Clock()
radius = 50
# Just to place the circle in the center later on
top_left_corner = ((x / 2) - (radius / 2), (y / 2) - (radius / 2))
outer_rect = pygame.Rect(top_left_corner, (radius, radius))
countdown = 1000 # seconds
angle_per_frame = 2 * pi / (countdown * 60)
angle_drawn = 0
new_angle = angle_per_frame
while True:
if angle_drawn < …Run Code Online (Sandbox Code Playgroud) 像我的问题,我该怎么办?我已经开始创建一个打开网站的.bat文件,现在我希望它将光标移动到屏幕的特定X'Y位置并左键单击.有没有办法可以在.bat或任何其他类型的脚本中执行此操作?
在此先感谢,-Stam
python-3.x ×2
async-await ×1
batch-file ×1
ffmpeg ×1
mousemove ×1
pygame ×1
python ×1
windows ×1
youtube-dl ×1