autosub-0.4.0.patch 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. --- __init__-0.4.0.py 2019-02-09 21:21:16.335586891 +0700
  2. +++ __init__.py 2019-02-10 21:25:41.864964164 +0700
  3. @@ -8,16 +8,22 @@
  4. import argparse
  5. import audioop
  6. -import json
  7. import math
  8. import multiprocessing
  9. import os
  10. +from json import JSONDecodeError
  11. import subprocess
  12. import sys
  13. import tempfile
  14. import wave
  15. +import json
  16. import requests
  17. +try:
  18. + from json.decoder import JSONDecodeError
  19. +except ImportError:
  20. + JSONDecodeError = ValueError
  21. +
  22. from googleapiclient.discovery import build
  23. from progressbar import ProgressBar, Percentage, Bar, ETA
  24. @@ -61,8 +67,10 @@
  25. start, end = region
  26. start = max(0, start - self.include_before)
  27. end += self.include_after
  28. - temp = tempfile.NamedTemporaryFile(suffix='.flac')
  29. - command = ["ffmpeg", "-ss", str(start), "-t", str(end - start),
  30. + #delete=False necessary for running on Windows
  31. + temp = tempfile.NamedTemporaryFile(suffix='.flac', delete=False)
  32. + program_ffmpeg = which("ffmpeg")
  33. + command = [str(program_ffmpeg), "-ss", str(start), "-t", str(end - start),
  34. "-y", "-i", self.source_path,
  35. "-loglevel", "error", temp.name]
  36. use_shell = True if os.name == "nt" else False
  37. @@ -102,6 +110,8 @@
  38. except IndexError:
  39. # no result
  40. continue
  41. + except JSONDecodeError:
  42. + continue
  43. except KeyboardInterrupt:
  44. return None
  45. @@ -149,17 +159,25 @@
  46. Checks whether a file is executable.
  47. """
  48. return os.path.isfile(file_path) and os.access(file_path, os.X_OK)
  49. -
  50. + #necessary to run on Windows
  51. + if os.name == "nt":
  52. + program += ".exe"
  53. fpath, _ = os.path.split(program)
  54. if fpath:
  55. if is_exe(program):
  56. return program
  57. else:
  58. - for path in os.environ["PATH"].split(os.pathsep):
  59. - path = path.strip('"')
  60. - exe_file = os.path.join(path, program)
  61. - if is_exe(exe_file):
  62. - return exe_file
  63. + #looks for file in the script execution folder before checking on system path
  64. + current_dir = os.getcwd()
  65. + local_program = os.path.join(current_dir, program)
  66. + if is_exe(local_program):
  67. + return local_program
  68. + else:
  69. + for path in os.environ["PATH"].split(os.pathsep):
  70. + path = path.strip('"')
  71. + exe_file = os.path.join(path, program)
  72. + if is_exe(exe_file):
  73. + return exe_file
  74. return None
  75. @@ -171,10 +189,11 @@
  76. if not os.path.isfile(filename):
  77. print("The given file does not exist: {}".format(filename))
  78. raise Exception("Invalid filepath: {}".format(filename))
  79. - if not which("ffmpeg"):
  80. + program_ffmpeg = which("ffmpeg")
  81. + if not program_ffmpeg:
  82. print("ffmpeg: Executable not found on machine.")
  83. raise Exception("Dependency not found: ffmpeg")
  84. - command = ["ffmpeg", "-y", "-i", filename,
  85. + command = [str(program_ffmpeg), "-y", "-i", filename,
  86. "-ac", str(channels), "-ar", str(rate),
  87. "-loglevel", "error", temp.name]
  88. use_shell = True if os.name == "nt" else False
  89. @@ -233,6 +252,12 @@
  90. """
  91. Given an input audio/video file, generate subtitles in the specified language and format.
  92. """
  93. +
  94. + if "Darwin" in os.uname():
  95. + #the default unix fork method does not work on Mac OS
  96. + #need to use forkserver
  97. + multiprocessing.set_start_method('forkserver')
  98. +
  99. audio_filename, audio_rate = extract_audio(source_path)
  100. regions = find_speech_regions(audio_filename)