학교 음악 듣기 수행평가 연습용으로 만든 python script 입니다.
- youtube URL 리스트를 무작위로 모두 audio로만 재생
- 1분간만 재생
- Audio 재생 시작은 30초 이후 구간부터
import pafy
import vlc
import time
import random
import sys
play_time = 60
def play_url(url):
video = pafy.new(url)
best = video.getbestaudio()
playurl = best.url
vlc_ins = vlc.Instance()
player = vlc_ins.media_player_new()
media = vlc_ins.media_new(playurl)
media.get_mrl()
media.add_option('start-time=30.0')
player.set_media(media)
player.play()
return player
url = ["https://www.youtube.com/watch?v=s7w-IeNR9ko",
"https://www.youtube.com/watch?v=9iR-gFIU4h4&t=22s",
"https://www.youtube.com/watch?v=MW8asBxO4oI",
"https://www.youtube.com/watch?v=cH2PH0auTUU",
"https://www.youtube.com/watch?v=iT19awyhYKE",
"https://www.youtube.com/watch?v=Q7mKmzQuiog",
"https://www.youtube.com/watch?v=GRu53u-yvQM",
"https://www.youtube.com/watch?v=_HX_jF1_Tgc",
"https://www.youtube.com/watch?v=GTXBLyp7_Dw"]
random.shuffle(url)
for link in url:
player = play_url(link)
time.sleep(play_time)
player.stop()