update subprocess to Popen with subprocess.PIPE for Python 3.6 stdout piping support (no capture output kwarg)

This commit is contained in:
Xevion
2019-12-23 16:22:03 -06:00
parent e792b11c1c
commit e8d889456a

View File

@@ -32,10 +32,11 @@ class YouTubeHandler:
config = YouTubeHandler.getConfig(videoid) config = YouTubeHandler.getConfig(videoid)
return config['filename'] return config['filename']
except KeyError: except KeyError:
filename = subprocess.run( # Use stdout=PIPE, [Python 3.6] production server support instead of 'capture_output=True' => 'process.stdout'
['youtube-dl', '-x', '--audio-format', 'mp3', '--restrict-filenames', '--get-filename', process = subprocess.Popen(
YouTubeHandler.url(videoid)], encoding='utf-8', capture_output=True).stdout ['youtube-dl', '-x', '--audio-format', 'mp3', '--restrict-filenames', '--get-filename', YouTubeHandler.url(videoid)],
filename = filename.split('.') encoding='utf-8', stdout=subprocess.PIPE)
filename = process.communicate()[0].split('.')
filename[-1] = 'mp3' filename[-1] = 'mp3'
return '.'.join(filename) return '.'.join(filename)
@@ -63,7 +64,6 @@ class YouTubeHandler:
config = YouTubeHandler.getConfig(videoid) config = YouTubeHandler.getConfig(videoid)
if not os.path.exists(config['path']): if not os.path.exists(config['path']):
subprocess.run(['youtube-dl', '-x', '--restrict-filenames', '--audio-format', 'mp3', YouTubeHandler.url(videoid)]) subprocess.run(['youtube-dl', '-x', '--restrict-filenames', '--audio-format', 'mp3', YouTubeHandler.url(videoid)])
print(os.listdir('.'))
os.rename(config['filename'], config['path']) os.rename(config['filename'], config['path'])
service_functions = { service_functions = {