1

Hey everyone this is my first question so I apologize for any formatting errors/ignorance. I'm working on a personal assistant and I want it to stream youtube videos (audio only). I've managed to get it to find the url of the first video of a search term, but I can't for the life of me figure out how to get mplayer to stream that url. I'm using pafy and this mplayer wrapper.

import urllib.request
import urllib.parse
import re
import pafy
import os
import mplayer
import subprocess


query_string = urllib.parse.urlencode({"search_query" : input()})
html_content = urllib.request.urlopen("http://www.youtube.com/results?" + query_string)
search_results = re.findall(r'href=\"\/watch\?v=(.{11})', html_content.read().decode())
url = ("http://www.youtube.com/watch?v=" + search_results[0])

v = pafy.new(url)
print(v.audiostreams)
s = v.getbestaudio()

This is the code to get the url and create a pafy instance. I'd greatly appreciate any help you guys could offer in streaming it to mplayer. Thanks!

4

0 回答 0