首页 > 编程问答 >pywhatkit 打开同一个 YouTube 视频

pywhatkit 打开同一个 YouTube 视频

时间:2024-07-31 11:04:27浏览次数:6  
标签:python pywhatkit

当尝试使用 pywhatkit 打开 YouTube 视频时,它可以工作,只是每次都会打开相同的 YouTube 视频。我没有要求的一个

 if 'play' in command:
        song = command.replace('play', '')
        talk('playing' + song)
        pywhatkit.playonyt('song')

它一直打开这个链接 https://www.youtube.com/watch?v=Jq_WDQsKYu8&ab_channel=PopularMusic


问题在于你传递给 pywhatkit.playonyt() 的参数。你总是传递字符串字面量 “song”,而不是变量 song 的内容。

将其更改为传递 song 变量,你的代码就能正常工作:

if 'play' in command:
    song = command.replace('play', '')
    talk('playing' + song)
    pywhatkit.playonyt(song)  # 传递 song 变量,而不是字符串 "song"

通过此更改, pywhatkit.playonyt() 将使用 song 变量中存储的实际歌曲标题搜索 YouTube,从而打开正确的视频。

标签:python,pywhatkit
From: 69992718

相关文章

  • Python应用—加密、解密文件
    1.创作需求日常生活中我们有很多文件想要保密。这个脚本可以方便大家对所有的文件类型进行加密,解密。最大程度保护我们的隐私。2.话不多说,直接上代码fromcryptography.fernetimportFernetimportdocx#加密defencrypt_file(filename):#生成密钥key=Fer......
  • 使用 pywhatkit 发送 Whatsapp 消息时出错
    我的程序应该使用pywhatkit库通过语音识别获取用户的输入来发送whatsapp消息。这是发送消息的功能。defWhatsApp():speak("ForWhomshouldisendmessage")Contacts={'mom':63XXXXXXX,#thesearenumbers(hidden)'karthi......
  • 如何在Google Colaboratory上导入并使用PyWhatKit?
    我想使用pywhatkit库自动从GoogleColab在WhatsApp上发送消息。到目前为止,我已经尝试过这样做:pipinstallpywhatkit输出:Requirementalreadysatisfied:pywhatkitin/usr/local/lib/python3.7/dist-packages(5.3)Requirementalreadysatisfied:wikipediain......
  • 使用 pywhatkit 发送 Whatsapp 消息但出现错误
    嘿,我是python编程新手,我正在尝试使用Pywhatkit在特定时间向特定号码发送Whatsapp消息。这是我的代码importpywhatkitpywhatkit.sendwhatmsg("anumber","Hi",0,43)这是我在运行此代码时收到的错误|||请帮我解决这个问题。PSD:\PROJECTS\python>pyth......
  • 三种语言实现二维前缀和(C++/Python/Java)
    题目输入一个n行m列的整数矩阵,再输入q个询问,每个询问包含四个整数x1,y1,x2,y2表示一个子矩阵的左上角坐标和右下角坐标。对于每个询问输出子矩阵中所有数的和。输入格式第一行包含三个整数n,m,q接下来n行,每行包含m个整数,表示整数矩阵。接下来q行,每行包含四个整数......
  • Python rocketMq 客户端的同步和异步模式
    同步模式fromrocketmq.clientimportPushConsumer,ConsumeStatusimporttimedefcallback(msg):print(msg.id,msg.body,msg.get_property('property'))returnConsumeStatus.CONSUME_SUCCESSdefstart_consume_message():consumer=PushCon......
  • python中元组的学习
    元组目录元组元组的概念元组操作元组的常用方法元组的遍历元组的概念Tuple(元组)与列表相似,不同之处遭遇元组的元素不能修改元组表示多个元素组成的序列用于储存一串信息,数据之间使用,分隔元组用()定义#元组的创建info_tuple=("zhangsan",18,1.75)info_tuple2=(1,)#......
  • 尝试通过Python访问.zip文件中的.gz文件
    我有一个包含大量.gz文件的.zip文件,我需要对其进行处理。我想打开.zip,我可以通过以下代码轻松完成:zf=zipfile.ZipFile("file.zip","r")forgzfileinzf.filelist:withgzip.GzipFile(fileobj=zf.open(gzfile.filename,"r"),mode="r")asf:df......
  • python导入包报错ImportError: cannot import name ‘Protocol‘
    python32.pyTraceback(mostrecentcalllast):File"2.py",line5,in<module>importptwt#use"fromsrcimportptwt"foraclonedtherepoFile"……lib/python3.6/site-packages/ptwt/_util.py",line2......
  • Python - Creating your own Iterator
    Inourfirstexample,wewillcreateiterableobjects,which,wheniteratedover,willgiveoutcubesofnumbers,andtheseobjectswillsupportmultipleiterations.classCubes:def__init__(self,start,stop):self.start=startsel......