2015-05-07 104 views
0

我正在嘗試編寫一個簡單的程序來反覆在YouTube上打開一個3分鐘的視頻,並在特定數量的頁面關閉每個瀏覽器後再重新開始 但它只運行一旦..請指點繼續在Python中播放YouTube剪輯

#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() 

回答

0

速戰速決是:

#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) 

我不太清楚你的程序的目的是什麼,但這樣會執行您的play功能(順便說一句函數總是以小寫字母)每3分鐘一次。

+0

感謝您的回覆。此計劃的目的是儘可能多地增加此剪輯的視圖 – SkyW3lker