I'm trying to record and get song information (title and artist) from web radios using python-vlc lib.
The recording functionality is working well but the media parse to get the song information doesn't work!
This is my code:
inst = vlc.Instance() # Create a VLC instance
p = inst.media_player_new() # Create a player instance
cmd1 = "sout=file/ts:%s" % outfile
media = inst.media_new("http://playerservices.streamtheworld.com/api/livestream-redirect/JBFMAAC1.aac", cmd1)
media.get_mrl()
p.set_media(media)
p.play()
media.parse()
for i in range(13):
print("{} - {}".format(i, media.get_meta(i)))
It's always returning "MediaParsedStatus.skipped" status. And all song information returns "None". I tested the same radio in VLC App and there it works fine.
Anyone can help me?
thanks in advance
Since this is a stream, libvlc will not parse it by default (only local files).
You need to use a flag to tell libvlc to parse the media even if it is a network stream.
Use libvlc_media_parse_with_options with MediaParseFlag set to network (1).
Related
import vlc
p = vlc.MediaPlayer("https://www.youtube.com/watch?v=7ailmFB38Rk")
p.play()
gives me this error
[00007f97a80030c0] http stream error: local stream 1 error: Cancellation (0x8)
I was told this is causes if the link is invalid or broken, both of these are not the cases because using regular vlc to play the video works perfectly
Also, if it is somehow not possible to play the video, I only need to play the audio so that will also be of help.
use pafy
# importing vlc module
import vlc
# importing pafy module
import pafy
# url of the video
url = "https://www.youtube.com/watch?v = vG2PNdI8axo"
# creating pafy object of the video
video = pafy.new(url)
# getting best stream
best = video.getbest()
# creating vlc media player object
media = vlc.MediaPlayer(best.url)
# start playing video
media.play()
I have done it using os module but I can't stop the song there. then I use VLC module but it's only applicable for one song only. please help
elif 'music' in query:
music_dir = 'D:\\my songs\\my songs'
songs = os.listdir(music_dir)
random.shuffle(songs)
os.startfile(os.path.join(music_dir,songs[0]))
I want to play all the songs .its working but how to stop songs when its playing
I want to download a Video on a CNN's website using Python 3 automatically.
The address is https://edition.cnn.com/cnn10 .
Every weekday the CNN will put a video on that website.
I know how to find the video's real URL using Chrome browser manually:
Open the adress in Chrome browser, then press F12, like this:
enter image description here
Choosing the label of Network, then click the PLAY button to start playing the video, like this:
enter image description here
Then I can get the real URL, like this:
enter image description here
enter image description here
The video real URL is https://pmd.cdn.turner.com/cnn/big/cnn10/2018/09/13/caption/ten-0914.cnn_2253601_768x432_1300k.mp4
Using the following python 3 code can download that video:
import requests
print("Download is start!")
url = 'https://pmd.cdn.turner.com/cnn/big/cnn10/2018/09/13/caption/ten-0914.cnn_2253601_768x432_1300k.mp4'
r = requests.get(url, stream = True)
with open('20180914.mp4', "wb") as mp4:
for chunk in r.iter_content(chunk_size = 768*432):
if chunk:
mp4.write(chunk)
print("Download over!")
My problem is how to get that URL using Python or any other automatic ways? Because I want to download automatically those different videos every weekday.
What works I have already did:
I am looking for a solution on the Internet but failed.
Then I got some video's URL and try to find a regular pattern about these URL, like this:
https://pmd.cdn.turner.com/cnn/big/cnn10/2018/09/11/caption/ten-0912.cnn_2250840_768x432_1300k.mp4
https://pmd.cdn.turner.com/cnn/big/cnn10/2018/09/10/caption/ten-0911.cnn_2249562_768x432_1300k.mp4
Obviously, the date is related to every weekday, but there is 7 "random" numbers in url. I still can not understand these numbers now!
Any Help will be appreciated !
Thank you !
i am trying to make a media player that generates random subtitles based on nltk library. I am using the vlc python for it, for now i do not care about interface. But i have problem understanding how to put subtitles, even as a srt file.
The function is SubtitleTrack() inside vlc.py. Somewhere else i saw that i must use the add_slave() function.
My code until now is:
import vlc
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new('Test.avi')
Sub = player.add_slave(player,'Test.srt', True)
player.set_media(Media)
player.play()
The version of libvlc is 2.2.6
SubtitleTrack() is a class.
What you want to do is add the subtitles after you hit play. How you do this, from my understanding depends on the version.
import vlc
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new('Test.avi')
player.set_media(Media)
player.play()
player.video_set_subtitle_file('Test.srt')
I don't have the add_slave() function on my local version of vlc, but I would assume it's safe to say functionality stayed the same for compatibility reasons.
If you are using vlc 2.2, you should use
player.video_set_subtitle_file('Test.srt')
but this method has been deprecated in the 3.0 release and you should use add_slave.
You can have a look at https://en.wikipedia.org/wiki/URL#Syntax it will help you with the URL concept, and https://blogs.msdn.microsoft.com/ie/2006/12/06/file-uris-in-windows/ for the application to Windows paths.
I have an application that shows a video stream from a camera, and is able to save the video stream on a file on request. When I run this command from the terminal I see the video in VLC, and the contents is saved on a file as expected:
vlc v4l:///dev/video0:norm=ntsc ':sout=#duplicate{dst=display{noaudio},dst="transcode{vcodec=wmv2,vb=800}:file{dst=aaa.wmv}"}'
However, when I save a file from my application the there are no time codes in the file, so when I open the file in another application I'm unable to move backwards or forwards in the file. I can also not see how long the file is.
Here is a simplified version of my code
factory = new MediaPlayerFactory();
mainframe = new JFrame("Video Viewer");
fullscreenStrategy = new DefaultFullScreenStrategy(mainframe);
Canvas canvas = new Canvas();
canvas.setBackground(Color.black);
EmbeddedMediaPlayer player= factory.newEmbeddedMediaPlayer(fullscreenStrategy);
mainframe.add(canvas);
player.setVideoSurface(factory.newVideoSurface(canvas));
...
String media = "v4l:///dev/video0:norm=ntsc";
String filename = "aaa.wmv";
String mediaoptions = ":sout=#duplicate{ dst=display,"+
" dst=\"transcode{vcodec=wmv2,vb=800}:"+
"file{dst="+filename+"}\"}");
player.prepareMedia(media, mediaoptions);
player.start();
aaa.wmv is created, but without time codes.
What can be wrong? The only difference I see from the command line version is that I use a Canvas widget with the EmbeddedMediaPlayer instead of the native VLC view window.
Never mind, I found the problem. For the time codes to be saved properly it is necessary to call player.release(). I did that, but before the release call I copied the file to another location. Since release hadn't been called yet the file was incomplete. When I changed the code to first call player.release(), then copy the file it worked as expected.