Repository navigation
Expand file tree
/
Copy pathmumc.py
More file actions
executable file
·190 lines (143 loc) · 7.31 KB
/
Copy pathmumc.py
File metadata and controls
executable file
·190 lines (143 loc) · 7.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
#!/usr/bin/env python3
import sys
import copy
from pathlib import Path
from mumc_modules.mumc_init import initialize_mumc,getIsAnyMediaEnabled,override_consoleOutputs_onDEBUG
from mumc_modules.mumc_parse_commands import parse_command_line_options
from mumc_modules.mumc_config_import import importConfig
from mumc_modules.mumc_config_builder import edit_configuration_file
from mumc_modules.mumc_post_process import init_postProcessing
from mumc_modules.mumc_console_info import print_informational_header,print_starting_header,print_cache_stats,print_footer_information,print_all_media_disabled,cache_data_to_debug,print_configuration_yaml,override_media_manager_enabled_states
from mumc_modules.mumc_get_media import init_getMedia
from mumc_modules.mumc_sort import sortDeleteLists
from mumc_modules.mumc_paths_files import delete_debug_log,get_default_config_path
from mumc_modules.mumc_output import open_and_return_file
from mumc_modules.mumc_folder_cleanup import season_series_folder_cleanup
from mumc_modules.mumc_config_merge import merge_configurations
from mumc_modules.mumc_get_folders import populate_config_with_subfolder_ids
from mumc_modules.mumc_delete import print_and_delete_items
from mumc_modules.mumc_data_checks import data_checker,convertLegacyMediaManagers,convertLegacyMediaManagerSettings,convertLegacyMediaManagerLengths
from mumc_modules.mumc_yaml_check import cfgCheckYAML,pre_cfgCheckYAML
from mumc_modules.mumc_argenv_check import cfgCheckARGENV
#from memory_profiler import profile
#@profile
def MUMC():
#inital dictionary setup; get cwd; get mumc.py full path and filename if changed
init_dict=initialize_mumc(Path('.').parent.resolve(),Path(__file__))
#parse command line options
cmdopt_dict=parse_command_line_options(init_dict)
#remove old DEBUG if it exists
delete_debug_log(init_dict)
#fully check argv commandline options (and environmental variables) are what we expect them to be
argvCfgChecker=data_checker(cmdopt_dict['argv'])
cmdopt_dict['argv']=cfgCheckARGENV(argvCfgChecker)
#update the argv created during initialization
init_dict['argv']=cmdopt_dict['argv']
#import config file
cfg,init_dict=importConfig(init_dict,cmdopt_dict)
#get and pre-check user defined values are what we expect them to be
pre_cfgCheckYAML(cfg,init_dict)
#must be done in this order
#convert legacy admin_settings > media_managers > *arr > {} into admin_settings > media_managers > *arr > []
cfg=convertLegacyMediaManagers(cfg)
#get and fully check user defined config values are what we expect them to be
userCfgChecker=data_checker(cfg)
cfg=cfgCheckYAML(userCfgChecker)
#look for missing subfolder Ids and add them
cfg=populate_config_with_subfolder_ids(cfg,init_dict)
#remember original config for when user wants to update existing config file
cfg_orig=copy.deepcopy(cfg)
#convert legacy advanced_settings > *arr > media_type > {} into advanced_settings > *arr > media_type > []
cfg=convertLegacyMediaManagerSettings(cfg)
#match length of advanced_settings > *arr > media_type > [] to length of admin_settings > media_managers > *arr > []
cfg=convertLegacyMediaManagerLengths(cfg)
#create default config file
default_config=open_and_return_file(get_default_config_path(init_dict['MUMC_file_path']))
#copy over path info for use later
default_config['debug_file_path']=init_dict['debug_file_path']
default_config['debug_file_name_log']=init_dict['debug_file_name_log']
#merge user config into default config
cfg=merge_configurations(default_config,cfg)
if (cfg['DEBUG']):
#print config when DEBUG >= 1
print_configuration_yaml(cfg,init_dict)
#get and fully check user defined + default config values are what we expect them to be
#cfgChecker=data_checker(cfg)
#cfg=cfgCheckYAML(cfgChecker)
#merge cfg and init_dict; goal is to preserve cfg's structure
init_dict.update(copy.deepcopy(cfg))
cfg=copy.deepcopy(init_dict)
#update cache variables with values specified in the config file
cfg['cached_data'].updateCacheVariables(cfg)
#check if user wants to update the existing config file
if ((cfg['advanced_settings']['UPDATE_CONFIG']) or (('-config_updater' in cmdopt_dict['argv']) and (cmdopt_dict['argv']['-config_updater']))):
#check if user intentionally wants to update the config
edit_configuration_file(cfg,cfg_orig)
if (cfg['DEBUG']):
#show cache stats
print_cache_stats(cfg)
if (cfg['DEBUG'] == 255):
#show cache data (only when DEBUG == 255
cache_data_to_debug(cfg)
#clear cache
cfg['cached_data'].wipeCache()
return
#check for media_manager info; override if None or ''
cfg=override_media_manager_enabled_states(cfg)
#output details about MUMC, Emby/Jellyfin, and server
print_informational_header(cfg)
#when debug is enabled force all console outputs
cfg=override_consoleOutputs_onDEBUG(cfg)
#output the starting header
print_starting_header(cfg)
#before running the main part of MUMC, determine if at least one media type is enabled to be monitored
cfg=getIsAnyMediaEnabled(cfg)
#check if at least one media type is enabled ot be monitored
#if not; print message to console
#if it is; proceed and process media items
if (cfg['all_media_disabled']):
#output message letting user know none of the media is enabled to be monitored
print_all_media_disabled(cfg)
deleteItems=[]
else:
#prepare for the main event; return dictionaries of media items per monitored user
cfg=init_getMedia(cfg)
#prepare for post processing; return list of media items to be deleted
deleteItems_dict=init_postProcessing(cfg)
#sort lists of items to be deleted into a single list
deleteItems=sortDeleteLists(deleteItems_dict)
#output to console the items to be deleted; then delete media items
print_and_delete_items(deleteItems,cfg)
#cleanup empty season and series folders
season_series_folder_cleanup(deleteItems,cfg)
if (cfg['DEBUG']):
#show cache stats
print_cache_stats(cfg)
if (cfg['DEBUG'] == 255):
#show cache data (only when DEBUG == 255)
cache_data_to_debug(cfg)
#show footer info
print_footer_information(cfg)
#clear cache
cfg['cached_data'].wipeCache()
return
############# START OF MUMC #############
if (__name__ == "__main__"):
# :::: :::: ::: ::: :::: ::::: ::::::::
# +:+:+: :+:+:+ :+: :+: +:+:+: :+:+:+ :+: :+:
# +:+ +:+:+ +:+ +:+ +:+ +:+ +:+:+ +:+ +:+
# +#+ +:+ +#+ +#+ +:+ +#+ +:+ +#+ +#+
# +#+ +#+ +#+ +#+ +#+ +#+ +#+
# #+# #+# #+# #+# #+# #+# #+# #+#
# ### ### ######## ### ### ########
MUMC()
# #### #### ### ### #### ##### ########
# #+#+#+ +#+#+# #+# #+# #+#+#+ +#+#+# #+# #+#
# +#+ +#+#+ +#+ +#+ +#+ +#+ +#+#+ +#+ +#+
# +#+ +:+ +#+ +#+ +:+ +#+ +:+ +#+ +#+
# +:+ +:+ +:+ +:+ +:+ +:+ +:+
# :+: :+: :+: :+: :+: :+: :+: :+:
# ::: ::: :::::::: ::: ::: ::::::::
#Exit Gracefully
sys.exit(0)
############# END OF MUMC #############