17 Respostas
+ 13
★«Caleb Guerra Ortega»★ you can use the python package "youtubedl" to download content (movie clips, audio ...) from YouTube.
Next you can use "PyAudio" to play audio.
youtube-dl and PyAudio are cros-platform powerful librairies.
https://en.wikipedia.org/wiki/Youtube-dl
+ 5
Hi there, you can use the "pytube" module for downloading the song and the "playsound" module to play it. Read through the documentation and you'll have your project up and running in no time!
Both of which can be found here:
https://pypi.org/project/pytube/
https://pypi.org/project/playsound/
+ 3
★«Caleb Guerra Ortega»★ do you mean stream music from YouTube in your python code ?
+ 3
Nazil_the_professor
I know, but I want to play a music from YouTube since my program Python
+ 2
Yes, of course
+ 2
(only run on desktop no mobile)
use mpv.
mpv is a media player that allow you to stream medias(video/audio) from any url.
Download link: https://mpv.io/
import re, requests, subprocess, urllib.parse, urllib.request
from bs4 import BeautifulSoup
music_name = "Linkin Park Numb"
query_string = urllib.parse.urlencode({"search_query": music_name})
formatUrl = urllib.request.urlopen("https://www.youtube.com/results?" + query_string)
search_results = re.findall(r"watch\?v=(\S{11})", formatUrl.read().decode())
clip = requests.get("https://www.youtube.com/watch?v=" + "{}".format(search_results[0]))
clip2 = "https://www.youtube.com/watch?v=" + "{}".format(search_results[0])
inspect = BeautifulSoup(clip.content, "html.parser")
yt_title = inspect.find_all("meta", property="og:title")
for concatMusic1 in yt_title:
pass
print(concatMusic1['content'])
subprocess.Popen(
"start /b " + "path\\to\\mpv.exe " + clip2 + " --no-video --loop=inf --input-ipc-server=\\\\.\\pipe\\mpv-pipe > output.txt",
shell=True)
+ 2
Hmm, say "start: must be a root", Elon Yemp #RELOADED#
+ 2
★«Caleb Guerra Ortega»★ you're running on Linux ? Mac os?
+ 2
I run it in my mobile and my computator is Window
+ 2
Qufu[ISLAM-SOLDIER]
Error:
"/data/user/0/ru.iiec.pydroid3/files/arm-linux-androideabi/lib/python3.9/site-packages/pafy/backend_youtube_dl.py", line 54, in _fetch_basic
self._dislikes = self._ydl_info['dislike_count']
KeyError: 'dislike_count'
+ 1
skaltecho
That's I know, but I want to play a music from Internet
+ 1
Well, ok, Elon Yemp #RELOADED#, that isn't I was want, but ok
+ 1
What more info, Qufu[ISLAM-SOLDIER]?
I need to play a music from YouTube since a Python program.
+ 1
Just install pywhatkit
pip install pywhatkit
+ 1
Jeet Panchal
Next?
+ 1
0
Use python package "youtubedl" And also from audio "PyAudio"