Callback when VLC done on command line - python

I need to make VLC download then play songs. I'm planning on using the os.popen to issue commands to the VLC command line (I'm having some problems getting the python binding working...). My question is, is there any callback that I can get when VLC is done downloading so that I can know to start streaming?

You're probably better off doing the download yourself, but if you really want to do this, you might be able to combine http://stromberg.dnsalias.org/~strombrg/notify-when-up2.html with a sniffer like tshark or tcpdump.
Or... You could modify vlc. ^_^

To close VLC after any actions append vlc://quit to your command line

Related

Using aplay to play a sound through subprocess within a python script

There are alot of libraries to play audio within a python script, I was wondering if it would be possible to simply use call aplay through the subprocess feature to play a sound? When I try it I get OSError: [Errno 2] No such file or directory but there is definitely a sound there, it works when I do it through the command prompt. I may be doing something wrong as far as syntax in the python script?
from subprocess import call
call(["aplay /home/pi/file.wav"])
The syntax that will work is :
from subprocess import call
call(["aplay", "/home/pi/file.wav"])
I found that installing
alsa-utils
in this case : sudo apt install alsa-utils
make it work.
example of "text to speech"
import pyttsx3
# init function to get an engine instance
engine = pyttsx3.init()
# say method for input text to be spoken
engine.say('Here the message you want you hear')
# run and wait method, it processes the voice commands.
engine.runAndWait()
I hope it helps.

vlc mac python bindings video output and location of vlc.py

I am hoping that someone can help with a Python bindings output question (using vlc.py)
I have a basic test script that uses vlc.py which runs but does not play the video.
import vlc
def setup_player(filename):
vlc_instance = vlc.Instance('--no-audio', '--fullscreen')
player = vlc_instance.media_player_new()
media = vlc_instance.media_new(filename)
player.set_media(media)
print media.get_mrl() # File location to get title
print player.get_length() #Time duration of file -1 means there is no media
print player.get_state() #Player's state
player.play()
setup_player('foo.mp4')
This outputs
file:///Users/admin/Sites/pythontest/foo.mp4
-1
State.NothingSpecial
I am unsure where to install the vlc.py module and hoping someone can help. I'm on MacOs, VLC 2.0.9, Python 2.7.3. Running python through the terminal.
At the moment I have the vlc.py module in the same directory as my test script - and outside of the VLC.app directories and although the script is executing without errors it isn't playing the video or returning any parameters about the specified mp4 file.
Apologies for a banal question! Any help very gratefully received.
It seems that the player.play() function is not blocking, but instead returns immediately.
If the Python script then terminates, the player is destroyed right after it has been created.
If you look at the example player in vlc.py, it has a while True loop at the very end that basically reads key presses over and over again in order to implement a simple user interface.
So if you simply add
while True:
pass
at the end of your function, it should continue playing (terminate with CTRL+C until you implement some sort of user input handling).
As for "installing" the script: Unfortunately, the vlc.py module they provide is just that, a simple stand-alone Python module. It's not packaged as a setuptools distribution that you could just install with pip or easy_install like most other Python modules. That means you can (or rather have to) drop it into a location that will be in sys.path yourself.
The current working directory where you launch your script from works for that, but if you want a more permanent location you could drop it into your Python's site-packages (/Users/<your-username>/Library/Python/2.7/lib/python/site-packages for example if you're using the standard OS X framework Python).
Since the API calls succeed, it means that the bindings work correctly. The problem here is rather that the macos x video output module is not able to instanciate its own window. It must be embedded in a native Cocoa widget.
You can use the qt example from the vlc repository or use the x11 video output module, combined with the MacOS X X11 server (which has to be installed for recent versions of MacOS X).

Python save .mp3 to a file

Using Python on a Raspian (Raspberry pi) system I can successfully play and listen to a .mp3 file using the os.system() call with mpg123 and a valid URL.
How can I use Python to save the .mp3 file to disk instead of listen to it?
I can save it manually by right-clicking on the web page's Play button and selecting "Save video as...", but I don't know how to do that in a program.
I checked the manual page for mp3123 here:
http://linux.die.net/man/1/mpg123
According to that page, you can specify an output file using the -O option or --outfile.
P.S. os.system() is a simple way to get started. If you ever start getting frustrated by limitations of os.system(), such as not being able to capture the output or the error output, I suggest you use the subprocess module. It's more complicated, but once you are used to it, it's easy to use... and it gives you full control over how your program executes.

Automating Subversion Commands using Python

I am pretty new to Subversion, and not that experienced in Python, but am doing some work with large volume of media-files that need moving around within the directory. Using the Visions GUI, some of the file transfers are taking a very long time, so I'd like to automate these tasks to run over night by storing the actions within a text file and then having a python script act on these overnight?
For example the text file might contain a command such as:
svn mv current desired
How can I send this string to Terminal to execute the command?
You could do os.system call or try using PySVN, which may give you more control in Python over SVN repository you're working with.
The subprocess module is the best way to execute commands. As #Abgan points out, the better way might be to use a subversion library instead.
If you're on Windows, it'd be better to use an SVN library. On Linux/Mac/Unix you could go either way realistically, because these can run a subprocess well - windows doesn't do terribly well at this.
subprocess is indeed preferred over os.system today.
The nice thing about using subprocess.Popen instead of an SVN library (module), is that you don't have to learn two ways of accessing SVN. Your command line SVN knowledge translates directly into your code.

Python and ffmpeg

I am attempting to call ffmpeg to create an image from a frame in a video, I am using python to do this with subprocess.Popen on a mac, eventually this will move to a unix server.
I can successfully create a video from the command line with this line
ffmpeg -i /Users/bimemployee/Movies/ski\ commute.m4v -r .5 -vframes 1 -ss 00:01:14 /Users/bimemployee/Movies/untitled\ folder/image-%d.jpeg
I then turn this into a python iterable and passed it Popen
s=["ffmpeg","-i","Users/bimemployee/Movies/ski\ commute.m4v","-r","1","-vframes","1","-ss","00:01:14","/Users/bimemployee/Movies/untitled\ folder/image-%d.jpeg"]
subprocess.Popen(s)
When I do so I get the standard info screen from ffmpeg and an error that says Users/bimemployee/Movies/ski\ commute.m4v: No such file or directory
Why would this path work ok from the command line but not from python?
Secondly is their a better library for handling this, the ones I could find don't seem to be active projects or don't work with straight python but require things like cython.
Thanks,
CG
You're missing the opening forward slash:
/Users/bimemployee/Movies/ski_commute.m4v
is not the same as
Users/bimemployee/Movies/ski_commute.m4v

Categories

Resources