bazarrbulksync 0.0.0__py3-none-any.whl

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,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: bazarrbulksync
3
+ Version: 0.0.0
4
+ Summary: An optimized command-line tool for bulk syncing media subtitles in Bazarr
5
+ Home-page: https://github.com/BrianWeiHaoMa/bazarrbulksync
6
+ Author: Brian Wei Hao Ma
7
+ Author-email: brianmaytc@gmail.com
8
+ License: MIT
9
+ Keywords: bazarr,subtitles,subtitle-sync,subtitle-synchronization,media,video,movies,tv,cli,command-line,automation,bulk,sync,media-server,plex,emby,jellyfin,sonarr,radarr,streaming
10
+ Classifier: Development Status :: 4 - Beta
11
+ Classifier: License :: OSI Approved :: MIT License
12
+ Classifier: Operating System :: OS Independent
13
+ Classifier: Topic :: Utilities
14
+ Classifier: Topic :: Multimedia :: Video
15
+ Classifier: Intended Audience :: System Administrators
16
+ Classifier: Intended Audience :: End Users/Desktop
17
+ Classifier: Intended Audience :: Information Technology
18
+ Classifier: Programming Language :: Python :: 3.10
19
+ Classifier: Programming Language :: Python :: 3.11
20
+ Classifier: Programming Language :: Python :: 3.12
21
+ Classifier: Programming Language :: Python :: 3.13
22
+ Classifier: Programming Language :: Python :: 3 :: Only
23
+ Requires-Python: >=3.10
24
+ Description-Content-Type: text/markdown
25
+ License-File: LICENSE
26
+ Requires-Dist: PyYAML<7.0.0,>=6.0.0
27
+ Requires-Dist: requests<3.0.0,>=2.32.0
28
+ Dynamic: author
29
+ Dynamic: author-email
30
+ Dynamic: classifier
31
+ Dynamic: description
32
+ Dynamic: description-content-type
33
+ Dynamic: home-page
34
+ Dynamic: keywords
35
+ Dynamic: license
36
+ Dynamic: license-file
37
+ Dynamic: requires-dist
38
+ Dynamic: requires-python
39
+ Dynamic: summary
40
+
41
+ # BazarrBulkSync
42
+ An optimized command-line tool for bulk syncing media subtitles in Bazarr.
43
+
44
+ ## Use Cases
45
+ - You want to sync all of your Bazarr media subtitles in one go. BazarrBulkSync allows you to do this with a single command.
46
+ - Your Bazarr collection is MASSIVE and you want to save RAM while syncing. BazarrBulkSync supports chunking to limit the amount of resources used during the sync.
47
+ - You want to bulk sync more than once. BazarrBulkSync supports ignoring recently synced subtitles to avoid redundant syncing, saving a significant amount of time and computational resources.
48
+ - You want to record the syncing process and know which subtitles were synced at what time. BazarrBulkSync supports logging to a file and/or outputting to the screen.
49
+
50
+ ## Installation and Usage
51
+ ### Local Python
52
+ Make sure you have Python installed on your machine. You can install Python from [python.org](https://www.python.org/downloads/).
53
+ BazarrBulkSync has been tested for Python versions 3.10, 3.11, 3.12, and 3.13.
54
+
55
+ In the working directory of your choice, do
56
+ ```
57
+ python -m venv .venv
58
+ source .venv/bin/activate # This is for Linux. On Windows use .venv\Scripts\activate instead
59
+ pip install bazarrbulksync
60
+ ```
61
+
62
+ Each time you run the command-line tool, make sure that the virtual environment is activated (by using `source .venv/bin/activate` or `.venv\Scripts\activate` in the same working directory).
63
+
64
+ You can now run BazarrBulkSync:
65
+ ```
66
+ bazarrbulksync --help
67
+ ```
68
+ You should create a [config file](#config-file-template) in the same working directory as the one where you want to run BazarrBulkSync.
69
+
70
+ ### Docker
71
+ Make sure you have Docker installed on your machine. You can install Docker from [docker.com](https://www.docker.com/).
72
+
73
+ Pull the official BazarrBulkSync image from DockerHub:
74
+ ```
75
+ docker pull wayhowma/bazarrbulksync:latest
76
+ ```
77
+
78
+ After replacing `/my_absolute_path` below with the directory path that you want to mount (this is the place you would like to store BazarrBulkSync's config file and log file), you can run BazarrBulkSync:
79
+ ```
80
+ docker run --rm -v /my_absolute_path:/app wayhowma/bazarrbulksync --help
81
+ ```
82
+ You should create a [config file](#config-file-template) in the mounted directory `/my_absolute_path`.
83
+
84
+ ### Config File Template
85
+ It is recommended to create the config file `bazarrbulksync_cli.yaml` in the same working directory as the one where you want to run BazarrBulkSync. This allows you to easily run BazarrBulkSync each time without need to respecify the parameters. The content of `bazarrbulksync_cli.yaml` should follow the template below.
86
+ ```yaml
87
+ # bazarrbulksync_cli.yaml
88
+
89
+ bazarr:
90
+ base_url: http://192.168.1.251:6767/ # replace this with your bazarr service url
91
+ api_key: asdai21g3isufykasgfs7iodftas9d8f # replace this with your bazarr API key
92
+
93
+ output_messages_to_screen: true # false if you don't want to see messages on the screen
94
+ log_messages_to_file: true # false if you don't want to log messages to a file
95
+ log_messages_file_path: ./bazarrbulksync.log # the file path to store the log messages
96
+
97
+ # These are values for controlling maximum API request payload sizes.
98
+ # If you are running out of ram, reducing these values may help
99
+ # especially if the number of movies/series in your bazarr is large.
100
+ max_movies_per_request: 25
101
+ max_series_per_request: 25
102
+
103
+ # The maximum number of retries for a failed API request.
104
+ max_request_retries: 3
105
+
106
+ # The maximum amount of time to wait (in seconds) for the bazarr server
107
+ # to respond before automatically failing a request.
108
+ request_timeout: 1600
109
+
110
+ # A request failure is when the same request fails max_request_retries times.
111
+ stop_on_request_failure: false # true if you want the program to stop on the first request failure
112
+
113
+ # These are additional optional parameters for the API when syncing subtitles.
114
+ original_format: null # Use original subtitles format from ["True", "False"]
115
+ max_offset_seconds: null # Maximum offset seconds to allow as a string ex. "300"
116
+ no_fix_framerate: null # Don't try to fix framerate from ["True", "False"]
117
+ gss: null # Use Golden-Section Search from ["True", "False"]
118
+ ```
119
+
120
+ ## Examples
121
+ ### Local Python
122
+ Assuming we use [this](#config-file-template) config file, we can run the below command to sync all movies. Note: you need to activate the virtual environment that you set up [earlier](#local-python) before running this command.
123
+ ```
124
+ bazarrbulksync --sync movies
125
+ ```
126
+
127
+ ```
128
+ 2025-09-28 00:15:24,289 | Bazarr Bulk Sync CLI Tool Arguments: Namespace(sync='movies', bazarr_base_url='http://192.168.1.251:6767/', bazarr_api_key='asdai21g3isufykasgfs7iodftas9d8f', output_messages_to_screen=True, log_messages_to_file=True, log_messages_file_path='./bazarrbulksync.log', max_movies_per_request=25, max_series_per_request=25, max_request_retries=1, request_timeout=1600, latest_to_sync='9999-12-31', original_format=None, max_offset_seconds=None, no_fix_framerate=None, gss=None, stop_on_request_failure=False)
129
+ 2025-09-28 00:15:24,291 | Syncing movies...
130
+ 2025-09-28 00:15:24,364 | Syncing /data/media/media/movies/5 Centimeters per Second (2007)/[Arid] 5 Centimeters per Second (BDRip 1920x1080 Hi10 FLAC) [FD8B6FF2].ja.srt (previous sync 2025-09-28 00:08:13)
131
+ 2025-09-28 00:15:28,332 | Finished syncing /data/media/media/movies/5 Centimeters per Second (2007)/[Arid] 5 Centimeters per Second (BDRip 1920x1080 Hi10 FLAC) [FD8B6FF2].ja.srt (newest sync 2025-09-28 00:15:28)
132
+ 2025-09-28 00:15:28,332 | Movies synced so far: 1
133
+ 2025-09-28 00:15:28,354 | Syncing /data/media/media/movies/Django Unchained (2012)/Django.Unchained.2012.1080p.BluRay.x264.YIFY.en.srt (previous sync 2025-09-28 00:08:32)
134
+ 2025-09-28 00:15:47,170 | Finished syncing /data/media/media/movies/Django Unchained (2012)/Django.Unchained.2012.1080p.BluRay.x264.YIFY.en.srt (newest sync 2025-09-28 00:15:47)
135
+ 2025-09-28 00:15:47,171 | Movies synced so far: 2
136
+ 2025-09-28 00:15:47,213 | Syncing /data/media/media/movies/KPop Demon Hunters (2025)/KPop.Demon.Hunters.2025.1080p.WEBRip.x264.AAC5.1-[YTS.MX].en.srt (previous sync 2025-09-28 00:01:43)
137
+ 2025-09-28 00:16:04,363 | Finished syncing /data/media/media/movies/KPop Demon Hunters (2025)/KPop.Demon.Hunters.2025.1080p.WEBRip.x264.AAC5.1-[YTS.MX].en.srt (newest sync 2025-09-28 00:16:04)
138
+ 2025-09-28 00:16:04,364 | Movies synced so far: 3
139
+ 2025-09-28 00:16:04,394 | Syncing /data/media/media/movies/Kung Fu Panda 3 (2016)/Kung.Fu.Panda.3.2016.1080p.BluRay.x264-[YTS.AG].en.srt (previous sync 2025-09-28 00:01:55)
140
+ 2025-09-28 00:16:15,712 | Finished syncing /data/media/media/movies/Kung Fu Panda 3 (2016)/Kung.Fu.Panda.3.2016.1080p.BluRay.x264-[YTS.AG].en.srt (newest sync 2025-09-28 00:16:15)
141
+ 2025-09-28 00:16:15,712 | Movies synced so far: 4
142
+ 2025-09-28 00:16:15,764 | Syncing /data/media/media/movies/Penguins of Madagascar (2014)/Penguins.of.Madagascar.2014.1080p.BluRay.x264.YIFY.en.srt (previous sync 2025-09-28 00:02:06)
143
+ 2025-09-28 00:16:26,659 | Finished syncing /data/media/media/movies/Penguins of Madagascar (2014)/Penguins.of.Madagascar.2014.1080p.BluRay.x264.YIFY.en.srt (newest sync 2025-09-28 00:16:26)
144
+ 2025-09-28 00:16:26,659 | Movies synced so far: 5
145
+ 2025-09-28 00:16:26,688 | Finished syncing movies. Total movies synced: 5
146
+ ```
147
+
148
+ ### Docker
149
+ Assuming we use [this](#config-file-template) config file, we can run the following command to sync all movies:
150
+ ```
151
+ docker run --rm -v /bazarrbulksync:/app wayhowma/bazarrbulksync:latest --sync movies
152
+ ```
153
+
154
+ ```
155
+ 2025-09-28 04:01:04,012 | Bazarr Bulk Sync CLI Tool Arguments: Namespace(sync='movies', bazarr_base_url='http://192.168.1.251:6767/', bazarr_api_key='asdai21g3isufykasgfs7iodftas9d8f', output_messages_to_screen=True, log_messages_to_file=True, log_messages_file_path='./bazarrbulksync.log', max_movies_per_request=25, max_series_per_request=25, max_request_retries=1, request_timeout=1600, latest_to_sync='9999-12-31', original_format=None, max_offset_seconds=None, no_fix_framerate=None, gss=None, stop_on_request_failure=False)
156
+ 2025-09-28 04:01:04,018 | Syncing movies...
157
+ 2025-09-28 04:01:04,060 | Syncing /data/media/media/movies/5 Centimeters per Second (2007)/[Arid] 5 Centimeters per Second (BDRip 1920x1080 Hi10 FLAC) [FD8B6FF2].ja.srt (previous sync 2025-09-27 23:57:21)
158
+ 2025-09-28 04:01:08,200 | Finished syncing /data/media/media/movies/5 Centimeters per Second (2007)/[Arid] 5 Centimeters per Second (BDRip 1920x1080 Hi10 FLAC) [FD8B6FF2].ja.srt (newest sync 2025-09-28 00:01:08)
159
+ 2025-09-28 04:01:08,201 | Movies synced so far: 1
160
+ 2025-09-28 04:01:08,212 | Syncing /data/media/media/movies/Django Unchained (2012)/Django.Unchained.2012.1080p.BluRay.x264.YIFY.en.srt (previous sync 2025-09-27 23:57:39)
161
+ 2025-09-28 04:01:27,074 | Finished syncing /data/media/media/movies/Django Unchained (2012)/Django.Unchained.2012.1080p.BluRay.x264.YIFY.en.srt (newest sync 2025-09-28 00:01:27)
162
+ 2025-09-28 04:01:27,075 | Movies synced so far: 2
163
+ 2025-09-28 04:01:27,105 | Syncing /data/media/media/movies/KPop Demon Hunters (2025)/KPop.Demon.Hunters.2025.1080p.WEBRip.x264.AAC5.1-[YTS.MX].en.srt (previous sync 2025-09-27 21:11:54)
164
+ 2025-09-28 04:01:43,846 | Finished syncing /data/media/media/movies/KPop Demon Hunters (2025)/KPop.Demon.Hunters.2025.1080p.WEBRip.x264.AAC5.1-[YTS.MX].en.srt (newest sync 2025-09-28 00:01:43)
165
+ 2025-09-28 04:01:43,847 | Movies synced so far: 3
166
+ 2025-09-28 04:01:43,858 | Syncing /data/media/media/movies/Kung Fu Panda 3 (2016)/Kung.Fu.Panda.3.2016.1080p.BluRay.x264-[YTS.AG].en.srt (previous sync 2025-09-27 21:12:06)
167
+ 2025-09-28 04:01:55,179 | Finished syncing /data/media/media/movies/Kung Fu Panda 3 (2016)/Kung.Fu.Panda.3.2016.1080p.BluRay.x264-[YTS.AG].en.srt (newest sync 2025-09-28 00:01:55)
168
+ 2025-09-28 04:01:55,180 | Movies synced so far: 4
169
+ 2025-09-28 04:01:55,209 | Syncing /data/media/media/movies/Penguins of Madagascar (2014)/Penguins.of.Madagascar.2014.1080p.BluRay.x264.YIFY.en.srt (previous sync 2025-09-27 21:12:16)
170
+ 2025-09-28 04:02:06,189 | Finished syncing /data/media/media/movies/Penguins of Madagascar (2014)/Penguins.of.Madagascar.2014.1080p.BluRay.x264.YIFY.en.srt (newest sync 2025-09-28 00:02:06)
171
+ 2025-09-28 04:02:06,189 | Movies synced so far: 5
172
+ 2025-09-28 04:02:06,205 | Finished syncing movies. Total movies synced: 5
173
+ ```
174
+
175
+ Using the same config file as above, we run the sync again but only for movies that were never synced after 2025-09-28 00:01:30 using
176
+ ```
177
+ docker run --rm -v /bazarrbulksync:/app wayhowma/bazarrbulksync:latest --sync movies --latest-to-sync "2025-09-28 00:01:30"
178
+ ```
179
+
180
+ ```
181
+ 2025-09-28 04:08:08,920 | Bazarr Bulk Sync CLI Tool Arguments: Namespace(sync='movies', bazarr_base_url='http://192.168.1.251:6767/', bazarr_api_key='asdai21g3isufykasgfs7iodftas9d8f', output_messages_to_screen=True, log_messages_to_file=True, log_messages_file_path='./bazarrbulksync.log', max_movies_per_request=25, max_series_per_request=25, max_request_retries=1, request_timeout=1600, latest_to_sync='2025-09-28 00:01:30', original_format=None, max_offset_seconds=None, no_fix_framerate=None, gss=None, stop_on_request_failure=False)
182
+ 2025-09-28 04:08:08,928 | Syncing movies...
183
+ 2025-09-28 04:08:08,971 | Syncing /data/media/media/movies/5 Centimeters per Second (2007)/[Arid] 5 Centimeters per Second (BDRip 1920x1080 Hi10 FLAC) [FD8B6FF2].ja.srt (previous sync 2025-09-28 00:01:08)
184
+ 2025-09-28 04:08:13,115 | Finished syncing /data/media/media/movies/5 Centimeters per Second (2007)/[Arid] 5 Centimeters per Second (BDRip 1920x1080 Hi10 FLAC) [FD8B6FF2].ja.srt (newest sync 2025-09-28 00:08:13)
185
+ 2025-09-28 04:08:13,115 | Movies synced so far: 1
186
+ 2025-09-28 04:08:13,125 | Syncing /data/media/media/movies/Django Unchained (2012)/Django.Unchained.2012.1080p.BluRay.x264.YIFY.en.srt (previous sync 2025-09-28 00:01:27)
187
+ 2025-09-28 04:08:32,166 | Finished syncing /data/media/media/movies/Django Unchained (2012)/Django.Unchained.2012.1080p.BluRay.x264.YIFY.en.srt (newest sync 2025-09-28 00:08:32)
188
+ 2025-09-28 04:08:32,167 | Movies synced so far: 2
189
+ 2025-09-28 04:08:32,197 | Skipping /data/media/media/movies/KPop Demon Hunters (2025)/KPop.Demon.Hunters.2025.1080p.WEBRip.x264.AAC5.1-[YTS.MX].en.srt (last synced at 2025-09-28 00:01:43)
190
+ 2025-09-28 04:08:32,206 | Skipping /data/media/media/movies/Kung Fu Panda 3 (2016)/Kung.Fu.Panda.3.2016.1080p.BluRay.x264-[YTS.AG].en.srt (last synced at 2025-09-28 00:01:55)
191
+ 2025-09-28 04:08:32,234 | Skipping /data/media/media/movies/Penguins of Madagascar (2014)/Penguins.of.Madagascar.2014.1080p.BluRay.x264.YIFY.en.srt (last synced at 2025-09-28 00:02:06)
192
+ 2025-09-28 04:08:32,250 | Finished syncing movies. Total movies synced: 2
193
+ ```
194
+
195
+ ## Contributing
196
+ Contributions are welcome. Please open up an issue if you have ideas for improvements or submit a pull request on GitHub.
197
+
198
+ ## Licensing
199
+ BazarrBulkSync is distributed under the MIT License.
@@ -0,0 +1,16 @@
1
+ bazarrbulksync-0.0.0.dist-info/licenses/LICENSE,sha256=xS6JKiweSchBZBoSfD1D0tKPupwYH26T7dkq0Vk2t9k,1092
2
+ cli/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
3
+ cli/cli.py,sha256=MyyZwwsiBokaXCUOgDoaRvYz8846MXRTJG2MxvKDy8Y,9063
4
+ cli/config.py,sha256=eIGy3RwNg5YG-aiyKLXUHI-OXPnhoQbzanL55kuEUL4,1964
5
+ sync/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
6
+ sync/bazarr.py,sha256=-cd1R8JY1On9gaqgA-luinp3RRhn_SnGKLrGhr_ttZ0,10549
7
+ sync/sync.py,sha256=UQbp7RhPF0kLXt-1blIsy9mZZOSUktsDA1e0wfAwteA,12198
8
+ tests/__init__.py,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
9
+ tests/config.py,sha256=DgPHNFLqEEs_MiQ9RwiXn9LyEKW36jRix-kvzxxsWm8,385
10
+ tests/test_bazarr.py,sha256=o3AeFYOYR_840ntK9dYVfcj3Mhrm1GwMOXRAbLL9GpE,2906
11
+ tests/test_bazarr_api.py,sha256=9NYDpxys4hHQmOa4fkhrILNCYWeH53hvHJScrA3ZOVw,2654
12
+ bazarrbulksync-0.0.0.dist-info/METADATA,sha256=TdgzFfoWKl0oMQirFgAMElkvEMD3YXe7i9ZY6Vm-01Q,14407
13
+ bazarrbulksync-0.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
14
+ bazarrbulksync-0.0.0.dist-info/entry_points.txt,sha256=lsopl1HKYcVuE4V5gCSFsTeBc8XL7ZQenurREm_AKls,48
15
+ bazarrbulksync-0.0.0.dist-info/top_level.txt,sha256=rJ5KyWeMLnYTSORFkVL8DDjPL_OpwkGvluPWgqZq360,15
16
+ bazarrbulksync-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ bazarrbulksync = cli.cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Brian Wei Hao Ma
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,3 @@
1
+ cli
2
+ sync
3
+ tests
cli/__init__.py ADDED
File without changes
cli/cli.py ADDED
@@ -0,0 +1,268 @@
1
+ import logging
2
+ from datetime import datetime
3
+ from argparse import ArgumentParser
4
+ import traceback
5
+
6
+ import requests
7
+
8
+ from sync.sync import (
9
+ Syncer,
10
+ )
11
+ from sync.bazarr import (
12
+ BazarrAPI,
13
+ )
14
+ from .config import (
15
+ BAZARR_BASE_URL,
16
+ BAZARR_API_KEY,
17
+ OUTPUT_MESSAGES_TO_SCREEN,
18
+ LOG_MESSAGES_TO_FILE,
19
+ LOG_MESSAGES_FILE_PATH,
20
+ MAX_MOVIES_PER_REQUEST,
21
+ MAX_SERIES_PER_REQUEST,
22
+ REQUEST_TIMEOUT,
23
+ STOP_ON_REQUEST_FAILURE,
24
+ MAX_REQUEST_RETRIES,
25
+ ORIGINAL_FORMAT,
26
+ MAX_OFFSET_SECONDS,
27
+ NO_FIX_FRAMERATE,
28
+ GSS,
29
+ )
30
+
31
+
32
+ def main():
33
+ parser = ArgumentParser(
34
+ prog="bazarrbulksync",
35
+ description="A CLI tool to bulk sync subtitles in Bazarr. "
36
+ "You can find out more about the project at: https://github.com/BrianWeiHaoMa/bazarrbulksync",
37
+ )
38
+
39
+ parser.add_argument(
40
+ "--sync",
41
+ type=str,
42
+ choices=["movies", "episodes", "both"],
43
+ required=True,
44
+ help="What to run the sync for",
45
+ )
46
+ parser.add_argument(
47
+ "--bazarr-base-url",
48
+ type=str,
49
+ default=BAZARR_BASE_URL,
50
+ help="The bazarr base url (ex: http://192.168.1.251:6767/)",
51
+ )
52
+ parser.add_argument(
53
+ "--bazarr-api-key",
54
+ type=str,
55
+ default=BAZARR_API_KEY,
56
+ help="The bazarr API key (ex: asdai21g3isufykasgfs7iodftas9d8f)",
57
+ )
58
+ parser.add_argument(
59
+ "--output-messages-to-screen",
60
+ type=lambda x: (str(x).lower() == "true"),
61
+ default=OUTPUT_MESSAGES_TO_SCREEN,
62
+ help="True if you want to enable outputting log messages to screen",
63
+ )
64
+ parser.add_argument(
65
+ "--log-messages-to-file",
66
+ type=lambda x: (str(x).lower() == "true"),
67
+ default=LOG_MESSAGES_TO_FILE,
68
+ help="True if you want to save log messages to a file",
69
+ )
70
+ parser.add_argument(
71
+ "--log-messages-file-path",
72
+ type=str,
73
+ default=LOG_MESSAGES_FILE_PATH,
74
+ help="The file path to save the log messages to (ex: ./bazarr_bulk_sync.log)",
75
+ )
76
+ parser.add_argument(
77
+ "--max-movies-per-request",
78
+ type=int,
79
+ default=MAX_MOVIES_PER_REQUEST,
80
+ help="The maximum number of movies to query per request",
81
+ )
82
+ parser.add_argument(
83
+ "--max-series-per-request",
84
+ type=int,
85
+ default=MAX_SERIES_PER_REQUEST,
86
+ help="The maximum number of series to query per request",
87
+ )
88
+ parser.add_argument(
89
+ "--max-request-retries",
90
+ type=int,
91
+ default=MAX_REQUEST_RETRIES,
92
+ help="The maximum number of retries for a failed API request",
93
+ )
94
+ parser.add_argument(
95
+ "--request-timeout",
96
+ type=int,
97
+ default=REQUEST_TIMEOUT,
98
+ help="The request timeout in seconds for each API request",
99
+ )
100
+ parser.add_argument(
101
+ "--latest-to-sync",
102
+ type=str,
103
+ default=datetime.max.strftime("%Y-%m-%d"),
104
+ help="The most latest sync time to sync from (up until the present time) \
105
+ '%%Y-%%m-%%d %%H:%%M:%%S' or '%%Y-%%m-%%d' format. Items previously already \
106
+ synced more recently than this time will be skipped.",
107
+ )
108
+ parser.add_argument(
109
+ "--original-format",
110
+ type=str,
111
+ choices=["True", "False"],
112
+ default=ORIGINAL_FORMAT,
113
+ help="Use original subtitles format when syncing subtitles",
114
+ )
115
+ parser.add_argument(
116
+ "--max-offset-seconds",
117
+ type=str,
118
+ default=MAX_OFFSET_SECONDS,
119
+ help="Maximum offset seconds to allow when syncing subtitles",
120
+ )
121
+ parser.add_argument(
122
+ "--no-fix-framerate",
123
+ type=str,
124
+ choices=["True", "False"],
125
+ default=NO_FIX_FRAMERATE,
126
+ help="Don't try to fix framerate when syncing subtitles",
127
+ )
128
+ parser.add_argument(
129
+ "--gss",
130
+ type=str,
131
+ choices=["True", "False"],
132
+ default=GSS,
133
+ help="Use Golden-Section Search when syncing subtitles",
134
+ )
135
+ parser.add_argument(
136
+ "--stop-on-request-failure",
137
+ type=lambda x: (str(x).lower() == "true"),
138
+ choices=["True", "False"],
139
+ default=STOP_ON_REQUEST_FAILURE,
140
+ help="True if you want to stop the sync when a request fails",
141
+ )
142
+
143
+ parsed_args = parser.parse_args()
144
+
145
+ if parsed_args.bazarr_base_url is None:
146
+ raise ValueError("Bazarr URL must be set via config file or CLI argument")
147
+
148
+ if parsed_args.bazarr_api_key is None:
149
+ raise ValueError("Bazarr API key must be set via config file or CLI argument")
150
+
151
+ sync = parsed_args.sync
152
+
153
+ LOGGER_NAME = "Bazarr Bulk Sync CLI Tool"
154
+ logging_fmt = "%(asctime)s | %(message)s"
155
+ if parsed_args.output_messages_to_screen:
156
+ logging.basicConfig(
157
+ level=logging.INFO,
158
+ format=logging_fmt,
159
+ )
160
+ logger = logging.getLogger(LOGGER_NAME)
161
+
162
+ if parsed_args.log_messages_to_file:
163
+ file_handler = logging.FileHandler(
164
+ parsed_args.log_messages_file_path, mode="a"
165
+ )
166
+ file_handler.setLevel(logging.INFO)
167
+ file_formatter = logging.Formatter(logging_fmt)
168
+ file_handler.setFormatter(file_formatter)
169
+ logger.addHandler(file_handler)
170
+ else:
171
+ disable_logging = False
172
+ if parsed_args.log_messages_to_file:
173
+ logging.basicConfig(
174
+ level=logging.INFO,
175
+ format=logging_fmt,
176
+ filename=parsed_args.log_messages_file_path,
177
+ filemode="a",
178
+ )
179
+ else:
180
+ disable_logging = True
181
+
182
+ logger = logging.getLogger(LOGGER_NAME)
183
+ if disable_logging:
184
+ logger.disabled = True
185
+
186
+ logger.info(f"Bazarr Bulk Sync CLI Tool Arguments: {parsed_args}")
187
+
188
+ try:
189
+ latest_to_sync = datetime.strptime(
190
+ parsed_args.latest_to_sync,
191
+ "%Y-%m-%d",
192
+ )
193
+ except Exception:
194
+ try:
195
+ latest_to_sync = datetime.strptime(
196
+ parsed_args.latest_to_sync,
197
+ "%Y-%m-%d %H:%M:%S",
198
+ )
199
+ except Exception:
200
+ raise ValueError(
201
+ f"latest_to_sync ({parsed_args.latest_to_sync}) must be in"
202
+ "'%%Y-%%m-%%d %%H:%%M:%%S' or '%%Y-%%m-%%d' format"
203
+ )
204
+
205
+ bazarr_api = BazarrAPI(
206
+ base_url=parsed_args.bazarr_base_url,
207
+ api_key=parsed_args.bazarr_api_key,
208
+ request_timeout=parsed_args.request_timeout,
209
+ max_request_retries=parsed_args.max_request_retries,
210
+ )
211
+
212
+ syncer = Syncer(
213
+ bazarr_api=bazarr_api,
214
+ latest_to_sync=latest_to_sync,
215
+ logger=logger,
216
+ stop_on_request_failure=parsed_args.stop_on_request_failure,
217
+ )
218
+
219
+ try:
220
+ if sync == "movies":
221
+ syncer.sync_movies(
222
+ lastest_to_sync=latest_to_sync,
223
+ original_format=parsed_args.original_format,
224
+ max_offset_seconds=parsed_args.max_offset_seconds,
225
+ no_fix_framerate=parsed_args.no_fix_framerate,
226
+ gss=parsed_args.gss,
227
+ max_payload_size=parsed_args.max_movies_per_request,
228
+ )
229
+ elif sync == "episodes":
230
+ syncer.sync_episodes(
231
+ lastest_to_sync=latest_to_sync,
232
+ original_format=parsed_args.original_format,
233
+ max_offset_seconds=parsed_args.max_offset_seconds,
234
+ no_fix_framerate=parsed_args.no_fix_framerate,
235
+ gss=parsed_args.gss,
236
+ max_payload_size=parsed_args.max_movies_per_request,
237
+ )
238
+ elif sync == "both":
239
+ syncer.sync_movies(
240
+ lastest_to_sync=latest_to_sync,
241
+ original_format=parsed_args.original_format,
242
+ max_offset_seconds=parsed_args.max_offset_seconds,
243
+ no_fix_framerate=parsed_args.no_fix_framerate,
244
+ gss=parsed_args.gss,
245
+ max_payload_size=parsed_args.max_movies_per_request,
246
+ )
247
+ syncer.sync_episodes(
248
+ lastest_to_sync=latest_to_sync,
249
+ original_format=parsed_args.original_format,
250
+ max_offset_seconds=parsed_args.max_offset_seconds,
251
+ no_fix_framerate=parsed_args.no_fix_framerate,
252
+ gss=parsed_args.gss,
253
+ max_payload_size=parsed_args.max_series_per_request,
254
+ )
255
+ else:
256
+ assert False, "this should never be reached"
257
+ except Exception as e:
258
+ if isinstance(e, requests.RequestException):
259
+ logger.warning(f"A request failure occurred during the sync: {e}")
260
+ else:
261
+ logger.critical(
262
+ f"A critical error occurred during the sync:\n{traceback.format_exc()}"
263
+ )
264
+ raise e
265
+
266
+
267
+ if __name__ == "__main__":
268
+ main()
cli/config.py ADDED
@@ -0,0 +1,64 @@
1
+ import os
2
+
3
+ import yaml
4
+
5
+ CONFIG_PATH = "./bazarrbulksync_cli.yaml"
6
+
7
+ config = {}
8
+ if os.path.exists(CONFIG_PATH):
9
+ with open(CONFIG_PATH, "r") as f:
10
+ config = yaml.safe_load(f)
11
+
12
+
13
+ def _get_nested_value(
14
+ *args,
15
+ default=None,
16
+ data: dict,
17
+ ):
18
+ try:
19
+ if len(args) == 1:
20
+ return data.get(args[0], default)
21
+
22
+ idx = 1
23
+ holder = data[args[0]]
24
+ while idx < len(args) - 1:
25
+ holder = holder[args[idx]]
26
+
27
+ return holder.get(args[-1], default)
28
+ except:
29
+ return default
30
+
31
+
32
+ BAZARR_BASE_URL = _get_nested_value("bazarr", "base_url", default=None, data=config)
33
+ BAZARR_API_KEY = _get_nested_value("bazarr", "api_key", default=None, data=config)
34
+
35
+ OUTPUT_MESSAGES_TO_SCREEN = _get_nested_value(
36
+ "output_messages_to_screen", default=True, data=config
37
+ )
38
+ LOG_MESSAGES_TO_FILE = _get_nested_value(
39
+ "log_messages_to_file", default=True, data=config
40
+ )
41
+ LOG_MESSAGES_FILE_PATH = _get_nested_value(
42
+ "log_messages_file_path", default="./bazarr_bulk_sync.log", data=config
43
+ )
44
+
45
+ MAX_MOVIES_PER_REQUEST = _get_nested_value(
46
+ "max_movies_per_request", default=25, data=config
47
+ )
48
+ MAX_SERIES_PER_REQUEST = _get_nested_value(
49
+ "max_series_per_request", default=25, data=config
50
+ )
51
+
52
+ MAX_REQUEST_RETRIES = _get_nested_value("max_request_retries", default=3, data=config)
53
+
54
+ REQUEST_TIMEOUT = _get_nested_value("request_timeout", default=30, data=config)
55
+
56
+ STOP_ON_REQUEST_FAILURE = _get_nested_value(
57
+ "stop_on_request_failure", default=False, data=config
58
+ )
59
+
60
+ ORIGINAL_FORMAT = _get_nested_value("original_format", default=None, data=config)
61
+ REFERENCE = _get_nested_value("reference", default=None, data=config)
62
+ MAX_OFFSET_SECONDS = _get_nested_value("max_offset_seconds", default=None, data=config)
63
+ NO_FIX_FRAMERATE = _get_nested_value("no_fix_framerate", default=None, data=config)
64
+ GSS = _get_nested_value("gss", default=None, data=config)
sync/__init__.py ADDED
File without changes