-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.py
More file actions
658 lines (497 loc) · 24.1 KB
/
Copy pathmain.py
File metadata and controls
658 lines (497 loc) · 24.1 KB
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
#!/usr/bin/env python3
# coding: utf-8
import wx
import os
import sys
import io
import pyperclip
import audiofile
import scinfo
from urllib.request import urlopen
# リソースアクセス用
def ResourcePath(filename):
if hasattr(sys, "_MEIPASS"):
return os.path.join(sys._MEIPASS, filename)
return os.path.join(filename)
class MyFrame(wx.Frame):
def __init__(self):
wx.Frame.__init__(self, None, title="FreeDLHelper v1.4.4", size=(900, 550))
# ** ステータスバー **
self.CreateStatusBar()
self.SetStatusText('音声ファイルをドラッグ&ドロップしてください')
self.GetStatusBar().SetBackgroundColour(None)
# ** アイコン **
#tbi = wx.adv.TaskBarIcon()
icon = wx.Icon(ResourcePath('Resources/fdh_v2.ico'), wx.BITMAP_TYPE_ICO)
self.SetIcon(icon)
# scinfo, audiofileのインスタンス作成
sc = scinfo.SoundCloudInfo()
af = audiofile.AudioFile()
# ** 構築 ** sc, afは参照渡し
root_panel = wx.Panel(self)
# 曲情報
self.ai_panel = AudioInfoPanel(root_panel)
# アートワーク
self.aw_panel = ArtworkPanel(root_panel, imgsize=(300, 300))
# URL入力欄
self.url_panel = URLTextPanel(root_panel)
# ファイルパス
self.fr_panel = FileRefPanel(root_panel, sc, af)
# ボタン
self.bt_panel = ButtonPanel(root_panel, sc, af)
root_layout = wx.GridBagSizer()
root_layout.Add(self.aw_panel, (0, 0), (2, 1), flag=wx.ALL, border=10)
root_layout.Add(self.fr_panel, (0, 1), (1, 1), flag=wx.EXPAND | wx.ALL, border=10)
root_layout.Add(self.ai_panel, (1, 1), (1, 1), flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10)
root_layout.Add(self.url_panel, (2, 0), (1, 2), flag=wx.EXPAND | wx.LEFT | wx.RIGHT | wx.BOTTOM, border=10)
root_layout.Add(self.bt_panel, (3, 0), (1, 2), flag=wx.EXPAND | wx.LEFT | wx.RIGHT, border=10)
root_layout.AddGrowableCol(1)
root_panel.SetSizer(root_layout)
root_layout.Fit(root_panel)
# ドラッグ&ドロップの設定
fdt = MyFileDropTarget(root_panel, sc, af)
root_panel.SetDropTarget(fdt)
self.Show()
self.Center() # 画面中央に表示
class FileRefPanel(wx.Panel):
""" ファイルパス入力部分 """
def __init__(self, parent, sc, af):
super().__init__(parent)
# scinfo, audiofileのインスタンス(参照)
self.sc = sc
self.af = af
# AudioInfoPanel内のテキストボックス
self.cb_title = parent.GetParent().ai_panel.cb_title
self.cb_album = parent.GetParent().ai_panel.cb_album
self.cb_artist = parent.GetParent().ai_panel.cb_artist
self.cb_genre = parent.GetParent().ai_panel.cb_genre
self.tc_comment = parent.GetParent().ai_panel.tc_comment
# URL入力欄
self.tc_url = parent.GetParent().url_panel.tc_url
# ArtworkPanelの画像設定メソッド
self.set_img = parent.GetParent().aw_panel.set_img
s_box = wx.StaticBox(self, -1, 'ファイル')
# ** 各項目 **
self.tc_file = wx.TextCtrl(self, -1)
bt_file = wx.Button(self, -1, label='ファイル選択')
# イベント設定: ダイアログ表示
bt_file.Bind(wx.EVT_BUTTON, self.click_bt_file)
# 配置
grid = wx.FlexGridSizer(cols=2, gap=(0, 0))
grid.Add(self.tc_file, flag=wx.EXPAND | wx.ALL, border=10)
grid.Add(bt_file, flag=wx.ALL, border=10)
# 引き伸ばし
grid.AddGrowableCol(0)
layout = wx.StaticBoxSizer(s_box, wx.HORIZONTAL)
layout.Add(grid, 1)
self.SetSizer(layout)
def click_bt_file(self, event):
"""
ダイアログ表示・パス取得イベント
"""
# 曲情報のドロップダウンリストを初期化
titlelist = ['']
albumlist = ['']
artistlist = ['']
genrelist = ['']
# ダイアログ設定
file_filter = \
"audio file(*.wav;*.aif;*.aiff;*.aifc;*.afc;*.flac;*.fla;*.mp3;*.m4a) \
| *.wav;*.aif;*.aiff;*.aifc;*.afc;*.flac;*.fla;*.mp3;*.m4a; \
| all file(*.*) | *.*"
dialog = wx.FileDialog(self, 'ファイルを選択してください', wildcard=file_filter)
# ファイルが選択された場合
if dialog.ShowModal() == wx.ID_OK:
# アートワークURLを初期化
self.sc.artwork_url = ''
# パスを取得
filepath = dialog.GetPath()
# ファイル読み込み
try:
self.GetTopLevelParent().SetStatusText('ファイルの読み込み・変換中...')
self.af.info(filepath)
# アートワークを更新
self.set_img(self.af.artwork)
# ジャンルを入力
genrelist = [self.af.genre]
self.cb_genre.SetItems(genrelist)
self.cb_genre.SetValue(self.af.genre)
self.GetTopLevelParent().SetStatusText(
'ファイルの読み込み・変換が完了しました。SoundCloudのURLを入力し、"情報取得"を押してください')
except audiofile.FileFormatError:
wx.MessageBox('ファイルが未対応のフォーマットです', '読み込みエラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('読み込みエラーです。ファイルを確認してください')
except audiofile.FFmpegNotFoundError:
wx.MessageBox('ffmpegが見つかりませんでした', '変換エラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('変換エラーです。ffmpegを本アプリと同じディレクトリにインストールしてください')
except audiofile.JsonLoadError:
wx.MessageBox('config.jsonの読み込みに失敗しました', '読み込みエラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('読み込みエラーです。config.jsonを確認してください')
except audiofile.CommandFailedError:
wx.MessageBox('ffmpegのコマンド実行に失敗しました', '変換エラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('変換エラーです。config.json内の設定を確認してください')
# アートワークを初期状態に
self.set_img()
# ジャンルを初期状態に
self.cb_genre.SetItems(genrelist)
self.cb_genre.SetValue('選択してください')
# テキストボックスにパス設定
self.tc_file.SetValue(self.af.filepath)
# ジャンル以外のドロップダウンリストを更新
titlelist = [self.af.title]
albumlist = [self.af.album]
artistlist = [self.af.artist]
self.cb_title.SetItems(titlelist)
self.cb_album.SetItems(albumlist)
self.cb_artist.SetItems(artistlist)
# 曲情報を入力
self.cb_title.SetValue(self.af.title)
self.cb_album.SetValue(self.af.album)
self.cb_artist.SetValue(self.af.artist)
self.tc_comment.SetValue(self.af.comment)
# URL入力欄をクリア
self.tc_url.Clear()
# ダイアログを破棄
dialog.Destroy()
class MyFileDropTarget(wx.FileDropTarget):
""" ドラッグ&ドロップ """
def __init__(self, parent, sc, af):
wx.FileDropTarget.__init__(self)
self.parent = parent
# scinfo, audiofileのインスタンス(参照)
self.sc = sc
self.af = af
# AudioInfoPanel内のテキストボックス
self.cb_title = parent.GetParent().ai_panel.cb_title
self.cb_album = parent.GetParent().ai_panel.cb_album
self.cb_artist = parent.GetParent().ai_panel.cb_artist
self.cb_genre = parent.GetParent().ai_panel.cb_genre
self.tc_comment = parent.GetParent().ai_panel.tc_comment
# URL入力欄
self.tc_url = parent.GetParent().url_panel.tc_url
# FileRefPanelのテキストボックス
self.tc_file = parent.GetParent().fr_panel.tc_file
# ArtworkPanelの画像設定メソッド
self.set_img = parent.GetParent().aw_panel.set_img
def OnDropFiles(self, x, y, filenames):
# 各リストを初期化
titlelist = ['']
albumlist = ['']
artistlist = ['']
genrelist = ['']
# アートワークURLを初期化
self.sc.artwork_url = ''
# D&Dされたパスを取得
dnd_filepath = filenames[0]
# ファイル読み込み
try:
self.parent.GetTopLevelParent().SetStatusText('ファイルの読み込み・変換中...')
self.af.info(dnd_filepath)
# アートワークを更新
self.set_img(self.af.artwork)
# ジャンルを入力
genrelist = [self.af.genre]
self.cb_genre.SetItems(genrelist)
self.cb_genre.SetValue(self.af.genre)
self.parent.GetTopLevelParent().SetStatusText(
'ファイルの読み込みが完了しました。SoundCloudのURLを入力し、"情報取得"を押してください')
except audiofile.FileFormatError:
wx.MessageBox('ファイルが未対応のフォーマットです', '読み込みエラー', wx.ICON_ERROR)
self.parent.GetTopLevelParent().SetStatusText('読み込みエラーです。ファイルを確認してください')
except audiofile.FFmpegNotFoundError:
wx.MessageBox('ffmpegが見つかりませんでした', '変換エラー', wx.ICON_ERROR)
self.parent.GetTopLevelParent().SetStatusText('変換エラーです。ffmpegを本アプリと同じディレクトリにインストールしてください')
except audiofile.JsonLoadError:
wx.MessageBox('config.jsonの読み込みに失敗しました', '読み込みエラー', wx.ICON_ERROR)
self.parent.GetTopLevelParent().SetStatusText('読み込みエラーです。config.jsonを確認してください')
except audiofile.FileAlreadyExistsError:
wx.MessageBox('出力先ディレクトリに変換後のファイルが存在します', '変換エラー', wx.ICON_WARNING)
self.parent.GetTopLevelParent().SetStatusText('変換エラーです。変換する場合は変換後のファイルをディレクトリから削除してください')
except audiofile.CommandFailedError:
wx.MessageBox('ffmpegのコマンド実行に失敗しました', '変換エラー', wx.ICON_ERROR)
self.parent.GetTopLevelParent().SetStatusText('変換エラーです。config.json内の設定を確認してください')
# アートワークを初期状態に
self.set_img()
# ジャンルを初期状態に
self.cb_genre.SetItems(genrelist)
self.cb_genre.SetValue('選択してください')
# テキストボックスにパス設定
self.tc_file.SetValue(self.af.filepath)
# ジャンル以外のドロップダウンリストを更新
titlelist = [self.af.title]
albumlist = [self.af.album]
artistlist = [self.af.artist]
self.cb_title.SetItems(titlelist)
self.cb_album.SetItems(albumlist)
self.cb_artist.SetItems(artistlist)
# 曲情報を入力
self.cb_title.SetValue(self.af.title)
self.cb_album.SetValue(self.af.album)
self.cb_artist.SetValue(self.af.artist)
self.tc_comment.SetValue(self.af.comment)
# URL入力欄をクリア
self.tc_url.Clear()
return True
class ArtworkPanel(wx.Panel):
""" アートワーク画像表示部分 """
def __init__(self, parent, imgsize):
super().__init__(parent)
self.imgsize = imgsize
image = ResourcePath('Resources/dnd_file.jpg')
img = wx.Image(image)
# サイズ・品質
newimg = img.Scale(self.imgsize[0], self.imgsize[1], wx.IMAGE_QUALITY_HIGH)
self.img_panel = wx.StaticBitmap(self, -1, wx.Bitmap(newimg))
# タイトル付きBoxSizer
box = wx.StaticBox(self, -1, 'アートワーク')
# 構築
layout = wx.StaticBoxSizer(box, wx.VERTICAL)
layout.Add(self.img_panel)
self.SetSizer(layout)
img.Destroy()
def set_img(self, img_data=-1):
"""
画像変更用
Parameters
----------
img_data : str or bytes or None
画像のURL(str), bytes型のデータ, ない場合はNone
"""
# URL(文字列)の場合
if type(img_data) is str:
image = urlopen(img_data).read()
image = io.BytesIO(image)
# 画像データ(bytes)の場合
elif type(img_data) is bytes:
image = io.BytesIO(img_data)
# 画像がない(None)場合
elif img_data == None:
image = ResourcePath('Resources/no_artwork.jpg')
# 引数なし
elif img_data == -1:
image = ResourcePath('Resources/dnd_file.jpg')
img = wx.Image(image)
try:
# サイズ・品質
newimg = img.Scale(self.imgsize[0], self.imgsize[1], wx.IMAGE_QUALITY_HIGH)
except:
# 画像を読み込めなかった場合
image = ResourcePath('Resources/no_artwork.jpg')
img = wx.Image(image)
newimg = img.Scale(self.imgsize[0], self.imgsize[1], wx.IMAGE_QUALITY_HIGH)
# 画像変更
self.img_panel.SetBitmap(wx.Bitmap(newimg))
img.Destroy()
class AudioInfoPanel(wx.Panel):
"""
曲情報パネル
Attributes
----------
cb_title : wx.ComboBox
タイトルのテキストボックス
cb_album : wx.ComboBox
アルバム名のテキストボックス
cb_artist : wx.ComboBox
アーティスト名のテキストボックス
cb_genre : wx.ComboBox
ジャンル一覧
tc_comment : wx.TextCtrl
コメントのテキストボックス
"""
def __init__(self, parent):
super().__init__(parent)
# ** 各項目 **
st_title = wx.StaticText(self, -1, 'タイトル: ')
self.cb_title = wx.ComboBox(self, -1, choices=[''], style=wx.CB_DROPDOWN)
st_album = wx.StaticText(self, -1, 'アルバム名: ')
self.cb_album = wx.ComboBox(self, -1, choices=[''], style=wx.CB_DROPDOWN)
st_artist = wx.StaticText(self, -1, 'アーティスト名: ')
self.cb_artist = wx.ComboBox(self, -1, choices=[''], style=wx.CB_DROPDOWN)
st_genre = wx.StaticText(self, -1, 'ジャンル: ')
self.cb_genre = wx.ComboBox(self, -1, '選択してください', choices=[''], style=wx.CB_DROPDOWN)
st_comment = wx.StaticText(self, -1, 'コメント: ')
self.tc_comment = wx.TextCtrl(self, -1, style=wx.TE_MULTILINE)
# タイトル付きBoxSizer
s_box = wx.StaticBox(self, -1, '曲情報')
# 配置
grid = wx.FlexGridSizer(cols=2, gap=(0, 0))
grid.Add(st_title, flag=wx.ALL, border=10)
grid.Add(self.cb_title, flag=wx.EXPAND | wx.ALL, border=10)
grid.Add(st_album, flag=wx.ALL, border=10)
grid.Add(self.cb_album, flag=wx.EXPAND | wx.ALL, border=10)
grid.Add(st_artist, flag=wx.ALL, border=10)
grid.Add(self.cb_artist, flag=wx.EXPAND | wx.ALL, border=10)
grid.Add(st_genre, flag=wx.ALL, border=10)
grid.Add(self.cb_genre, flag=wx.EXPAND | wx.ALL, border=10)
grid.Add(st_comment, flag=wx.ALL, border=10)
grid.Add(self.tc_comment, flag=wx.EXPAND | wx.ALL, border=10)
# 引き伸ばし
grid.AddGrowableCol(1)
# 構築
layout = wx.StaticBoxSizer(s_box, wx.HORIZONTAL)
layout.Add(grid, 1)
self.SetSizer(layout)
class URLTextPanel(wx.Panel):
"""
URL入力パネル
Attributes
----------
tc_url : wx.TextCtrl
URLのテキストボックス
"""
def __init__(self, parent):
super().__init__(parent)
s_box = wx.StaticBox(self, -1, 'SoundCloudのURL')
# ** 各項目 **
self.tc_url = wx.TextCtrl(self, -1)
bt_url_paste = wx.Button(self, -1, label='貼り付け')
bt_url_clear = wx.Button(self, -1, label='クリア')
bt_url_paste.Bind(wx.EVT_BUTTON, self.click_bt_url_paste)
bt_url_clear.Bind(wx.EVT_BUTTON, self.click_bt_url_clear)
# 配置
grid = wx.FlexGridSizer(cols=3, gap=(0, 0))
grid.Add(self.tc_url, flag=wx.EXPAND | wx.ALL, border=10)
grid.Add(bt_url_paste, flag=wx.ALL, border=10)
grid.Add(bt_url_clear, flag=wx.ALL, border=10)
# 引き伸ばし
grid.AddGrowableCol(0)
layout = wx.StaticBoxSizer(s_box, wx.HORIZONTAL)
layout.Add(grid, 1)
self.SetSizer(layout)
def click_bt_url_paste(self, event):
self.tc_url.SetValue(pyperclip.paste())
def click_bt_url_clear(self, event):
""" URL入力欄をクリア """
self.tc_url.Clear()
class ButtonPanel(wx.Panel):
""" ボタン用 """
def __init__(self, parent, sc, af):
super().__init__(parent)
# scinfo, audiofileのインスタンス(参照)
self.sc = sc
self.af = af
# AudioInfoPanel内のテキストボックス
self.cb_title = parent.GetParent().ai_panel.cb_title
self.cb_album = parent.GetParent().ai_panel.cb_album
self.cb_artist = parent.GetParent().ai_panel.cb_artist
self.cb_genre = parent.GetParent().ai_panel.cb_genre
self.tc_comment = parent.GetParent().ai_panel.tc_comment
# URLPanelのテキストボックス
self.tc_url = parent.GetParent().url_panel.tc_url
# ArtworkPanelの画像設定メソッド
self.set_img = parent.GetParent().aw_panel.set_img
# ** 各項目 **
bt_get = wx.Button(self, -1, label='情報取得')
bt_edit = wx.Button(self, -1, label='書き込み')
# イベント設定
bt_get.Bind(wx.EVT_BUTTON, self.click_bt_get)
bt_edit.Bind(wx.EVT_BUTTON, self.click_bt_edit)
# 配置
grid = wx.FlexGridSizer(cols=2, gap=(0, 0))
grid.Add(bt_get, flag=wx.LEFT, border=200)
grid.Add(bt_edit, flag=wx.RIGHT, border=200)
grid.AddGrowableCol(0)
self.SetSizer(grid)
def click_bt_get(self, event):
""" SoundCloudから情報取得 """
# 各リストを初期化
titlelist = ['']
albumlist = ['']
artistlist = ['']
genrelist = ['']
if self.af.filepath == '':
wx.MessageBox('ファイルを先に選択してください', 'ファイル未選択', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('音声ファイルをドラッグ&ドロップしてください')
return
# テキストボックスからURL取得
url = self.tc_url.GetValue()
url = url.split('?')[0] # クエリパラメータを省略したURL
# 情報取得
try:
# バー更新
self.GetTopLevelParent().SetStatusText('SoundCloudから情報を取得しています')
self.sc.get(url)
# ドロップダウンリストを更新
titlelist = [self.af.title] + [self.sc.title]
albumlist = [self.af.album]
artistlist = [self.af.artist] + [self.sc.artist]
genrelist = [self.af.genre] if not self.af.genre == '' else []
genrelist += [self.sc.maintag] if not self.sc.maintag == '' else []
genrelist += self.sc.taglist
self.cb_title.SetItems(titlelist)
self.cb_album.SetItems(albumlist)
self.cb_artist.SetItems(artistlist)
self.cb_genre.SetItems(genrelist)
# 曲情報を入力: 元の情報は保持
if self.af.title == '':
self.cb_title.SetValue(self.sc.title)
else:
self.cb_title.SetValue(self.af.title)
self.cb_album.SetValue(self.af.album)
if self.af.artist == '':
self.cb_artist.SetValue(self.sc.artist)
else:
self.cb_artist.SetValue(self.af.artist)
if self.af.genre == '':
if not self.sc.maintag == '':
self.cb_genre.SetLabel(self.sc.maintag)
elif not self.sc.taglist == []:
self.cb_genre.SetLabel('選択してください')
else:
self.cb_genre.SetLabel('')
else:
self.cb_genre.SetLabel(self.af.genre)
# すでにSCのURLがコメントにある場合
if url in self.tc_comment.GetValue():
url = ''
# 既にコメントがあるときは、改行してURL挿入
elif self.tc_comment.GetValue() != '':
url = '\n' + url
self.tc_comment.AppendText(url)
# アートワークを更新
self.set_img(self.sc.artwork_url)
self.GetTopLevelParent().SetStatusText('曲情報を確認・編集し、"書き込み"を押してください')
# エラー
except scinfo.NotSoundCloudURL:
wx.MessageBox('SoundCloudのURLを入力してください', '読み込みエラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('情報を取得できませんでした')
except scinfo.NotTrackURL:
wx.MessageBox('曲以外のURLが入力されています', '読み込みエラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('情報を取得できませんでした')
except scinfo.OfflineError:
wx.MessageBox('オフラインでは情報取得できません\nオンラインで実行してください',
'読み込みエラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('情報を取得できませんでした')
def click_bt_edit(self, event):
""" 曲情報書き込み """
# ファイル未選択時
if self.af.filepath == '':
wx.MessageBox('ファイルを選択してください', 'ファイル未選択', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('音声ファイルをドラッグ&ドロップしてください')
return
# 曲情報を設定
self.af.title = self.cb_title.GetValue()
self.af.album = self.cb_album.GetValue()
self.af.artist = self.cb_artist.GetValue()
self.af.genre = self.cb_genre.GetValue()
self.af.comment = self.tc_comment.GetValue()
self.af.artwork_url = self.sc.artwork_url
try:
self.af.edit()
wx.MessageBox('書き込みが完了しました', '書き込み完了', wx.OK)
self.GetTopLevelParent().SetStatusText('書き込み完了')
except FileNotFoundError:
wx.MessageBox('ファイルが見つからないため、曲情報の書き込みができませんでした',
'書き込みエラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('書き込みエラーが発生しました: ファイルが見つかりません')
except audiofile.URLOpenError:
wx.MessageBox('オフラインか、その他の理由で画像の書き込みができませんでした',
'書き込みエラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('書き込みエラーが発生しました: オンラインになっているか確認してください')
except:
wx.MessageBox('曲情報の書き込みができませんでした', '書き込みエラー', wx.ICON_ERROR)
self.GetTopLevelParent().SetStatusText('書き込みエラーが発生しました')
if __name__ == '__main__':
app = wx.App()
frame = MyFrame()
app.MainLoop()