-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvlc.py
54 lines (38 loc) · 1.5 KB
/
vlc.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import os
import sys
import subprocess
from pathlib import Path
from typing import Union
def popen(cmd):
startupinfo = subprocess.STARTUPINFO()
startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
process = subprocess.Popen(cmd, shell=True, startupinfo=startupinfo, stdout=subprocess.PIPE, stderr=subprocess.PIPE, stdin=subprocess.PIPE)
return process.stdout.read()
def get_path_exe(exe_name: str, x86: bool = True, folder: str = '') -> Union[str, None]:
''' Retorna a path de um executável '''
path_exe = None
if x86:
path_program_files = os.path.join(os.environ['PROGRAMFILES(X86)'], folder)
else:
path_program_files = os.path.join(os.environ['PROGRAMFILES'], folder)
for path in Path(path_program_files).rglob(exe_name):
path_exe = path
return path_exe
def vlc_path() -> Union[str, bool]:
path_vlc = get_path_exe("vlc.exe", folder='VideoLAN')
if not path_vlc:
path_vlc = get_path_exe("vlc.exe", x86=False, folder='VideoLAN')
if not path_vlc:
return False
return path_vlc
def start_stream(url: str) -> bool:
if sys.platform == 'win32':
path_vlc = vlc_path()
else:
print('[!] A busca automática pelo VLC só funciona no Windows')
print('[!] Sete a path do vlc (path_vlc) manulamente')
if not path_vlc:
print('[-] VLC não foi encontrado !!')
return False
popen(f'"{path_vlc}" "{url}"')
return True