Skip to content

Commit

Permalink
Added better settings upgrading! Favorites carry over now.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomasedv committed Nov 23, 2018
1 parent 2e721e3 commit 057fc44
Showing 1 changed file with 23 additions and 6 deletions.
29 changes: 23 additions & 6 deletions utils/utilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ def path_shortener(full_path: str):
times += 1
if times == 3 and full_path.count('/') >= 4:
short_path = ''.join([full_path[:full_path.find('/')+1], '...', full_path[split:]])
print(short_path)
# print(short_path)
break
elif times == 3:
split = full_path.find('/', split)
Expand Down Expand Up @@ -102,7 +102,8 @@ def __init__(self, settings, profiles, filehandler=None):
if not profiles:
profiles = old_profiles
else:
profiles = old_profiles.update(profiles)
old_profiles.update(profiles)
profiles = copy.deepcopy(old_profiles)
try:
self._userdefined = settings['default']
self._parameters = settings['parameters']
Expand All @@ -116,8 +117,8 @@ def __init__(self, settings, profiles, filehandler=None):

self._validate_settings()

print(self._profiles)
print(self.get_settings_data)
# print(self._profiles)
# print(self.get_settings_data)

def __enter__(self):
return self._parameters
Expand Down Expand Up @@ -211,13 +212,16 @@ def change_profile(self, profile):

@staticmethod
def _upgrade_settings(old_settings):
print('Upgrading settings!!')
# print('Upgrading settings!!')
settings = {}
try:
settings['default'] = copy.deepcopy(old_settings['Other stuff'])
if old_settings['Favorites']:
settings['default']['favorites'] = copy.deepcopy(old_settings['Favorites'])
settings['parameters'] = copy.deepcopy(old_settings['Settings'])
except KeyError:
pass

try:
profiles = copy.deepcopy(old_settings['Profiles'])
except KeyError:
Expand All @@ -243,6 +247,9 @@ def _validate_settings(self):
'state',
'tooltip']

for setting in {i for i in base_settings['parameters'] if i not in self._parameters}:
self._parameters[setting] = copy.deepcopy(base_settings['parameters'][setting])

for setting, option in self._parameters.items():
# setting: The name of the setting, like "Ignore errors"
# option: The dict which contains the base keys.
Expand Down Expand Up @@ -303,7 +310,6 @@ def _validate_settings(self):
self._filehandler.save_settings(self.get_settings_data)



stylesheet = f"""
QWidget {{
background-color: #484848;
Expand Down Expand Up @@ -877,6 +883,17 @@ def _validate_settings(self):
"title like \"Coldplay - Paradise\".\nExample"
"(regex):\n\"(?P<artist>.+?) - (?P<title>.+)\""
}
base_settings['parameters']['Merge output format'] = {
"active option": 0,
"command": "--merge-output-format {}",
"dependency": None,
"options": ["mp4", "mkv", "ogg", "webm", "flv"],
"state": False,
"tooltip": "If a merge is required (e.g. bestvideo+bestaudio),"
"\noutput to given container format."
"\nOne of mkv, mp4, ogg, webm, flv."
"\nIgnored if no merge is required"
}


def get_base_settings() -> dict:
Expand Down

0 comments on commit 057fc44

Please sign in to comment.