Skip to content

Commit

Permalink
Fix running extra scripts in Python 3. Fixes pymedusa#6395 (pymedusa#…
Browse files Browse the repository at this point in the history
…6428)

* Fix running extra scripts in Python 3. Fixes pymedusa#6395

* flake8

* Update CHANGELOG.md
  • Loading branch information
medariox authored and Thilas committed Jun 5, 2019
1 parent b7a777a commit 2c64884
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 25 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
#### Improvements

#### Fixes
- Fixed lists not being saved when used with comma separated items ([#6428](https://github.com/pymedusa/Medusa/pull/6428))
- Fixed extra scripts running with Python 3 ([#6428](https://github.com/pymedusa/Medusa/pull/6428))

## 0.3.1 (2019-03-20)

Expand Down
26 changes: 6 additions & 20 deletions medusa/post_processor.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
import rarfile
from rarfile import Error as RarError, NeedFirstVolume

from six import text_type, viewitems
from six import viewitems

# Most common language tags from IETF
# https://datahub.io/core/language-codes#resource-ietf-language-tags
Expand Down Expand Up @@ -947,34 +947,20 @@ def _run_extra_scripts(self, ep_obj):
if not app.EXTRA_SCRIPTS:
return

def _attempt_to_encode(item, _encoding):
if isinstance(item, text_type):
try:
item = item.encode(_encoding)
except UnicodeEncodeError:
pass # ignore it
finally:
return item

encoding = app.SYS_ENCODING

file_path = _attempt_to_encode(self.file_path, encoding)
ep_location = _attempt_to_encode(ep_obj.location, encoding)
ep_location = ep_obj.location
file_path = self.file_path
indexer_id = str(ep_obj.series.indexerid)
season = str(ep_obj.season)
episode = str(ep_obj.episode)
airdate = str(ep_obj.airdate)

for cur_script_name in app.EXTRA_SCRIPTS:
cur_script_name = _attempt_to_encode(cur_script_name, encoding)

# generate a safe command line string to execute the script and provide all the parameters
script_cmd = [piece for piece in re.split(r'(\'.*?\'|".*?"| )', cur_script_name) if piece.strip()]
script_cmd[0] = os.path.abspath(script_cmd[0])
self.log(u'Absolute path to script: {0}'.format(script_cmd[0]), logger.DEBUG)
script_cmd = [piece for piece in cur_script_name.split(' ') if piece.strip()]
self.log(u'Running extra script: {0}'.format(cur_script_name), logger.INFO)

script_cmd += [ep_location, file_path, indexer_id, season, episode, airdate]

# use subprocess to run the command and capture output
self.log(u'Executing command: {0}'.format(script_cmd))
try:
Expand All @@ -990,7 +976,7 @@ def _attempt_to_encode(item, _encoding):
self.log(u'Script result: {0}'.format(out), logger.DEBUG)

except Exception as error:
self.log(u'Unable to run extra_script: {0!r}'.format(error))
self.log(u'Unable to run extra script: {0!r}'.format(error))

def flag_kodi_clean_library(self):
"""Set flag to clean Kodi's library if Kodi is enabled."""
Expand Down
5 changes: 2 additions & 3 deletions medusa/subtitles.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import logging
import operator
import os
import re
import subprocess
import time
from builtins import object
Expand Down Expand Up @@ -1110,7 +1109,7 @@ def run_subs_scripts(video_path, scripts, *args):
:type args: list of str
"""
for script_name in scripts:
script_cmd = [piece for piece in re.split("( |\\\".*?\\\"|'.*?')", script_name) if piece.strip()]
script_cmd = [piece for piece in script_name.split(' ') if piece.strip()]
script_cmd.extend(str(arg) for arg in args)

logger.info(u'Running subtitle %s-script: %s', 'extra' if len(args) > 1 else 'pre', script_name)
Expand All @@ -1124,6 +1123,6 @@ def run_subs_scripts(video_path, scripts, *args):
logger.debug(u'Script result: %s', out)

except Exception as error:
logger.info(u'Unable to run subtitles script: %s', ex(error))
logger.info(u'Unable to run subtitles script: %r', ex(error))

invalidate_video_cache(video_path)
1 change: 1 addition & 0 deletions themes-default/slim/src/components/helpers/select-list.vue
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ export default {
this.addItem(value.trim());
}
}));
this.$emit('change', this.editItems);
} else {
this.csv = this.editItems.map(item => item.value).join(', ');
}
Expand Down
2 changes: 1 addition & 1 deletion themes/dark/assets/js/medusa-runtime.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 2c64884

Please sign in to comment.