Skip to content

Commit

Permalink
apply python-black formatter
Browse files Browse the repository at this point in the history
  • Loading branch information
patillacode committed Oct 25, 2021
1 parent 7d33da7 commit 8aaa18d
Show file tree
Hide file tree
Showing 8 changed files with 111 additions and 129 deletions.
1 change: 1 addition & 0 deletions convert/__main__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
from .cli import main

main()
11 changes: 6 additions & 5 deletions convert/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,16 +26,17 @@
"""


from inspect import getmembers, isclass

from docopt import docopt
from inspect import getmembers
from inspect import isclass

from . import __version__ as VERSION


def main():
"""Main CLI entrypoint."""
import convert.commands

options = docopt(__doc__, version=VERSION)

# Here we'll try to dynamically match the command the user is trying to run
Expand All @@ -44,8 +45,8 @@ def main():
if hasattr(convert.commands, k) and v:
module = getattr(convert.commands, k)
convert.commands = getmembers(module, isclass)
command = [command[1] for command
in convert.commands
if command[0] != 'Base'][0]
command = [
command[1] for command in convert.commands if command[0] != 'Base'
][0]
command = command(options)
command.run()
16 changes: 4 additions & 12 deletions convert/commands/audio.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,25 +13,17 @@ def __init__(self, options, *args, **kwargs):
1: {
'option_text': 'Convert to .mp3 (320k)',
'extension': 'mp3',
'params': {
'ar': 44100,
'ac': 2,
'ab': '320k ',
'f': 'mp3'
}
'params': {'ar': 44100, 'ac': 2, 'ab': '320k ', 'f': 'mp3'},
},
2: {
'option_text': 'Convert to .wav',
'extension': 'wav',
'params': {}
}
2: {'option_text': 'Convert to .wav', 'extension': 'wav', 'params': {}},
}

def run(self):
"""Run the Audio command."""
chosen_option = let_user_pick(self.conversion_map)
source_paths, output_paths, params = self.get_user_input(
self.conversion_map[chosen_option])
self.conversion_map[chosen_option]
)
for (source_path, output_path) in list(zip(source_paths, output_paths)):
run_ffmpeg(source_path, output_path, params, self.options)
prmsg('completed')
49 changes: 31 additions & 18 deletions convert/commands/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@

from termcolor import colored

from ..converter_utils import clear, confirmator, multi_source
from ..converter_utils import print_message as prmsg
from ..converter_utils import single_source, validate_path
from ..converter_utils import (clear, confirmator, multi_source, single_source,
validate_path)


class Base(object):
Expand Down Expand Up @@ -41,9 +40,16 @@ def get_user_input(self, conversion_data):
source_path, source_name, source_folder = single_source()

default_folder = '{}'.format(source_folder)
destination = input(colored(
"Enter path to destination folder "
"(Enter for same folder as source): ", 'green')) or default_folder
destination = (
input(
colored(
"Enter path to destination folder "
"(Enter for same folder as source): ",
'green',
)
)
or default_folder
)
destination = validate_path(destination, 'folder')

source_paths = []
Expand All @@ -53,10 +59,13 @@ def get_user_input(self, conversion_data):
if self.options['--multiple']:
confirmator(
self.options,
**{'ori_ext': source_extension,
'ori_folder': source_folder,
'out_ext': conversion_data['extension'],
'out_folder': destination})
**{
'ori_ext': source_extension,
'ori_folder': source_folder,
'out_ext': conversion_data['extension'],
'out_folder': destination,
},
)

folder = os.fsencode(source_folder)
for file in os.listdir(folder):
Expand All @@ -71,25 +80,29 @@ def get_user_input(self, conversion_data):
if source_ext == '.{}'.format(source_extension):
source_paths.append(source_path)
output_path = '{}{}.{}'.format(
destination, source_name, conversion_data['extension'])
destination, source_name, conversion_data['extension']
)
output_paths.append(output_path)

# single file flow
else:
# do not show confirmation message if the option is enabled
confirmator(
self.options,
**{'ori_path': source_path,
'out_ext': conversion_data['extension'],
'out_folder': destination})
**{
'ori_path': source_path,
'out_ext': conversion_data['extension'],
'out_folder': destination,
},
)

source_paths = [source_path]
output_paths = ['{}{}.{}'.format(
destination, source_name, conversion_data['extension'])]
output_paths = [
'{}{}.{}'.format(destination, source_name, conversion_data['extension'])
]

return source_paths, output_paths, conversion_data['params']

def run(self):
"""All commands must implement this method."""
raise NotImplementedError(
'You must implement the run() method yourself!')
raise NotImplementedError('You must implement the run() method yourself!')
21 changes: 9 additions & 12 deletions convert/commands/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@ def __init__(self, options, *args, **kwargs):
'vcodec': 'libx264',
'crf': 20,
'acodec': 'aac',
'strict': 'experimental'
}
'strict': 'experimental',
},
},
2: {
'option_text': 'Convert to .mov',
Expand All @@ -28,24 +28,20 @@ def __init__(self, options, *args, **kwargs):
'crf': 20,
'acodec': 'aac',
'f': 'mov',
}
},
},
3: {
'option_text': 'Convert to .flv',
'extension': 'flv',
'params': {
'vcodec': 'flv1',
'acodec': 'aac',
'strict': 'experimental'
}
'params': {'vcodec': 'flv1', 'acodec': 'aac', 'strict': 'experimental'},
},
4: {
'option_text': 'Convert to .mkv',
'extension': 'mkv',
'params': {
'vcodec': 'copy',
'acodec': 'copy',
}
},
},
5: {
'option_text': 'Extract audio (output in .mp3)',
Expand All @@ -55,15 +51,16 @@ def __init__(self, options, *args, **kwargs):
'ac': '2',
'ab': '320k',
'f': 'mp3',
}
}
},
},
}

def run(self):
"""Run the Video command."""
chosen_option = let_user_pick(self.conversion_map)
source_paths, output_paths, params = self.get_user_input(
self.conversion_map[chosen_option])
self.conversion_map[chosen_option]
)
for (source_path, output_path) in list(zip(source_paths, output_paths)):
run_ffmpeg(source_path, output_path, params, self.options)
prmsg('completed')
Loading

0 comments on commit 8aaa18d

Please sign in to comment.