kodi-rename 0.0.4__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Duncan Fraser
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: kodi-rename
3
+ Version: 0.0.4
4
+ Author-email: Duncan Fraser <dfraser@thedrunkencoder.uk>
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://gitlab.com/thedrunkencoder/kodi-rename
7
+ Project-URL: Repository, https://gitlab.com/thedrunkencoder/kodi-rename
8
+ Project-URL: Issues, https://gitlab.com/thedrunkencoder/kodi-rename/-/issues
9
+ Project-URL: Changelog, https://gitlab.com/thedrunkencoder/kodi-rename/-/blob/main/CHANGELOG.md?ref_type=heads
10
+ Project-URL: Documentation, https://gitlab.com/thedrunkencoder/kodi-rename
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Natural Language :: English
13
+ Classifier: Topic :: Utilities
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: requests==2.32.3
19
+ Dynamic: license-file
20
+
21
+ # Kodi Rename
22
+
23
+ ## todo
24
+ - configure logging
25
+ - implement a simple cache for src.parentPath in clean
@@ -0,0 +1,5 @@
1
+ # Kodi Rename
2
+
3
+ ## todo
4
+ - configure logging
5
+ - implement a simple cache for src.parentPath in clean
@@ -0,0 +1,38 @@
1
+ # -*- coding: utf-8 -*-
2
+ #################################################################################
3
+ # MIT License
4
+ #
5
+ # Copyright (c) 2025 Duncan Fraser
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #################################################################################
25
+ #
26
+ # File : __init__.py
27
+ #
28
+ # Author : Duncan Fraser <dfraser@thedrunkencoder.uk>
29
+ #
30
+ # Description :
31
+ #
32
+ #################################################################################
33
+
34
+ from .kodiRename import main # noqa: F401
35
+
36
+ from . import _version
37
+
38
+ __version__ = _version.get_versions()["version"]
@@ -0,0 +1,21 @@
1
+
2
+ # This file was generated by 'versioneer.py' (0.29) from
3
+ # revision-control system data, or from the parent directory name of an
4
+ # unpacked source archive. Distribution tarballs contain a pre-generated copy
5
+ # of this file.
6
+
7
+ import json
8
+
9
+ version_json = '''
10
+ {
11
+ "date": "2025-05-18T18:10:00+0100",
12
+ "dirty": false,
13
+ "error": null,
14
+ "full-revisionid": "d07f4f5a2215392d027c79e9fe97e24104a7ff6b",
15
+ "version": "0.0.4"
16
+ }
17
+ ''' # END VERSION_JSON
18
+
19
+
20
+ def get_versions():
21
+ return json.loads(version_json)
@@ -0,0 +1,273 @@
1
+ # -*- coding: utf-8 -*-
2
+ #################################################################################
3
+ # MIT License
4
+ #
5
+ # Copyright (c) 2025 Duncan Fraser
6
+ #
7
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ # of this software and associated documentation files (the "Software"), to deal
9
+ # in the Software without restriction, including without limitation the rights
10
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ # copies of the Software, and to permit persons to whom the Software is
12
+ # furnished to do so, subject to the following conditions:
13
+ #
14
+ # The above copyright notice and this permission notice shall be included in all
15
+ # copies or substantial portions of the Software.
16
+ #
17
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ # SOFTWARE.
24
+ #################################################################################
25
+ #
26
+ # File : kodiRename.py
27
+ #
28
+ # Author : Duncan Fraser <dfraser@thedrunkencoder.uk>
29
+ #
30
+ # Description :
31
+ #
32
+ #################################################################################
33
+ import logging
34
+ import os
35
+ import sys
36
+ from argparse import ArgumentParser
37
+ from typing import Final, Optional
38
+
39
+ from alive_progress import alive_bar
40
+
41
+ from . import collector, config, process
42
+
43
+ DEFAULT_CONFIG_FILE: Final = "config.ini"
44
+ OUTPUT_MOVIES: Final = "movie.bin"
45
+ OUTPUT_TV: Final = "tv.bin"
46
+
47
+
48
+ def collectConfig(config_path: str = DEFAULT_CONFIG_FILE) -> config.ConfigSpec:
49
+ config_data = config.ConfigSpec()
50
+
51
+ if not os.path.exists(config_path):
52
+ return config_data
53
+
54
+ with open(config_path, "rb") as conf_file:
55
+ config_data = config.parseConfig(configIO=conf_file)
56
+
57
+ return config_data
58
+
59
+
60
+ def configLogger(
61
+ level: str, log_file: Optional[str] = None, log_std: bool = False
62
+ ) -> logging.Logger:
63
+
64
+ logger = logging.getLogger(__name__)
65
+ form = logging.Formatter(
66
+ "%(asctime)s %(levelname)s [%(module)s:%(funcName)s] %(message)s",
67
+ datefmt="%Y-%m-%d %H:%M:%S",
68
+ )
69
+
70
+ log_levels = {
71
+ "debug": logging.DEBUG,
72
+ "info": logging.INFO,
73
+ "warning": logging.WARNING,
74
+ "error": logging.ERROR,
75
+ "critical": logging.CRITICAL,
76
+ }
77
+
78
+ if level not in log_levels:
79
+ raise ValueError("Undefined Level {0}".format(level))
80
+
81
+ logger.setLevel(log_levels[level])
82
+
83
+ if log_file:
84
+ fh = logging.FileHandler(filename=log_file, mode="a")
85
+ fh.setFormatter(form)
86
+ logger.addHandler(fh)
87
+
88
+ if log_std:
89
+ sh = logging.StreamHandler(sys.stdout)
90
+ sh.setFormatter(form)
91
+ logger.addHandler(sh)
92
+
93
+ return logger
94
+
95
+
96
+ def parseArgs(config_data: config.ConfigSpec):
97
+ desc_str = ""
98
+ parser = ArgumentParser(prog="kodiRename", description=desc_str)
99
+
100
+ parser.add_argument("--config", "-c", required=False, default=DEFAULT_CONFIG_FILE)
101
+ parser.add_argument(
102
+ "--debug",
103
+ "-d",
104
+ action="store",
105
+ default="info",
106
+ choices=["debug", "info", "warning", "error", "critical"],
107
+ required=False,
108
+ )
109
+ parser.add_argument("--logfile", action="store", required=False, metavar="xxx.log")
110
+ parser.add_argument(
111
+ "--quiet", "-q", action="store_true", required=False, default=False
112
+ )
113
+
114
+ subparsers = parser.add_subparsers(dest="command", required=True)
115
+
116
+ init = subparsers.add_parser("init", help="Initialize config file") # noqa: F841
117
+ collection = subparsers.add_parser( # noqa: F841
118
+ "collect", help="Collect Information"
119
+ )
120
+ rename = subparsers.add_parser("rename", help="Use Information")
121
+ clean = subparsers.add_parser("clean", help="Print Information")
122
+
123
+ rename.add_argument("--dryRun", required=False, action="store_true")
124
+ clean.add_argument("--dryRun", required=False, action="store_true")
125
+
126
+ args = parser.parse_args()
127
+
128
+ if args.config:
129
+ config_data = collectConfig(args.config)
130
+
131
+ if args.logfile:
132
+ config_data.general.logFile = args.logfile
133
+
134
+ return (args, config_data)
135
+
136
+
137
+ def init(config_path: str = DEFAULT_CONFIG_FILE) -> int:
138
+ with open(config_path, "w") as conf_file:
139
+ config.writeDefaultConfig(configIO=conf_file)
140
+ return 0
141
+
142
+
143
+ def collect(config_data: config.ConfigSpec) -> int:
144
+ movie_info = collector.getMovieInfo(config=config_data)
145
+ tv_info = collector.getTvInfo(config=config_data)
146
+
147
+ if not os.path.isdir(config_data.general.dataDirectory):
148
+ os.makedirs(config_data.general.dataDirectory, exist_ok=True)
149
+
150
+ with open(
151
+ os.path.join(config_data.general.dataDirectory, OUTPUT_MOVIES), "wb"
152
+ ) as movie_file:
153
+ collector.serializeMovieInfo(pickleIO=movie_file, movieInfo=movie_info)
154
+
155
+ with open(
156
+ os.path.join(config_data.general.dataDirectory, OUTPUT_TV), "wb"
157
+ ) as tv_file:
158
+ collector.serializeTVInfo(pickleIO=tv_file, tvInfo=tv_info)
159
+
160
+ return 0
161
+
162
+
163
+ def rename(config_data: config.ConfigSpec, dry_run: bool = False) -> int:
164
+ with open(
165
+ os.path.join(config_data.general.dataDirectory, OUTPUT_MOVIES), "rb"
166
+ ) as movie_file:
167
+ movie_info = collector.deserializeMovieInfo(pickleIO=movie_file)
168
+
169
+ with open(
170
+ os.path.join(config_data.general.dataDirectory, OUTPUT_TV), "rb"
171
+ ) as tv_file:
172
+ tv_info = collector.deserializeTVInfo(pickleIO=tv_file)
173
+
174
+ movie_rename = process.collectMovieRename(config=config_data, movie_list=movie_info)
175
+ tv_rename = process.collectTvRename(config=config_data, tv_info=tv_info)
176
+
177
+ with alive_bar(len(movie_rename), title="Movie Rename") as progress:
178
+ for movie in movie_rename:
179
+ config_data.log.info(
180
+ "{2} Movie : {0} --> {1}".format(
181
+ movie.src.path,
182
+ movie.dest.path,
183
+ "Moving" if config_data.general.mode == "move" else "Copying",
184
+ )
185
+ )
186
+ process.performRenameOperation(
187
+ config=config_data, data=movie, dry_run=dry_run
188
+ )
189
+ progress()
190
+
191
+ with alive_bar(len(tv_rename), title="TV Rename ") as progress:
192
+ for tv in tv_rename:
193
+ config_data.log.info(
194
+ "{2} Episode : {0} --> {1}".format(
195
+ tv.src.path,
196
+ tv.dest.path,
197
+ "Moving" if config_data.general.mode == "move" else "Copying",
198
+ )
199
+ )
200
+
201
+ process.performRenameOperation(config=config_data, data=tv, dry_run=dry_run)
202
+ progress()
203
+
204
+ return 0
205
+
206
+
207
+ def clean(config_data: config.ConfigSpec, dry_run: bool = False) -> int:
208
+ with open(
209
+ os.path.join(config_data.general.dataDirectory, OUTPUT_MOVIES), "rb"
210
+ ) as movie_file:
211
+ movie_info = collector.deserializeMovieInfo(pickleIO=movie_file)
212
+
213
+ with open(
214
+ os.path.join(config_data.general.dataDirectory, OUTPUT_TV), "rb"
215
+ ) as tv_file:
216
+ tv_info = collector.deserializeTVInfo(pickleIO=tv_file)
217
+
218
+ movie_rename = process.collectMovieRename(config=config_data, movie_list=movie_info)
219
+ tv_rename = process.collectTvRename(config=config_data, tv_info=tv_info)
220
+
221
+ with alive_bar(len(movie_rename), title="Movie Clean") as progress:
222
+ for movie in movie_rename:
223
+ config_data.log.info(
224
+ "Deleting Movie Directory : {0}".format(movie.src.parentPath)
225
+ )
226
+ process.performCleanDirectory(
227
+ config=config_data, data=movie, dry_run=dry_run
228
+ )
229
+ progress()
230
+
231
+ with alive_bar(len(tv_rename), title="TV Clean ") as progress:
232
+ for tv in tv_rename:
233
+ config_data.log.info(
234
+ "Deleting TV Directory : {0}".format(tv.src.parentPath)
235
+ )
236
+ process.performCleanDirectory(config=config_data, data=tv, dry_run=dry_run)
237
+ progress()
238
+ return 0
239
+
240
+
241
+ def main() -> int:
242
+ config_data = collectConfig(DEFAULT_CONFIG_FILE)
243
+
244
+ args, config_data = parseArgs(config_data=config_data)
245
+
246
+ if not os.path.isdir(config_data.general.dataDirectory):
247
+ os.makedirs(config_data.general.dataDirectory, exist_ok=True)
248
+
249
+ if not os.path.isdir(os.path.dirname(config_data.general.logFile)):
250
+ if os.path.dirname(config_data.general.logFile) != "":
251
+ os.makedirs(os.path.dirname(config_data.general.logFile), exist_ok=True)
252
+
253
+ logger = configLogger(
254
+ level=args.debug, log_file=config_data.general.logFile, log_std=(not args.quiet)
255
+ )
256
+ config_data.log = logger
257
+
258
+ status = 0
259
+
260
+ if args.command == "init":
261
+ status = init(args.config)
262
+ elif args.command == "collect":
263
+ status = collect(config_data=config_data)
264
+ elif args.command == "rename":
265
+ status = rename(config_data=config_data, dry_run=args.dryRun)
266
+ elif args.command == "clean":
267
+ status = clean(config_data=config_data, dry_run=args.dryRun)
268
+
269
+ return status
270
+
271
+
272
+ if __name__ == "__main__":
273
+ sys.exit(main())
File without changes
@@ -0,0 +1,25 @@
1
+ Metadata-Version: 2.4
2
+ Name: kodi-rename
3
+ Version: 0.0.4
4
+ Author-email: Duncan Fraser <dfraser@thedrunkencoder.uk>
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://gitlab.com/thedrunkencoder/kodi-rename
7
+ Project-URL: Repository, https://gitlab.com/thedrunkencoder/kodi-rename
8
+ Project-URL: Issues, https://gitlab.com/thedrunkencoder/kodi-rename/-/issues
9
+ Project-URL: Changelog, https://gitlab.com/thedrunkencoder/kodi-rename/-/blob/main/CHANGELOG.md?ref_type=heads
10
+ Project-URL: Documentation, https://gitlab.com/thedrunkencoder/kodi-rename
11
+ Classifier: Development Status :: 3 - Alpha
12
+ Classifier: Natural Language :: English
13
+ Classifier: Topic :: Utilities
14
+ Classifier: Typing :: Typed
15
+ Requires-Python: >=3.11
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: requests==2.32.3
19
+ Dynamic: license-file
20
+
21
+ # Kodi Rename
22
+
23
+ ## todo
24
+ - configure logging
25
+ - implement a simple cache for src.parentPath in clean
@@ -0,0 +1,15 @@
1
+ LICENSE
2
+ README.md
3
+ pyproject.toml
4
+ setup.cfg
5
+ setup.py
6
+ kodiRename/__init__.py
7
+ kodiRename/_version.py
8
+ kodiRename/kodiRename.py
9
+ kodiRename/py.typed
10
+ kodi_rename.egg-info/PKG-INFO
11
+ kodi_rename.egg-info/SOURCES.txt
12
+ kodi_rename.egg-info/dependency_links.txt
13
+ kodi_rename.egg-info/entry_points.txt
14
+ kodi_rename.egg-info/requires.txt
15
+ kodi_rename.egg-info/top_level.txt
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ kodiRename = kodiRename:main
@@ -0,0 +1 @@
1
+ requests==2.32.3
@@ -0,0 +1 @@
1
+ kodiRename
@@ -0,0 +1,50 @@
1
+ [project]
2
+ name = "kodi-rename"
3
+ description = ""
4
+ dynamic = ["version"]
5
+ readme = {file = "README.md", content-type = "text/markdown"}
6
+ authors = [
7
+ { name="Duncan Fraser", email="dfraser@thedrunkencoder.uk" }
8
+ ]
9
+ requires-python = ">=3.11"
10
+ license = "MIT"
11
+ license-files = ["LICENSE"]
12
+ classifiers = [
13
+ "Development Status :: 3 - Alpha",
14
+
15
+ "Natural Language :: English",
16
+ "Topic :: Utilities",
17
+ "Typing :: Typed"
18
+ ]
19
+
20
+ dependencies = [
21
+ "requests==2.32.3"
22
+ ]
23
+
24
+ [project.scripts]
25
+ kodiRename = "kodiRename:main"
26
+
27
+ [project.urls]
28
+ Homepage="https://gitlab.com/thedrunkencoder/kodi-rename"
29
+ Repository="https://gitlab.com/thedrunkencoder/kodi-rename"
30
+ Issues="https://gitlab.com/thedrunkencoder/kodi-rename/-/issues"
31
+ Changelog="https://gitlab.com/thedrunkencoder/kodi-rename/-/blob/main/CHANGELOG.md?ref_type=heads"
32
+ Documentation="https://gitlab.com/thedrunkencoder/kodi-rename"
33
+
34
+ [build-system]
35
+ requires = ["setuptools", "versioneer[toml]"]
36
+ build-backend = "setuptools.build_meta"
37
+
38
+ [[tool.mypy.overrides]]
39
+ module = ["alive_progress.*"]
40
+ follow_untyped_imports = true
41
+
42
+ [tool.isort]
43
+ profile = "black"
44
+
45
+ [tool.versioneer]
46
+ VCS = "git"
47
+ style = "pep440-branch"
48
+ versionfile_source = "kodiRename/_version.py"
49
+ versionfile_build = "kodiRename/_version.py"
50
+ tag_prefix = "v"
@@ -0,0 +1,8 @@
1
+ [flake8]
2
+ extend-ignore = E501
3
+ exclude = kodiRename/_version.py
4
+
5
+ [egg_info]
6
+ tag_build =
7
+ tag_date = 0
8
+
@@ -0,0 +1,10 @@
1
+ # -*- coding: utf-8 -*-
2
+ import versioneer
3
+ from setuptools import setup
4
+
5
+ setup(
6
+ packages=["kodiRename"],
7
+ package_data={"kodiRename": ["py.typed"]},
8
+ version=versioneer.get_version(),
9
+ cmdclass=versioneer.get_cmdclass(),
10
+ )