Automated music library format conversion with cuesheet detection, tagging support and configurable regex to obtain tags from filenames. Configuration with ini-files to support multiple locations with multiple quality requirements.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

86 lines
2.9 KiB

  1. """
  2. Name: utils.py
  3. Porpose: utils used by FFcuesplitter
  4. Platform: MacOs, Gnu/Linux, FreeBSD
  5. Writer: jeanslack <jeanlucperni@gmail.com>
  6. license: GPL3
  7. Rev: January 16 2022
  8. Code checker: flake8 and pylint
  9. ####################################################################
  10. This file is part of FFcuesplitter.
  11. FFcuesplitter is free software: you can redistribute it and/or modify
  12. it under the terms of the GNU General Public License as published by
  13. the Free Software Foundation, either version 3 of the License, or
  14. (at your option) any later version.
  15. FFcuesplitter is distributed in the hope that it will be useful,
  16. but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. GNU General Public License for more details.
  19. You should have received a copy of the GNU General Public License
  20. along with FFcuesplitter. If not, see <http://www.gnu.org/licenses/>.
  21. """
  22. import subprocess
  23. import platform
  24. import datetime
  25. def pairwise(iterable):
  26. """
  27. Return a zip object from iterable.
  28. This function is used by run method.
  29. ----
  30. USE:
  31. after splitting ffmpeg's progress strings such as:
  32. output = "frame= 1178 fps=155 q=29.0 size= 2072kB time=00:00:39.02
  33. bitrate= 435.0kbits/s speed=5.15x "
  34. in a list as:
  35. iterable = ['frame', '1178', 'fps', '155', 'q', '29.0', 'size', '2072kB',
  36. 'time', '00:00:39.02', 'bitrate', '435.0kbits/s', speed',
  37. '5.15x']
  38. for x, y in pairwise(iterable):
  39. (x,y)
  40. <https://stackoverflow.com/questions/5389507/iterating-over-every-
  41. two-elements-in-a-list>
  42. """
  43. itobj = iter(iterable) # list_iterator object
  44. return zip(itobj, itobj) # zip object pairs from list iterable object
  45. # ------------------------------------------------------------------------
  46. def frames_to_seconds(frames):
  47. """
  48. Converts frames (10407600) to seconds (236.0) and then
  49. converts them to a time format string (0:03:56) using datetime.
  50. """
  51. secs = frames / 44100
  52. return str(datetime.timedelta(seconds=secs))
  53. # ------------------------------------------------------------------------
  54. class Popen(subprocess.Popen):
  55. """
  56. Inherit subprocess.Popen class to set _startupinfo.
  57. This avoids displaying a console window on MS-Windows
  58. using GUI's .
  59. """
  60. if platform.system() == 'Windows':
  61. _startupinfo = subprocess.STARTUPINFO()
  62. _startupinfo.dwFlags |= subprocess.STARTF_USESHOWWINDOW
  63. else:
  64. _startupinfo = None
  65. def __init__(self, *args, **kwargs):
  66. """Constructor
  67. """
  68. super().__init__(*args, **kwargs, startupinfo=self._startupinfo)
  69. # def communicate_or_kill(self, *args, **kwargs):
  70. # return process_communicate_or_kill(self, *args, **kwargs)
  71. # ------------------------------------------------------------------------