所以我用python pytube和kivy制作了一个youtube视频下载程序,像往常一样,我尝试制作一个apk,但它不起作用,我尝试将pytube添加到我的需求中:在buildozer.spec中,但它一直失败。有人能告诉我这个问题吗?因为我尝试了很多次导入python模块,但总是失败 这是我的代码:
from kivy.lang import Builder
from kivymd.app import MDApp
from kivymd.uix.filemanager import MDFileManager
from kivymd.toast import toast
from kivy.core.window import Window
import pytube
class Main(MDApp):
def build(self):
Window.size = (Window.width,Window.height)
kv = Builder.load_file("Design.kv")
self.theme_cls.theme_style = "Dark"
self.theme_cls.primary_palette = "Red"
return kv
def VidDown(self):
try:
yt = pytube.YouTube(self.root.ids.Link.text)
self.root.ids.thumbnail.color = 1,1,1,1
self.root.ids.thumbnail.source = yt.thumbnail_url
if self.root.ids.low.color == [.21176470535294, .098039627451, 1, 1]:
print("low")
yt.streams.first().download()
elif self.root.ids.mid.color == [.21176470535294, .098039627451, 1, 1]:
print("mid")
yt.streams.filter(progressive = True, file_extension = "mp4").get_lowest_resolution().download()
elif self.root.ids.high.color == [.21176470535294, .098039627451, 1, 1]:
print("high")
yt.streams.filter(progressive = True, file_extension = "mp4").get_highest_resolution().download()
elif self.root.ids.audio.color == [.21176470535294, .098039627451, 1, 1]:
print("audio")
downloaded_file = yt.streams.filter(only_audio = True, subtype='webm', abr='160kbps').first().download()
except:
print("Error")
def reset(self):
self.root.ids.low.color = [255/255,0/255,40/255,1]
self.root.ids.mid.color = [255/255,0/255,40/255,1]
self.root.ids.high.color = [255/255,0/255,40/255,1]
self.root.ids.audio.color = [255/255,0/255,40/255,1]
Main().run()
这是我的kv文件:
MDScreen:
MDFloatLayout:
size: root.width, root.height
MDIconButton:
id: Download
icon:"youtube"
user_font_size: "64sp"
pos_hint:{"center_x":0.5,"center_y": 0.9}
MDTextField:
id: Link
pos_hint: {"center_x":0.5,"center_y":0.7}
size_hint: None,None
size: 400,100
multiline: False
hint_text: "Link"
mode: "rectangle"
MDChip:
id: low
text: "Low quality"
icon: ""
pos_hint: {"center_x":0.2,"center_y":0.6}
size: 12,20
check: True
normal_color: 1,1,1,1
color: 255/255,0/255,40/255,1
selected_chip_color: .21176470535294, .098039627451, 1, 1
MDChip:
id: mid
text: "Medium quality"
pos_hint: {"center_x":0.5,"center_y":0.6}
icon: ""
size: 0,20
check: True
normal_color: 1,1,1,1
color: 255/255,0/255,40/255,1
selected_chip_color: .21176470535294, .098039627451, 1, 1
MDChip:
id: high
text: "High quality"
size: 12,20
icon: ""
pos_hint: {"center_x":0.8,"center_y":0.6}
check: True
normal_color: 1,1,1,1
color: 255/255,0/255,40/255,1
selected_chip_color: .21176470535294, .098039627451, 1, 1
MDChip:
id: audio
text: "mp3"
size: 40,20
icon: ""
pos_hint: {"center_x":0.5,"center_y":0.5}
check: True
normal_color: 1,1,1,1
color: 255/255,0/255,40/255,1
selected_chip_color: .21176470535294, .098039627451, 1, 1
MDIconButton:
id: Download
icon:"download"
user_font_size: "64sp"
pos_hint:{"center_x":0.5,"center_y": 0.4}
on_release: app.VidDown()
MDRaisedButton:
text: "Reset"
size: 40,20
pos_hint:{"center_x":0.5,"center_y": 0.3}
color: 1,0,0,1
on_release: app.reset()
AsyncImage:
id: thumbnail
pos_hint:{"center_x":0.5,"center_y":0.1}
size_hint: 0.9,0.2
source: ""
color: 0,0,0,0
目前没有回答
相关问题 更多 >
编程相关推荐