Browse code
chore: 2->3
fiddlerwoaroof authored on 25/10/2022 18:48:22
Showing 1 changed files
Showing 1 changed files
... | ... |
@@ -46,7 +46,7 @@ parser.add_argument('destination') |
46 | 46 |
args = parser.parse_args() |
47 | 47 |
|
48 | 48 |
destination = args.destination |
49 |
-print 'copying music to, %s' % destination |
|
49 |
+print('copying music to, %s' % destination) |
|
50 | 50 |
|
51 | 51 |
import sys |
52 | 52 |
|
... | ... |
@@ -54,30 +54,40 @@ class PathFinder(object): |
54 | 54 |
def __init__(self): |
55 | 55 |
pass |
56 | 56 |
|
57 |
+ def construct_tag_map(self, data): |
|
58 |
+ tag_map = {} |
|
59 |
+ for (tag, _) in data.tags: |
|
60 |
+ tag_map[tag.lower()] = tag |
|
61 |
+ return tag_map |
|
62 |
+ |
|
57 | 63 |
def get_path(self, data, orig_name): |
64 |
+ tag_map = self.construct_tag_map(data) |
|
65 |
+ print(tag_map, tag_map['title'], data.get(tag_map['title'])) |
|
58 | 66 |
orig_name = orig_name.rpartition('.')[0] |
59 |
- title=self.clean(data.get('title', ['Unknown Title'])[0].encode('utf-8')) |
|
67 |
+ title=self.clean(data.get(tag_map['title'], ['Unknown Title'])[0]) |
|
60 | 68 |
if title.strip() == '': title = orig_name |
61 |
- album=self.clean(data.get('album', ['Unknown Album'])[0].encode('utf-8')) |
|
69 |
+ album=self.clean(data.get(tag_map['album'], ['Unknown Album'])[0]) |
|
62 | 70 |
if album.strip() == '': album = 'Unknown Album' |
63 | 71 |
|
64 |
- if 'performer' in data: artist = data['performer'][0].encode('utf-8') |
|
65 |
- elif 'conductor' in data: artist = data['conductor'][0].encode('utf-8') |
|
66 |
- else: artist = data.get('artist', ['Unknown Artist'])[0].encode('utf-8') |
|
72 |
+ if 'albumartist' in data: artist = data[tag_map['albumartist']][0] |
|
73 |
+ elif 'performer' in data: artist = data[tag_map['performer']][0] |
|
74 |
+ elif 'conductor' in data: artist = data[tag_map['conductor']][0] |
|
75 |
+ else: artist = data.get(tag_map['artist'], ['Unknown Artist'])[0] |
|
67 | 76 |
artist = self.clean(artist) |
68 | 77 |
if artist.strip() == '': artist = 'Unknown Artist' |
69 | 78 |
|
70 |
- tracknumber=self.clean(data.get('tracknumber', ['--'])[0].encode('utf-8')) |
|
79 |
+ tracknumber=self.clean(data.get(tag_map['tracknumber'], ['--'])[0]) |
|
71 | 80 |
if tracknumber != '--': |
72 | 81 |
try: |
73 | 82 |
tracknumber = tracknumber.partition('_')[0] |
74 | 83 |
tracknumber = '%02d' % int(tracknumber) |
75 | 84 |
except ValueError: |
76 | 85 |
pass |
77 |
- discnumber=self.clean(data.get('discnumber', ['--'])[0].partition('/')[0].encode('utf-8')) |
|
78 |
- if discnumber != '--': discnumber = '%02d' % int(discnumber) |
|
86 |
+ discnumber=self.clean(data.get(tag_map['discnumber'], ['--'])[0].partition('/')[0]) |
|
87 |
+ print(f'discnumber is: {discnumber}') |
|
88 |
+ if discnumber.strip() not in {'', '--'}: discnumber = '%02d' % int(discnumber) |
|
79 | 89 |
result =[ os.path.join(artist[0].upper(),artist,album), '%s_%s' % (tracknumber, title) ] |
80 |
- if discnumber != '--': |
|
90 |
+ if discnumber.strip() not in {'', '--'}: |
|
81 | 91 |
result[1] = '%s_%s' % (discnumber, result[1]) |
82 | 92 |
return result |
83 | 93 |
|
... | ... |
@@ -107,23 +117,23 @@ for line in sys.stdin: |
107 | 117 |
|
108 | 118 |
path = os.path.join(destination, path) |
109 | 119 |
|
110 |
- checkname = '%s.%s' % ('__'.join(filter(None, [name, suf])), ext) |
|
120 |
+ checkname = '%s.%s' % ('__'.join([_f for _f in [name, suf] if _f]), ext) |
|
111 | 121 |
|
112 |
- while os.path.exists(os.path.join(path, '%s.%s' % ('__'.join(filter(None, [name, suf])), ext))): |
|
122 |
+ while os.path.exists(os.path.join(path, '%s.%s' % ('__'.join([_f for _f in [name, suf] if _f]), ext))): |
|
113 | 123 |
x += 1 |
114 | 124 |
suf = '%02d' % x |
115 | 125 |
|
116 |
- name = '%s.%s' % ('__'.join(filter(None, [name, suf])), ext) |
|
126 |
+ name = '%s.%s' % ('__'.join([_f for _f in [name, suf] if _f]), ext) |
|
117 | 127 |
try: |
118 | 128 |
os.makedirs(path) |
119 |
- except OSError, e: |
|
129 |
+ except OSError as e: |
|
120 | 130 |
if e.errno == 17: |
121 | 131 |
pass |
122 | 132 |
else: |
123 | 133 |
raise |
124 | 134 |
|
125 |
- print os.path.join(path, name) |
|
135 |
+ print(os.path.join(path, name)) |
|
126 | 136 |
shutil.copy(line, os.path.join(path, name)) |
127 |
- except Exception, e: |
|
128 |
- print >> sys.stderr, 'Error Processing: %s' % line,e |
|
129 |
- print 'Error Processing: %s' % line,e |
|
137 |
+ except Exception as e: |
|
138 |
+ print('Error Processing: %s' % line,e, file=sys.stderr) |
|
139 |
+ print('Error Processing: %s' % line,e) |