-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcleanup-discogs-continuous.py
1254 lines (1160 loc) · 61.8 KB
/
cleanup-discogs-continuous.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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
# Tool to discover 'smells' in the Discogs data via the API. It downloads
# release data and flags releases that need to be fixed.
#
# The checks are (nearly) identical to cleanup-discogs.py
#
# The results that are printed by this script are by no means complete
# or accurate.
#
# Licensed under the terms of the General Public License version 3
#
# SPDX-License-Identifier: GPL-3.0-only
#
# Copyright 2017 - 2019 - Armijn Hemel for Tjaldur Software Governance Solutions
import sys
import os
import re
import datetime
import time
import json
import subprocess
import argparse
import configparser
import tempfile
import requests
import discogssmells
# grab the current year. Make sure to set the clock of your machine
# to the correct date or use NTP!
currentyear = datetime.datetime.utcnow().year
# grab the latest release from the API. Results tend to get cached
# by the Discogs nginx instance for some reason.
def get_latest_release(headers):
latest = 'https://api.discogs.com/database/search?type=release&sort=date_added'
r = requests.get(latest, headers=headers)
if r.status_code != 200:
return
# now parse the response
responsejson = r.json()
if not 'results' in responsejson:
return
return responsejson['results'][0]['id']
# convenience method to check if roles are valid
def checkrole(artist, release_id, credits):
invalidroles = []
if not '[' in artist['role']:
roles = map(lambda x: x.strip(), artist['role'].split(','))
for role in roles:
if role == '':
continue
if not role in credits:
invalidroles.append(role)
else:
# sometimes there is an additional description in the role in
# between [ and ]
# This method is definitely not catching everything.
rolesplit = artist['role'].split('[')
for rs in rolesplit:
if ']' in rs:
rs_tmp = rs
while ']' in rs_tmp:
rs_tmp = rs_tmp.split(']', 1)[1]
roles = map(lambda x: x.strip(), rs_tmp.split(','))
for role in roles:
if role == '':
continue
# ugly hack because sometimes the extra data between [ and ]
# appears halfway the words in a role, sigh.
if role == 'By':
continue
if not role in credits:
invalidroles.append(role)
return invalidroles
# process the contents of a release
def processrelease(release, config_settings, count, credits, ibuddy, favourites):
releaseurl = 'https://www.discogs.com/release/%s'
# only process entries that have a status of 'Accepted'
if release['status'] == 'Rejected':
return count
elif release['status'] == 'Draft':
return count
elif release['status'] == 'Deleted':
return count
errormsgs = []
# store some data that is used by multiple checks
founddeposito = False
year = None
release_id = release['id']
# check for favourite artist, if defined
for artist in release['artists']:
if artist['name'] in favourites:
if ibuddy != None:
ibuddy.executecommand('HEART:WINGSHIGH:RED:GO:SHORTSLEEP:NOHEART:WINGSLOW:GO:SHORTSLEEP:HEART:LEFT::WINGSHIGH::GO:SHORTSLEEP:NOHEART:RIGHT:GO:HEART:GO:BLUE:SHORTSLEEP:WINGSLOW:GO:SHORTSLEEP:RESET')
ibuddy.reset()
if config_settings['use_notify_send']:
count += 1
errormsgs.append('%8d -- Favourite Artist (%s): https://www.discogs.com/release/%s' % (count, artist['name'], str(release_id)))
# check for misspellings of Czechoslovak and Czech releases
# People use 0x115 instead of 0x11B, which look very similar but 0x115
# is not valid in the Czech alphabet. Check for all data except
# the YouTube playlist.
# https://www.discogs.com/group/thread/757556
# This is important for the following elements:
# * tracklist (title, subtracks not supported yet)
# * artist and extraartists (including extraartists in tracklist)
# * notes
# * BaOI identifiers (both value and description)
if config_settings['check_spelling_cs']:
if 'country' in release:
if release['country'] == 'Czechoslovakia' or release['country'] == 'Czech Republic':
for t in release['tracklist']:
if chr(0x115) in t['title']:
count += 1
errormsgs.append('%8d -- Czech character (0x115, tracklist: %s): https://www.discogs.com/release/%s' % (count, t['position'], str(release_id)))
if 'extraartists' in t:
for artist in t['extraartists']:
if chr(0x115) in artist['name']:
count += 1
errormsgs.append('%8d -- Czech character (0x115, artist name at: %s): https://www.discogs.com/release/%s' % (count, t['position'], str(release_id)))
if 'artists' in release:
for artist in release['artists']:
if chr(0x115) in artist['name']:
count += 1
errormsgs.append('%8d -- Czech character (0x115, artist name: %s): https://www.discogs.com/release/%s' % (count, artist['name'], str(release_id)))
if 'extraartists' in release:
for artist in release['extraartists']:
if chr(0x115) in artist['name']:
count += 1
errormsgs.append('%8d -- Czech character (0x115, artist name: %s): https://www.discogs.com/release/%s' % (count, artist['name'], str(release_id)))
for i in release['identifiers']:
if chr(0x115) in i['value']:
count += 1
errormsgs.append('%8d -- Czech character (0x115, BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
if 'description' in i:
if chr(0x115) in i['description']:
count += 1
errormsgs.append('%8d -- Czech character (0x115, BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
if 'notes' in release:
if chr(0x115) in release['notes']:
count += 1
errormsgs.append('%8d -- Czech character (0x115, Notes): https://www.discogs.com/release/%s' % (count, str(release_id)))
# check credit roles in three places:
# 1. artists
# 2. extraartists (release level)
# 3. extraartists (track level)
if 'check_credits' in config_settings:
if config_settings['check_credits']:
if 'artists' in release:
for artist in release['artists']:
if 'role' in artist:
invalidroles = checkrole(artist, release_id, credits)
for role in invalidroles:
count += 1
errormsgs.append('%8d -- Role \'%s\' invalid: https://www.discogs.com/release/%s' % (count, role, str(release_id)))
if 'extraartists' in release:
for artist in release['extraartists']:
if 'role' in artist:
invalidroles = checkrole(artist, release_id, credits)
for role in invalidroles:
count += 1
errormsgs.append('%8d -- Role \'%s\' invalid: https://www.discogs.com/release/%s' % (count, role, str(release_id)))
for t in release['tracklist']:
if 'extraartists' in t:
for artist in t['extraartists']:
if 'role' in artist:
invalidroles = checkrole(artist, release_id, credits)
for role in invalidroles:
count += 1
errormsgs.append('%8d -- Role \'%s\' invalid: https://www.discogs.com/release/%s' % (count, role, str(release_id)))
# check release month and year
if 'released' in release:
if config_settings['check_month']:
if '-' in release['released']:
monthres = re.search('-(\d+)-', release['released'])
if monthres != None:
monthnr = int(monthres.groups()[0])
if monthnr == 0:
count += 1
errormsgs.append('%8d -- Month 00: https://www.discogs.com/release/%s' % (count, str(release_id)))
elif monthnr > 12:
count += 1
errormsgs.append('%8d -- Month impossible (%d): https://www.discogs.com/release/%s' % (count, monthnr, str(release_id)))
try:
year = int(release['released'].split('-', 1)[0])
# TODO: check for implausible old years
except ValueError:
if config_settings['check_year']:
count += 1
errormsgs.append('%8d -- Year \'%s\' invalid: https://www.discogs.com/release/%s' % (count, release['released'], str(release_id)))
# check the tracklist
tracklistcorrect = True
tracklistpositions = set()
formattexts = set()
if config_settings['check_tracklisting'] and len(release['formats']) == 1:
formattext = release['formats'][0]['name']
formattexts.add(formattext)
formatqty = int(release['formats'][0]['qty'])
for t in release['tracklist']:
if tracklistcorrect:
if formattext in ['Vinyl', 'Cassette', 'Shellac', '8-Track Cartridge']:
try:
int(t['position'])
count += 1
errormsgs.append('%8d -- Tracklisting (%s): https://www.discogs.com/release/%s' % (count, formattext, str(release_id)))
tracklistcorrect = False
break
except:
pass
if formatqty == 1:
if t['position'].strip() != '' and t['position'].strip() != '-' and t['type_'] != 'heading' and t['position'] in tracklistpositions:
count += 1
errormsgs.append('%8d -- Tracklisting reuse (%s, %s): https://www.discogs.com/release/%s' % (count, formattext, t['position'], str(release_id)))
tracklistpositions.add(t['position'])
# various checks for labels
for l in release['labels']:
# check for several identifiers being used as catalog numbers
if 'catno' in l:
if config_settings['check_label_code']:
if l['catno'].lower().startswith('lc'):
falsepositive = False
# American releases on Epic (label 1005 in Discogs)
# sometimes start with LC
if l['id'] == 1005:
falsepositive = True
if not falsepositive:
if discogssmells.labelcodere.match(l['catno'].lower()) != None:
count += 1
errormsgs.append('%8d -- Possible Label Code (in Catalogue Number): https://www.discogs.com/release/%s' % (count, str(release_id)))
if config_settings['check_deposito']:
# now check for D.L.
dlfound = False
for d in discogssmells.depositores:
result = d.search(l['catno'])
if result != None:
for depositovalre in discogssmells.depositovalres:
if depositovalre.search(l['catno']) != None:
dlfound = True
break
if dlfound:
count += 1
errormsgs.append('%8d -- Possible Depósito Legal (in Catalogue Number): https://www.discogs.com/release/%s' % (count, str(release_id)))
if 'name' in l:
if config_settings['check_label_name']:
if l['name'] == 'London' and l['id'] == 26905:
count += 1
errormsgs.append('%8d -- Wrong label (London): https://www.discogs.com/release/%s' % (count, str(release_id)))
'''
if name == 'format':
for (k,v) in attrs.items():
if k == 'name':
if v == 'CD':
self.iscd = True
self.formattexts.add(v)
elif k == 'qty':
if self.formatmaxqty == 0:
self.formatmaxqty = max(self.formatmaxqty, int(v))
else:
self.formatmaxqty += int(v)
'''
# various checks for the formats
formattexts = set()
for f in release['formats']:
if 'descriptions' in f:
if 'Styrene' in f['descriptions']:
pass
# store the names of the formats. This is useful later for SID code checks
if 'name' in f:
formattexts.add(f['name'])
if 'text' in f:
if f['text'] != '':
if config_settings['check_spars_code']:
tmpspars = f['text'].lower().strip()
for s in ['.', ' ', '•', '·', '[', ']', '-', '|', '/']:
tmpspars = tmpspars.replace(s, '')
if tmpspars in discogssmells.validsparscodes:
count += 1
errormsgs.append('%8d -- Possible SPARS Code (in Format): https://www.discogs.com/release/%s' % (count, str(release_id)))
if config_settings['check_label_code']:
if f['text'].lower().startswith('lc'):
if discogssmells.labelcodere.match(f['text'].lower()) != None:
count += 1
errormsgs.append('%8d -- Possible Label Code (in Format): https://www.discogs.com/release/%s' % (count, str(release_id)))
# walk through the BaOI identifiers
for identifier in release['identifiers']:
v = identifier['value']
if config_settings['check_creative_commons']:
if 'creative commons' in v.lower():
count += 1
errormsgs.append('%8d -- Creative Commons reference: https://www.discogs.com/release/%s' % (count, str(release)))
if 'description' in identifier:
if 'creative commons' in identifier['description'].lower():
count += 1
errormsgs.append('%8d -- Creative Commons reference: https://www.discogs.com/release/%s' % (count, str(release)))
if config_settings['check_spars_code']:
if identifier['type'] == 'SPARS Code':
if v.lower() != "none":
# Sony format codes
# https://www.discogs.com/forum/thread/339244
# https://www.discogs.com/forum/thread/358285
if v == 'CDC' or v == 'CDM':
count += 1
errormsgs.append('%8d -- Sony Format Code in SPARS: https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
tmpspars = v.lower().strip()
for s in ['.', ' ', '•', '·', '[', ']', '-', '|', '/']:
tmpspars = tmpspars.replace(s, '')
if not tmpspars in discogssmells.validsparscodes:
count += 1
errormsgs.append('%8d -- SPARS Code (format): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
# first check the description free text field
sparsfound = False
if 'description' in identifier:
for spars in discogssmells.spars_ftf:
if spars in identifier['description'].lower():
sparsfound = True
# then also check the value to see if there is a valid SPARS
if v.lower() in discogssmells.validsparscodes:
sparsfound = True
else:
if 'd' in v.lower():
tmpspars = v.strip()
for s in ['.', ' ', '•', '·', '[', ']', '-', '|', '/']:
tmpspars = tmpspars.replace(s, '')
if tmpspars in discogssmells.validsparscodes:
sparsfound = True
# print error if some SPARS code reference was found
if sparsfound:
count += 1
errormsgs.append('%8d -- SPARS Code (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
if config_settings['check_label_code']:
if identifier['type'] == 'Label Code':
# check how many people use 'O' instead of '0'
if v.lower().startswith('lc'):
if 'O' in identifier['value']:
errormsgs.append('%8d -- Spelling error in Label Code): https://www.discogs.com/release/%s' % (count, str(release_id)))
sys.stdout.flush()
if discogssmells.labelcodere.match(v.lower()) is None:
count += 1
errormsgs.append('%8d -- Label Code (value): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
if identifier['type'] == 'Rights Society':
if v.lower().startswith('lc'):
if discogssmells.labelcodere.match(v.lower()) != None:
count += 1
errormsgs.append('%8d -- Label Code (in Rights Society): https://www.discogs.com/release/%s' % (count, str(release_id)))
elif identifier['type'] == 'Barcode':
if v.lower().startswith('lc'):
if discogssmells.labelcodere.match(v.lower()) != None:
count += 1
errormsgs.append('%8d -- Label Code (in Barcode): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
if 'description' in identifier:
if identifier['description'].lower() in discogssmells.label_code_ftf:
count += 1
errormsgs.append('%8d -- Label Code: https://www.discogs.com/release/%s' % (count, str(release_id)))
if config_settings['check_rights_society']:
if identifier['type'] != 'Rights Society':
foundrightssociety = False
for r in discogssmells.rights_societies:
if v.replace('.', '') == r or v.replace(' ', '') == r:
count += 1
foundrightssociety = True
if identifier['type'] == 'Barcode':
errormsgs.append('%8d -- Rights Society (Barcode): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
errormsgs.append('%8d -- Rights Society (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
break
if not foundrightssociety and 'description' in identifier:
if identifier['description'].lower() in discogssmells.rights_societies_ftf:
count += 1
errormsgs.append('%8d -- Rights Society: https://www.discogs.com/release/%s' % (count, str(release_id)))
# temporary hack, move to own configuration option
asinstrict = False
if config_settings['check_asin']:
if identifier['type'] == 'ASIN':
if not asinstrict:
tmpasin = v.strip().replace('-', '')
else:
tmpasin = v
if not len(tmpasin.split(':')[-1].strip()) == 10:
count += 1
errormsgs.append('%8d -- ASIN (wrong length): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
if 'description' in identifier:
if identifier['description'].lower().startswith('asin'):
count += 1
errormsgs.append('%8d -- ASIN (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
if config_settings['check_isrc']:
if identifier['type'] == 'ISRC':
# Check the length of ISRC fields. According to the
# specifications these should be 12 in length. Some ISRC
# identifiers that have been recorded in the database
# span a range of tracks. These will be reported as wrong ISRC
# codes. It is unclear what needs to be done with those.
# first get rid of cruft
isrc_tmp = v.strip().upper()
if isrc_tmp.startswith('ISRC'):
isrc_tmp = isrc_tmp.split('ISRC')[-1].strip()
if isrc_tmp.startswith('CODE'):
isrc_tmp = isrc_tmp.split('CODE')[-1].strip()
# replace a few characters
isrc_tmp = isrc_tmp.replace('-', '')
isrc_tmp = isrc_tmp.replace(' ', '')
isrc_tmp = isrc_tmp.replace('.', '')
isrc_tmp = isrc_tmp.replace(':', '')
isrc_tmp = isrc_tmp.replace('–', '')
if not len(isrc_tmp) == 12:
count += 1
errormsgs.append('%8d -- ISRC (wrong length): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
if 'description' in identifier:
if identifier['description'].lower().startswith('isrc'):
count += 1
errormsgs.append('%8d -- ISRC Code (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
elif identifier['description'].lower().startswith('issrc'):
count += 1
errormsgs.append('%8d -- ISRC Code (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
for isrc in discogssmells.isrc_ftf:
if isrc in identifier['description'].lower():
count += 1
errormsgs.append('%8d -- ISRC Code (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
if identifier['type'] == 'Barcode':
pass
# check depósito legal in BaOI
if config_settings['check_deposito']:
if 'country' in release:
if release['country'] == 'Spain':
if identifier['type'] == 'Depósito Legal':
founddeposito = True
if v.strip().endswith('.'):
count += 1
errormsgs.append('%8d -- Depósito Legal (formatting): https://www.discogs.com/release/%s' % (count, str(release_id)))
if year != None:
# now try to find the year
depositoyear = None
if v.strip().endswith('℗'):
count += 1
errormsgs.append('%8d -- Depósito Legal (formatting, has ℗): https://www.discogs.com/release/%s' % (count, str(release_id)))
# ugly hack, remove ℗ to make at least be able to do some sort of check
v = v.strip().rsplit('℗', 1)[0]
# several separators, including some Unicode ones
for sep in ['-', '–', '/', '.', ' ', '\'', '_']:
try:
depositoyeartext = v.strip().rsplit(sep, 1)[-1]
if sep == '.' and len(depositoyeartext) == 3:
continue
if '.' in depositoyeartext:
depositoyeartext = depositoyeartext.replace('.', '')
depositoyear = int(depositoyeartext)
if depositoyear < 100:
# correct the year. This won't work correctly after 2099.
if depositoyear <= currentyear - 2000:
depositoyear += 2000
else:
depositoyear += 1900
break
except:
pass
# TODO, also allow (year), example: https://www.discogs.com/release/265497
if depositoyear != None:
if depositoyear < 1900:
count += 1
errormsgs.append("%8d -- Depósito Legal (impossible year): https://www.discogs.com/release/%s" % (count, str(release_id)))
elif depositoyear > currentyear:
count += 1
errormsgs.append("%8d -- Depósito Legal (impossible year): https://www.discogs.com/release/%s" % (count, str(release_id)))
elif year < depositoyear:
count += 1
errormsgs.append("%8d -- Depósito Legal (release date earlier): https://www.discogs.com/release/%s" % (count, str(release_id)))
else:
count += 1
errormsgs.append("%8d -- Depósito Legal (year not found): https://www.discogs.com/release/%s" % (count, str(release_id)))
elif identifier['type'] == 'Barcode':
for depositovalre in discogssmells.depositovalres:
if depositovalre.match(v.lower()) != None:
founddeposito = True
count += 1
errormsgs.append('%8d -- Depósito Legal (in Barcode): https://www.discogs.com/release/%s' % (count, str(release_id)))
break
else:
if v.startswith("Depósito"):
founddeposito = True
count += 1
errormsgs.append('%8d -- Depósito Legal (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
elif v.startswith("D.L."):
founddeposito = True
count += 1
errormsgs.append('%8d -- Depósito Legal (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
if 'description' in identifier:
found = False
for d in discogssmells.depositores:
result = d.search(identifier['description'].lower())
if result != None:
found = True
break
# sometimes the depósito value itself can be found in the free text field
if not found:
for depositovalre in discogssmells.depositovalres:
deposres = depositovalre.match(identifier['description'].lower())
if deposres != None:
found = True
break
if found:
founddeposito = True
count += 1
errormsgs.append('%8d -- Depósito Legal (BaOI): https://www.discogs.com/release/%s' % (count, str(release_id)))
# temporary hack, move to own configuration option
mould_sid_strict = False
if config_settings['check_mould_sid']:
if identifier['type'] == 'Mould SID Code':
if v.strip() != 'none':
# cleanup first for not so heavy formatting booboos
mould_tmp = v.strip().lower().replace(' ', '')
mould_tmp = mould_tmp.replace('-', '')
# some people insist on using ƒ instead of f
mould_tmp = mould_tmp.replace('ƒ', 'f')
res = discogssmells.mouldsidre.match(mould_tmp)
if res is None:
count += 1
errormsgs.append('%8d -- Mould SID Code (value): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
if mould_sid_strict:
mould_split = mould_tmp.split('ifpi', 1)[-1]
for ch in ['i', 'o', 's', 'q']:
if ch in mould_split[-2:]:
count += 1
errormsgs.append('%8d -- Mould SID Code (strict value): https://www.discogs.com/release/%s' % (count, str(release_id)))
# rough check to find SID codes for formats other than CD/CD-like
if len(formattexts) == 1:
for fmt in set(['Vinyl', 'Cassette', 'Shellac', 'File', 'VHS', 'DCC', 'Memory Stick', 'Edison Disc']):
if fmt in formattexts:
count += 1
errormsgs.append('%8d -- Mould SID Code (Wrong Format: %s): https://www.discogs.com/release/%s' % (count, fmt, str(release_id)))
break
if year != None:
if year < 1993:
count += 1
errormsgs.append('%8d -- SID Code (wrong year): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
if 'description' in identifier:
description = identifier['description'].lower()
# squash repeated spaces
description = re.sub('\s+', ' ', description)
description = description.strip()
if description in ['source identification code', 'sid', 'sid code', 'sid-code']:
count += 1
errormsgs.append('%8d -- Unspecified SID Code: https://www.discogs.com/release/%s' % (count, str(release_id)))
elif description in discogssmells.mouldsids:
count += 1
errormsgs.append('%8d -- Mould SID Code: https://www.discogs.com/release/%s' % (count, str(release_id)))
if config_settings['check_mastering_sid']:
if identifier['type'] == 'Mastering SID Code':
if v.strip() != 'none':
# cleanup first for not so heavy formatting booboos
master_tmp = v.strip().lower().replace(' ', '')
master_tmp = master_tmp.replace('-', '')
# some people insist on using ƒ instead of f
master_tmp = master_tmp.replace('ƒ', 'f')
res = discogssmells.masteringsidre.match(master_tmp)
if res is None:
count += 1
errormsgs.append('%8d -- Mastering SID Code (value): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
# rough check to find SID codes for formats other than CD/CD-like
if len(formattexts) == 1:
for fmt in set(['Vinyl', 'Cassette', 'Shellac', 'File', 'VHS', 'DCC', 'Memory Stick', 'Edison Disc']):
if fmt in formattexts:
count += 1
errormsgs.append('%8d -- Mastering SID Code (Wrong Format: %s): https://www.discogs.com/release/%s' % (count, fmt, str(release_id)))
if year != None:
if year < 1993:
count += 1
errormsgs.append('%8d -- SID Code (wrong year): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
if 'description' in identifier:
description = identifier['description'].lower()
# squash repeated spaces
description = re.sub('\s+', ' ', description)
description = description.strip()
if description in ['source identification code', 'sid', 'sid code', 'sid-code']:
count += 1
errormsgs.append('%8d -- Unspecified SID Code: https://www.discogs.com/release/%s' % (count, str(release_id)))
elif description in discogssmells.masteringsids:
count += 1
errormsgs.append('%8d -- Mastering SID Code: https://www.discogs.com/release/%s' % (count, str(release_id)))
elif description in ['sid code matrix', 'sid code - matrix', 'sid code (matrix)', 'sid-code, matrix', 'sid-code matrix', 'sid code (matrix ring)', 'sid code, matrix ring', 'sid code: matrix ring']:
count += 1
errormsgs.append('%8d -- Possible Mastering SID Code: https://www.discogs.com/release/%s' % (count, str(release_id)))
if config_settings['check_pkd']:
if 'country' in release:
if release['country'] == 'India':
if 'pkd' in v.lower() or "production date" in v.lower():
if year != None:
# try a few variants
pkdres = re.search("\d{1,2}/((?:19|20)?\d{2})", v)
if pkdres != None:
pkdyear = int(pkdres.groups()[0])
if pkdyear < 100:
# correct the year. This won't work correctly after 2099.
if pkdyear <= currentyear - 2000:
pkdyear += 2000
else:
pkdyear += 1900
if pkdyear < 1900:
count += 1
errormsgs.append("%8d -- Indian PKD (impossible year): https://www.discogs.com/release/%s" % (count, str(release_id)))
elif pkdyear > currentyear:
count += 1
errormsgs.append("%8d -- Indian PKD (impossible year): https://www.discogs.com/release/%s" % (count, str(release_id)))
elif year < pkdyear:
count += 1
errormsgs.append("%8d -- Indian PKD (release date earlier): https://www.discogs.com/release/%s" % (count, str(release_id)))
else:
count += 1
errormsgs.append('%8d -- India PKD code (no year): https://www.discogs.com/release/%s' % (count, str(release_id)))
else:
# now check the description
if 'description' in identifier:
description = identifier['description'].lower()
if 'pkd' in description or "production date" in description:
if year != None:
# try a few variants
pkdres = re.search("\d{1,2}/((?:19|20)?\d{2})", attrvalue)
if pkdres != None:
pkdyear = int(pkdres.groups()[0])
if pkdyear < 100:
# correct the year. This won't work correctly after 2099.
if pkdyear <= currentyear - 2000:
pkdyear += 2000
else:
pkdyear += 1900
if pkdyear < 1900:
count += 1
errormsgs.append("%8d -- Indian PKD (impossible year): https://www.discogs.com/release/%s" % (count, str(release_id)))
elif pkdyear > currentyear:
count += 1
errormsgs.append("%8d -- Indian PKD (impossible year): https://www.discogs.com/release/%s" % (count, str(release_id)))
elif year < pkdyear:
count += 1
errormsgs.append("%8d -- Indian PKD (release date earlier): https://www.discogs.com/release/%s" % (count, str(release_id)))
else:
count += 1
errormsgs.append('%8d -- India PKD code (no year): https://www.discogs.com/release/%s' % (count, str(release_id)))
# check Czechoslovak manufacturing dates
if config_settings['check_manufacturing_date_cs']:
# config hack, needs to be in its own configuration option
strict_cs = False
strict_cs = True
if 'country' in release:
if release['country'] == 'Czechoslovakia':
if 'description' in identifier:
description = identifier['description'].lower()
if 'date' in description:
if year != None:
manufacturing_date_res = re.search("(\d{2})\s+\d$", identifier['value'].rstrip())
if manufacturing_date_res != None:
manufacturing_year = int(manufacturing_date_res.groups()[0])
if manufacturing_year < 100:
manufacturing_year += 1900
if manufacturing_year > year:
count += 1
errormsgs.append("%8d -- Czechoslovak manufacturing date (release year wrong): https://www.discogs.com/release/%s" % (count, str(release_id)))
# possibly this check makes sense, but not always
elif manufacturing_year < year and strict_cs:
count += 1
errormsgs.append("%8d -- Czechoslovak manufacturing date (release year possibly wrong): https://www.discogs.com/release/%s" % (count, str(release_id)))
# finally check the notes for some errors
if 'notes' in release:
if '카지노' in release['notes']:
# Korean casino spam that pops up every once in a while
errormsgs.append('Spam: https://www.discogs.com/release/%s' % str(release_id))
if 'country' in release:
if release['country'] == 'Spain':
if config_settings['check_deposito'] and not founddeposito:
# sometimes "deposito legal" can be found in the "notes" section
content_lower = release['notes'].lower()
for d in discogssmells.depositores:
result = d.search(content_lower)
if result != None:
count += 1
found = True
errormsgs.append('%8d -- Depósito Legal (Notes): https://www.discogs.com/release/%s' % (count, str(release_id)))
break
if config_settings['check_html']:
# see https://support.discogs.com/en/support/solutions/articles/13000014661-how-can-i-format-text-
if '<a href="http://www.discogs.com/release/' in release['notes'].lower():
count += 1
errormsgs.append('%8d -- old link (Notes): https://www.discogs.com/release/%s' % (count, str(release_id)))
if config_settings['check_creative_commons']:
ccfound = False
for cc in discogssmells.creativecommons:
if cc in release['notes']:
count += 1
errormsgs.append('%8d -- Creative Commons reference (%s): https://www.discogs.com/release/%s' % (count, cc, str(release)))
ccfound = True
break
if not ccfound:
if 'creative commons' in reales['notes'].lower():
count += 1
errormsgs.append('%8d -- Creative Commons reference: https://www.discogs.com/release/%s' % (count, str(release)))
ccfound = True
break
for e in errormsgs:
print(e)
if config_settings['use_notify_send']:
p = subprocess.Popen(['notify-send', "-t", "3000", "Error", e], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
(stanout, stanerr) = p.communicate()
sys.stdout.flush()
return count
def main(argv):
parser = argparse.ArgumentParser()
# the following options are provided on the commandline
parser.add_argument("-c", "--config", action="store", dest="cfg", help="path to configuration file", metavar="FILE")
parser.add_argument("-s", "--startvalue", action="store", dest="startvalue", help="start value for releases", metavar="STARTVALUE")
parser.add_argument("-l", "--latest", action="store", dest="latest_value", help="value for latest release", metavar="LATEST")
args = parser.parse_args()
# some checks for the configuration file
if args.cfg is None:
parser.error("Configuration file missing")
if not os.path.exists(args.cfg):
parser.error("Configuration file does not exist")
config = configparser.ConfigParser()
configfile = open(args.cfg, 'r')
try:
config.read_file(configfile)
except Exception:
print("Cannot read configuration file", file=sys.stderr)
sys.exit(1)
startvalue = None
# check for a startvalue
if args.startvalue != None:
try:
startvalue = int(args.startvalue)
except:
parser.error("start value is not a valid integer, exciting")
latest_release = None
# check for a startvalue
if args.latest_value != None:
try:
latest_release = int(args.latest_value)
except:
parser.error("latest value is not a valid integer, exciting")
# process the configuration file and store settings
config_settings = {}
for section in config.sections():
if section == 'cleanup':
# store settings for depósito legal checks
try:
if config.get(section, 'deposito') == 'yes':
config_settings['check_deposito'] = True
else:
config_settings['check_deposito'] = False
except Exception:
config_settings['check_deposito'] = True
# store settings for rights society checks
try:
if config.get(section, 'rights_society') == 'yes':
config_settings['check_rights_society'] = True
else:
config_settings['check_rights_society'] = False
except Exception:
config_settings['check_rights_society'] = True
# store settings for label code checks
try:
if config.get(section, 'label_code') == 'yes':
config_settings['check_label_code'] = True
else:
config_settings['check_label_code'] = False
except Exception:
config_settings['check_label_code'] = True
# store settings for label name checks
try:
if config.get(section, 'label_name') == 'yes':
config_settings['check_label_name'] = True
else:
config_settings['check_label_name'] = False
except Exception:
config_settings['check_label_name'] = True
# store settings for ISRC checks
try:
if config.get(section, 'isrc') == 'yes':
config_settings['check_isrc'] = True
else:
config_settings['check_isrc'] = False
except Exception:
config_settings['check_isrc'] = True
# store settings for ASIN checks
try:
if config.get(section, 'asin') == 'yes':
config_settings['check_asin'] = True
else:
config_settings['check_asin'] = False
except Exception:
config_settings['check_asin'] = True
# store settings for mastering SID checks
try:
if config.get(section, 'mastering_sid') == 'yes':
config_settings['check_mastering_sid'] = True
else:
config_settings['check_mastering_sid'] = False
except Exception:
config_settings['check_mastering_sid'] = True
# store settings for mould SID checks
try:
if config.get(section, 'mould_sid') == 'yes':
config_settings['check_mould_sid'] = True
else:
config_settings['check_mould_sid'] = False
except Exception:
config_settings['check_mould_sid'] = True
# store settings for SPARS Code checks
try:
if config.get(section, 'spars') == 'yes':
config_settings['check_spars_code'] = True
else:
config_settings['check_spars_code'] = False
except Exception:
config_settings['check_spars_code'] = True
# store settings for Indian PKD checks
try:
if config.get(section, 'pkd') == 'yes':
config_settings['check_pkd'] = True
else:
config_settings['check_pkd'] = False
except Exception:
config_settings['check_pkd'] = True
# check for Czechoslovak manufacturing dates
try:
if config.get(section, 'manufacturing_date_cs') == 'yes':
config_settings['check_manufacturing_date_cs'] = True
else:
config_settings['check_manufacturing_date_cs'] = False
except Exception:
config_settings['check_manufacturing_date_cs'] = True
# check for Czechoslovak and Czech spelling (0x115 used instead of 0x11B)
try:
if config.get(section, 'spelling_cs') == 'yes':
config_settings['check_spelling_cs'] = True
else:
config_settings['check_spelling_cs'] = False
except Exception:
config_settings['check_spelling_cs'] = True
# store settings for tracklisting checks, default True
try:
if config.get(section, 'tracklisting') == 'yes':
config_settings['check_tracklisting'] = True
else:
config_settings['check_tracklisting'] = False
except Exception:
config_settings['check_tracklisting'] = True
# store settings for credits list checks
try:
if config.get(section, 'credits') == 'yes':
creditsfile = config.get(section, 'creditsfile')
if os.path.exists(creditsfile):
config_settings['creditsfile'] = creditsfile
config_settings['check_credits'] = True
else:
config_settings['check_credits'] = False
except Exception:
config_settings['check_credits'] = False
# store settings for URLs in Notes checks
try:
if config.get(section, 'html') == 'yes':
config_settings['check_html'] = True
else:
config_settings['check_html'] = False
except Exception:
config_settings['check_html'] = True
# month is 00 check: default is False
try:
if config.get(section, 'month') == 'yes':
config_settings['check_month'] = True
else:
config_settings['check_month'] = False
except Exception:
config_settings['check_month'] = False
# year is wrong check: default is False
try:
if config.get(section, 'year') == 'yes':
config_settings['check_year'] = True
else:
config_settings['check_year'] = False
except Exception:
config_settings['check_year'] = False
# reporting all: default is False
try:
if config.get(section, 'reportall') == 'yes':
config_settings['reportall'] = True
else:
config_settings['reportall'] = False
except Exception:
config_settings['reportall'] = False
# debug: default is False
try:
if config.get(section, 'debug') == 'yes':
config_settings['debug'] = True
else:
config_settings['debug'] = False
except Exception:
config_settings['debug'] = False
# report creative commons references: default is False
try:
if config.get(section, 'creative_commons') == 'yes':
config_settings['check_creative_commons'] = True
else:
config_settings['check_creative_commons'] = False
except Exception:
config_settings['check_creative_commons'] = False
elif section == 'api':
# data directory to store JSON files
try:
storedir = config.get(section, 'storedir')
if not os.path.exists(os.path.normpath(storedir)):
config_settings['storedir'] = None
else:
# test if the directory is writable
testfile = tempfile.mkstemp(dir=storedir)
os.fdopen(testfile[0]).close()
os.unlink(testfile[1])
config_settings['storedir'] = storedir
except Exception:
config_settings['storedir'] = None
break
try:
token = config.get(section, 'token')
config_settings['token'] = token
except Exception:
config_settings['token'] = None
try: