Reputation: 43
I have a list of youtube videos to be played in vlc using python.
I am using tafy
and python-vlc
libraries for the same.
I have managed to play the videos in order using the above libraries.
But now I want to play the videos between certain timestamps ( different for each video ).
So does an API exist in tafy
or python-vlc
which would enable me to play the given video from a specified start timestamp to an end timestamp?
Update: Demo code
import pafy
import vlc
url = "https://www.youtube.com/watch?v=bMt47wvK6u0"
video = pafy.new(url)
best = video.getbest()
playurl = best.url
Instance = vlc.Instance()
player = Instance.media_player_new()
Media = Instance.media_new(playurl)
Media.get_mrl()
player.set_media(Media)
player.play()
sleep(10)
while player.is_playing():
sleep(1)
So now this plays a complete single video. I want to play it within certain ranges.
Upvotes: 3
Views: 8032
Reputation: 22443
The Media
object has both add_option
and add_options
functions.
pafy
falls over for me on Linux, so I can't test it but
Media.add_option('start-time=120.0')
Media.add_option('run-time=60.0')
Should start at the 2 minute mark and run for 1 minute
Media.add_option('start-time=120.0')
Media.add_option('stop-time=180.0')
Should achieve the same result.
Upvotes: 4
Reputation: 2159
You want to use libvlc options for that. With python-vlc, the function to use to pass string to the native library is libvlc_new, you will have to look into this. Then use
Playback control:
--start-time=<float [-340282346638528859811704183484516925440.000000 .. 340282346638528859811704183484516925440.000000]>
Start time
The stream will start at this position (in seconds).
--stop-time=<float [-340282346638528859811704183484516925440.000000 .. 340282346638528859811704183484516925440.000000]>
Stop time
The stream will stop at this position (in seconds).
--run-time=<float [-340282346638528859811704183484516925440.000000 .. 340282346638528859811704183484516925440.000000]>
Run time
The stream will run this duration (in seconds).
And more, from https://wiki.videolan.org/VLC_command-line_help
Upvotes: 0