This repository has been archived by the owner on Aug 25, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
TEST.py
340 lines (304 loc) · 12.6 KB
/
TEST.py
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
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
import os
import re
import fnmatch
import time
import logging
# Set variables
nfo_album = ''
nfo_author = ''
nfo_narr = ''
nfo_genre = ''
nfo_year = ''
nfo_duration = ''
nfo_asin = ''
nfo_publisher = ''
nfo_copy = ''
nfo_audio = ''
nfo_bitrate = ''
nfo_sub = ''
nfo_comm = ''
nfo_link = ''
nfo_desc = ''
nfo_series = ''
num_serie = ''
nfo_encoder = ''
nfo_full = ''
nfo_unabridged = ''
nfo_release = ''
nfo_size = ''
nfo_url = ''
nfofile = "Y:\\Sci-Fi & Fantasy\\Jerry Merritt\\ 2017. A Gift of Time (160kb)\\Jerry Merritt - 2017 - A Gift of Time (Unabridged).nfo"
# set up logging to file
logging.basicConfig(level=logging.INFO,
format='%(levelname)-8s%(asctime)s %(name)-12s %(message)s',
datefmt='%d-%m-%y (%H:%M)',
filename='log.log',
filemode='w')
# define a Handler which writes INFO messages or higher to the sys.stderr
console = logging.StreamHandler()
console.setLevel(logging.INFO)
# set a format which is simpler for console use
formatter = logging.Formatter('%(levelname)-8s%(asctime)s %(name)-8s %(message)s', "%H:%M:%S")
# tell the handler to use this format
console.setFormatter(formatter)
# add the handler to the root logger
logging.getLogger('').addHandler(console)
logger_nfo = logging.getLogger('nfo')
# --------------------------------------------------------------------
logger_nfo.info('Starting looking for NFO file....')
# Book Title
_title = ["Title:", "Title.."]
logger_nfo.info('Searching Title book...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _title: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_album = line
# remove (Unabridged)
nfo_album = re.sub(r' \(unabridged\)', r'', nfo_album)
# remove everything before :
nfo_album = re.sub(r'^[^:]*:', r'', nfo_album).lstrip().title()
# splitting if title as series
nfo_album2 = nfo_album.split(' - ')
try:
nfo_album = nfo_album2[1]
nfo_series = nfo_album2[0]
logger_nfo.info('Found Book Title: %s', nfo_album)
except:
logger_nfo.info('Found Book Title: %s', nfo_album)
if nfo_album == '':
logger_nfo.warning('Book Title not found.')
# Book Author
_author = ["Author:", "Author.."]
logger_nfo.info('Searching Author book...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _author: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_author = line
# remove everything before :
nfo_author = re.sub(r'^[^:]*:', r'', nfo_author).lstrip().title()
logger_nfo.info('Author Found: %s', nfo_author)
if nfo_author == '':
logger_nfo.warning('Author not found.')
# Book Narrator
_narrator = ["Read by:", "Narrator:", "Read by.."]
logger_nfo.info('Searching Narrator...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _narrator: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_narr = line
# remove everything before :
nfo_narr = re.sub(r'^[^:]*:', r'', nfo_narr).lstrip().title()
logger_nfo.info('Narrator Found: %s', nfo_narr)
if nfo_narr == '':
logger_nfo.warning('Narrator not found.')
# Book Series
_series = ["Series:", "Series Name:"]
logger_nfo.info('Searching Series...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _series: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
if nfo_series == '':
nfo_series = line
# remove everything before :
nfo_series = re.sub(r'^[^:]*:', r'', nfo_series).lstrip().title()
logger_nfo.info('Series Found: %s', nfo_series)
else:
pass
if nfo_series == '':
logger_nfo.warning('Series not found.')
else:
try:
num_serie2 = nfo_series.split(' Book ')
num_serie = num_serie2[1]
logger_nfo.info('Series number found: %s', num_serie)
except:
logger_nfo.warning('Series number not Found!')
nfo_series = re.sub(r' Book 1', r'', nfo_series)
nfo_series = re.sub(r' Book 2', r'', nfo_series)
nfo_series = re.sub(r' Book 3', r'', nfo_series)
nfo_series = re.sub(r' Book 4', r'', nfo_series)
logger_nfo.info('Series Found: %s', nfo_series)
if num_serie == '':
# Book series number
_number = ["Position in", "sfdsfdsfsd"]
logger_nfo.info('Searching Series number...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _number: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
num_serie = line
# remove everything before :
num_serie = re.sub(r'^[^:]*:', r'', num_serie).lstrip().title()
logger_nfo.info('Narrator Found: %s', num_serie)
if num_serie == '':
logger_nfo.warning('Series number not found.')
else:
pass
# Book Genre
_genre = ["Genre:", "GENRE.."]
logger_nfo.info('Searching Genre...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _genre: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_genre = line
# remove everything before :
nfo_genre = re.sub(r'^[^:]*:', r'', nfo_genre).lstrip().title()
logger_nfo.info('Genre Found: %s', nfo_genre)
if nfo_genre == '':
logger_nfo.warning('Genre not found.')
# Book Copyright
_copy = ["Copyright:", "Copyright.."]
logger_nfo.info('Searching Copyright...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _copy: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_copy = line
# remove everything before :
nfo_copy = re.sub(r'^[^:]*:', r'', nfo_copy).lstrip().title()
logger_nfo.info('Copyright Found: %s', nfo_copy)
if nfo_copy == '':
logger_nfo.warning('Copyright not found.')
# Book Duration
_dura = ["Duration:", "Time:", 'TiME..', "Duration.."]
logger_nfo.info('Searching Duration...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _dura: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_duration = line
# remove everything before :
nfo_duration = re.sub(r'^[^:]*:', r'', nfo_duration).lstrip().title()
logger_nfo.info('Duration Found: %s', nfo_duration)
if nfo_duration == '':
logger_nfo.warning('Duration not found.')
# Book Publisher
_publisher = ["Publisher:", "PUBLiSHER.."]
logger_nfo.info('Searching Publisher...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _publisher: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_publisher = line
# remove everything before :
nfo_publisher = re.sub(r'^[^:]*:', r'', nfo_publisher).lstrip().title()
logger_nfo.info('Publisher Found: %s', nfo_publisher)
if nfo_publisher == '':
logger_nfo.warning('Publisher not found.')
# Book unbridged
_uno = ["Unabridged:", "Unabridged.."]
logger_nfo.info('Searching Unbridged...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _uno: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_unabridged = line
# remove everything before :
nfo_unabridged = re.sub(r'^[^:]*:', r'', nfo_unabridged).lstrip().title()
logger_nfo.info('Unbridged Found: %s', nfo_unabridged)
if nfo_unabridged == '':
logger_nfo.warning('Unbridged not found.')
# Book Release
_release = ["Release:", "STOREDATE..", "Release.."]
logger_nfo.info('Searching Release...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _release: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_release = line
# remove everything before :
nfo_release = re.sub(r'^[^:]*:', r'', nfo_release).lstrip().title()
if not nfo_release:
pass
else:
logger_nfo.info('Release Found: %s', nfo_release)
if nfo_release == '':
logger_nfo.warning('Release not found.')
# Book size
_size = ["Size:", "SiZE.."]
logger_nfo.info('Searching Size...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _size: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_size = line
# remove everything before :
nfo_size = re.sub(r'^[^:]*:', r'', nfo_size).lstrip().title()
logger_nfo.info('Size Found: %s', nfo_size)
if nfo_size == '':
logger_nfo.warning('Size not found.')
# Book url
_url = ["URL:", "URL.."]
logger_nfo.info('Searching Url...')
with open(nfofile, "r+") as file1:
fileline1 = file1.readlines()
for x in _url: # <--- Loop through the list to check
for line in fileline1: # <--- Loop through each line
line = line.casefold() # <--- Set line to lowercase
if x.casefold() in line:
logger_nfo.info('Line found with word: %s', x)
nfo_url = line
# remove everything before :
nfo_url = re.sub(r'^[^:]*:', r'', nfo_url).lstrip().title()
logger_nfo.info('Url Found: %s', nfo_url)
if nfo_url == '':
logger_nfo.warning('Url Not Found.')
# Description
copy = False
with open(nfofile, "r") as saveoutput:
for line in saveoutput:
if 'Description' in line:
copy = True
# if line.startswith('-'):
# copy = False
if copy:
items = (format(line.strip()) for line in saveoutput)
join = '\n'.join(items)
join = re.sub(r'Description:', r'', join)
join = re.sub(r' ==', r'', join)
nfo_desc = join
# logger_nfo.info('Description: %s', join)
logger_nfo.info('Description Found: %s', nfo_desc)
# else:
# print('No description found.')