Ver código fonte

Coonvert add to mp3 when it is not

Hugo Quijada 6 anos atrás
pai
commit
a91c2e57c6
2 arquivos alterados com 10 adições e 1 exclusões
  1. 1 1
      ondemand/__init__.py
  2. 9 0
      ondemand/service.py

+ 1 - 1
ondemand/__init__.py

@@ -1 +1 @@
-__version__ = '1.3.2-rc5'
+__version__ = '1.3.2-rc6'

+ 9 - 0
ondemand/service.py

@@ -16,10 +16,12 @@ from base64 import b64decode
 from threading import Thread
 from multiprocessing import Process
 from argparse import ArgumentParser
+from subprocess import Popen, PIPE
 import logging as log
 import firebase_admin
 import mutagen.mp3
 import OpenSSL.SSL
+import subprocess
 import requests
 import dateutil
 import sqlite3
@@ -438,6 +440,13 @@ def cloud_download(ad_key=None):
         with open(out_file, "wb") as fp:
             fp.write(response.content)
             tp = (out_file, md5sum,)
+            p = Popen(['ffprobe', '-v', 'error', '-select_streams', 'a:0', '-show_entries', 'stream=codec_name', '-of', 'default=nokey=1:noprint_wrappers=1', out_file], stdin=PIPE, stdout=PIPE, stderr=PIPE)
+            rc = p.returncode
+            if rc != 'mp3\n':
+                log.info('[process_segment] file {} is not mp3'.format(out_file))
+                subprocess.call(['mv', out_file, out_file + '.old'])
+                subprocess.call(['ffmpeg', '-hide_banner', '-loglevel', 'panic', '-i', out_file + '.old', '-f', 'mp3', out_file])
+                subprocess.call(['rm', '-rf', out_file + '.old'])
             cloud_cache[ad_key] = tp
             return tp