3

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.

orsfield
  • 33
  • 1
  • 6

2 Answers2

4

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.

Rolf of Saxony
  • 21,661
  • 5
  • 39
  • 60
0

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

mfkl
  • 1,914
  • 1
  • 11
  • 21
  • Is there a python wrapper present for the same. For example '--fullscreen' option, when passed during instance creation, has no effect, but works when I use the .set_fullscreen() function on the instance. – orsfield Aug 04 '20 at 21:03
  • I tried to use the set_position API but I keep getting this error: Assertion failed! File: /home/jenkins/workspace/vlc-nightly/vlc-nightly-win64-x86_64/extras/package/win32/../../../src/player/player.c, Line 1346 Expression: speed == VLC_PLAYER_SEEK_PRECISE || speed == VLC_PLAYER_SEEK_FAST – orsfield Aug 04 '20 at 21:23
  • the --fullscreen option is not what you think it is. Anyway, try using the start/stop time in libvlc_new – mfkl Aug 05 '20 at 07:29