继续在python中播放youtube剪辑

时间:2021-09-26 22:57:56

I'm trying to write a simple program to keep opening a 3 minute video in youtube over and over , and after aspecific number of pages it closes every browser then start over again But it only run once .. Please advice

我正在尝试编写一个简单的程序,一遍又一遍地在youtube上打开一个3分钟的视频,然后在每个浏览器关闭的特定数量的页面后重新开始但是它只运行一次..请指教

#Keep playing a youtube clip

import time , webbrowser , os


total_breaks = -1
start=0
def Play():
    try:
        while start != total_breaks:
            print("The {} Play of WaKra Movie started at ".format(start+1),time.ctime())

            with webbrowser.open("https://www.youtube.com/watch?v=XXXXXXXXXX") as play:
                time.sleep(5) #*60*60)
                global start
                start = start + 1
                #time.sleep(5)
                if start % 5 == 0: #every 5 pages close all browsers 
                    os.popen('TASKKILL /IM  iexplore.exe /f')
                    os.popen('TASKKILL /IM firefox.exe /f ')
                    os.popen('TASKKILL /IM chrome.exe /f ')
    except:
        print ("Some Browsers were not found")  

    print("Program terminated at",time.ctime())





Play()

1 个解决方案

#1


A quick fix would be:

快速解决方案是:

#Keep playing a youtube clip

import time , webbrowser , os


total_breaks = -1
start=0
def play():
    try:
        while start != total_breaks:
            print("The {} Play of WaKra Movie started at ".format(start+1),time.ctime())

            with webbrowser.open("https://www.youtube.com/watch?v=XXXXXXXXXX") as play:
                time.sleep(5) #*60*60)
                global start
                start = start + 1
                #time.sleep(5)
                if start % 5 == 0: #every 5 pages close all browsers 
                    os.popen('TASKKILL /IM  iexplore.exe /f')
                    os.popen('TASKKILL /IM firefox.exe /f ')
                    os.popen('TASKKILL /IM chrome.exe /f ')
    except:
        print ("Some Browsers were not found")  

    print("Program terminated at",time.ctime())




while True:
    play()
    time.sleep(180)

I'm not too sure what the purpose of your program is but this will execute your play function (btw functions are ALWAYS in lowercase) every 3 minutes.

我不太确定你的程序的目的是什么,但是这将每3分钟执行你的游戏功能(顺便说一句,函数总是以小写形式)。

#1


A quick fix would be:

快速解决方案是:

#Keep playing a youtube clip

import time , webbrowser , os


total_breaks = -1
start=0
def play():
    try:
        while start != total_breaks:
            print("The {} Play of WaKra Movie started at ".format(start+1),time.ctime())

            with webbrowser.open("https://www.youtube.com/watch?v=XXXXXXXXXX") as play:
                time.sleep(5) #*60*60)
                global start
                start = start + 1
                #time.sleep(5)
                if start % 5 == 0: #every 5 pages close all browsers 
                    os.popen('TASKKILL /IM  iexplore.exe /f')
                    os.popen('TASKKILL /IM firefox.exe /f ')
                    os.popen('TASKKILL /IM chrome.exe /f ')
    except:
        print ("Some Browsers were not found")  

    print("Program terminated at",time.ctime())




while True:
    play()
    time.sleep(180)

I'm not too sure what the purpose of your program is but this will execute your play function (btw functions are ALWAYS in lowercase) every 3 minutes.

我不太确定你的程序的目的是什么,但是这将每3分钟执行你的游戏功能(顺便说一句,函数总是以小写形式)。