Created
February 9, 2015 16:02
-
-
Save Elettronik/8e970c9e7bfa894f5214 to your computer and use it in GitHub Desktop.
Stream pulseaudio in wifi network
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import difflib | |
import re | |
import subprocess | |
def add_module(mod_props): | |
''' | |
Add a module to pulseaudio and return | |
the index | |
''' | |
mod_list_before = subprocess.check_output(['pacmd', 'list-modules'], universal_newlines=True) | |
#Aggiungo il modulo | |
mod_def = ['pacmd', 'load-module'] | |
mod_def.extend(mod_props) | |
subprocess.call(mod_def) | |
mod_list_after = subprocess.check_output(['pacmd', 'list-modules'], universal_newlines=True) | |
diff = difflib.ndiff(mod_list_before.splitlines(1), mod_list_after.splitlines(1)) | |
module_inserted = [line for line in diff if line.startswith('+ ')] | |
for line in module_inserted: | |
match = re.search('index: (\d+)', line) | |
if match: | |
return match.group(1) | |
def clean_modules (modules) : | |
''' | |
Clean the list of modules loaded by this script | |
''' | |
for mod in modules: | |
subprocess.call(['pacmd', 'unload-module', mod]) | |
if __name__ == '__main__': | |
modules_ids = [] | |
modules_ids.append(add_module(['module-null-sink'])) | |
clean_modules(modules_ids) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment