Skip to content

Commit b011300

Browse files
committed
Update: Ruff を導入し、コードベースをフォーマット
1 parent 9442f7d commit b011300

File tree

9 files changed

+409
-261
lines changed

9 files changed

+409
-261
lines changed

.vscode/settings.json

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,13 @@
11
{
2+
// 保存時に Ruff による自動フォーマットを行う
3+
"[python]": {
4+
"editor.codeActionsOnSave": {
5+
"source.fixAll.ruff": "explicit",
6+
"source.organizeImports.ruff": "explicit",
7+
},
8+
"editor.defaultFormatter": "charliermarsh.ruff",
9+
"editor.formatOnSave": true,
10+
},
211
// Pylance の Type Checking を有効化
312
"python.languageServer": "Pylance",
413
"python.analysis.typeCheckingMode": "strict",

isdb_scanner/__init__.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
21
__version__ = '1.2.1'

isdb_scanner/__main__.py

Lines changed: 102 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,59 @@
1-
21
import subprocess
32
import sys
43
import time
5-
import typer
64
from pathlib import Path
5+
6+
import typer
77
from rich import print
8-
from rich.progress import BarColumn
9-
from rich.progress import Progress
10-
from rich.progress import TaskProgressColumn
11-
from rich.progress import TextColumn
12-
from rich.progress import TimeRemainingColumn
8+
from rich.progress import BarColumn, Progress, TaskProgressColumn, TextColumn, TimeRemainingColumn
139
from rich.rule import Rule
1410
from rich.style import Style
1511

1612
from isdb_scanner import __version__
17-
from isdb_scanner.analyzer import TransportStreamAnalyzeError
18-
from isdb_scanner.analyzer import TransportStreamAnalyzer
19-
from isdb_scanner.constants import LNBVoltage
20-
from isdb_scanner.constants import TransportStreamInfo
21-
from isdb_scanner.formatter import EDCBChSet4TxtFormatter
22-
from isdb_scanner.formatter import EDCBChSet5TxtFormatter
23-
from isdb_scanner.formatter import JSONFormatter
24-
from isdb_scanner.formatter import MirakcConfigYmlFormatter
25-
from isdb_scanner.formatter import MirakurunChannelsYmlFormatter
26-
from isdb_scanner.formatter import MirakurunTunersYmlFormatter
27-
from isdb_scanner.tuner import ISDBTuner
28-
from isdb_scanner.tuner import TunerOpeningError
29-
from isdb_scanner.tuner import TunerOutputError
30-
from isdb_scanner.tuner import TunerTuningError
13+
from isdb_scanner.analyzer import TransportStreamAnalyzeError, TransportStreamAnalyzer
14+
from isdb_scanner.constants import LNBVoltage, TransportStreamInfo
15+
from isdb_scanner.formatter import (
16+
EDCBChSet4TxtFormatter,
17+
EDCBChSet5TxtFormatter,
18+
JSONFormatter,
19+
MirakcConfigYmlFormatter,
20+
MirakurunChannelsYmlFormatter,
21+
MirakurunTunersYmlFormatter,
22+
)
23+
from isdb_scanner.tuner import ISDBTuner, TunerOpeningError, TunerOutputError, TunerTuningError
3124

3225

3326
def version(value: bool):
3427
if value is True:
3528
typer.echo(f'ISDBScanner version {__version__}')
3629
raise typer.Exit()
3730

31+
3832
app = typer.Typer()
3933

40-
@app.command(help='ISDBScanner: Scans Japanese TV broadcast channels (ISDB-T/ISDB-S) and outputs results in various formats (depends on recisdb)')
34+
35+
@app.command(
36+
help='ISDBScanner: Scans Japanese TV broadcast channels (ISDB-T/ISDB-S) and outputs results in various formats (depends on recisdb)'
37+
)
4138
def main(
4239
output: Path = typer.Argument(Path('scanned/'), help='Output scan results to the specified directory.'),
43-
exclude_pay_tv: bool = typer.Option(False, help='Exclude pay-TV channels from scan results and include only free-to-air terrestrial and BS channels.'),
40+
exclude_pay_tv: bool = typer.Option(
41+
False,
42+
help='Exclude pay-TV channels from scan results and include only free-to-air terrestrial and BS channels.',
43+
),
4444
output_recisdb_log: bool = typer.Option(False, help='Output recisdb log to stderr.'),
4545
list_tuners: bool = typer.Option(False, help='List available ISDB-T/ISDB-S tuners and exit.'),
4646
lnb: LNBVoltage = typer.Option(LNBVoltage.LOW, help='LNB voltage for satellite antenna power supply.'),
4747
version: bool = typer.Option(None, '--version', callback=version, is_eager=True, help='Show version information.'),
4848
):
49-
50-
print(Rule(
51-
title = f'ISDBScanner version {__version__}',
52-
characters='=',
53-
style = Style(color='#E33157'),
54-
align = 'center',
55-
))
49+
print(
50+
Rule(
51+
title=f'ISDBScanner version {__version__}',
52+
characters='=',
53+
style=Style(color='#E33157'),
54+
align='center',
55+
)
56+
)
5657

5758
# recisdb の実行ファイルがインストールされているか確認
5859
if subprocess.run(['/bin/bash', '-c', 'type recisdb'], stdout=subprocess.DEVNULL, stderr=subprocess.DEVNULL).returncode != 0:
@@ -108,15 +109,14 @@ def main(
108109

109110
# プログレスバーを開始
110111
progress = Progress(
111-
TextColumn("[progress.description]{task.description}"),
112+
TextColumn('[progress.description]{task.description}'),
112113
BarColumn(bar_width=9999),
113114
TaskProgressColumn(),
114115
TimeRemainingColumn(),
115116
transient=True,
116117
)
117-
task = progress.add_task("[bright_red]Scanning...", total=total_channel_count)
118+
task = progress.add_task('[bright_red]Scanning...', total=total_channel_count)
118119
with progress:
119-
120120
# ***** 地上波のチャンネルスキャン *****
121121

122122
print('Scanning ISDB-T (Terrestrial) channels...')
@@ -195,14 +195,15 @@ def main(
195195

196196
# 同一 TSID を持つ物理チャンネルのうち、信号レベルが最も高い物理チャンネルのみを残す
197197
for ts_infos in tsid_grouped_physical_channels.values():
198-
199198
# 同一 TSID を持つ物理チャンネルが1つだけ (正常) の場合は何もしない
200199
if len(ts_infos) == 1:
201200
continue
202201

203202
print(Rule(characters='-', style=Style(color='#E33157')))
204-
print(f'[yellow]{ts_infos[0].network_name} (TSID: {ts_infos[0].transport_stream_id}) '
205-
'was detected redundantly across multiple physical channels.[/yellow]')
203+
print(
204+
f'[yellow]{ts_infos[0].network_name} (TSID: {ts_infos[0].transport_stream_id}) '
205+
'was detected redundantly across multiple physical channels.[/yellow]'
206+
)
206207
print('[yellow]Outputs only the physical channel with the highest signal level...[/yellow]')
207208

208209
# それぞれの物理チャンネルの信号レベルを計測
@@ -231,8 +232,10 @@ def main(
231232
if signal_level != max_signal_level:
232233
tr_ts_infos.remove(ts_info)
233234
else:
234-
print(f'[green]Selected Physical Channel: {ts_info.physical_channel.replace("T", "")}ch | '
235-
f'Signal Level: {signal_level:.2f} dB[/green]')
235+
print(
236+
f'[green]Selected Physical Channel: {ts_info.physical_channel.replace("T", "")}ch | '
237+
f'Signal Level: {signal_level:.2f} dB[/green]'
238+
)
236239

237240
# 物理チャンネル順にソート
238241
tr_ts_infos = sorted(tr_ts_infos, key=lambda x: x.physical_channel)
@@ -326,54 +329,90 @@ def main(
326329
## JSON のみ常に取得した全チャンネルを出力
327330
JSONFormatter(
328331
output / 'Channels.json',
329-
tr_ts_infos, bs_ts_infos, cs_ts_infos,
330-
exclude_pay_tv = False).save()
332+
tr_ts_infos,
333+
bs_ts_infos,
334+
cs_ts_infos,
335+
exclude_pay_tv=False,
336+
).save()
331337
EDCBChSet4TxtFormatter(
332338
output / 'EDCB-Wine/BonDriver_mirakc(BonDriver_mirakc).ChSet4.txt',
333-
tr_ts_infos, bs_ts_infos, cs_ts_infos,
334-
exclude_pay_tv).save()
339+
tr_ts_infos,
340+
bs_ts_infos,
341+
cs_ts_infos,
342+
exclude_pay_tv,
343+
).save()
335344
EDCBChSet4TxtFormatter(
336345
output / 'EDCB-Wine/BonDriver_mirakc_T(BonDriver_mirakc).ChSet4.txt',
337-
tr_ts_infos, [], [],
338-
exclude_pay_tv).save()
346+
tr_ts_infos,
347+
[],
348+
[],
349+
exclude_pay_tv,
350+
).save()
339351
EDCBChSet4TxtFormatter(
340352
output / 'EDCB-Wine/BonDriver_mirakc_S(BonDriver_mirakc).ChSet4.txt',
341-
[], bs_ts_infos, cs_ts_infos,
342-
exclude_pay_tv).save()
353+
[],
354+
bs_ts_infos,
355+
cs_ts_infos,
356+
exclude_pay_tv,
357+
).save()
343358
EDCBChSet5TxtFormatter(
344359
output / 'EDCB-Wine/ChSet5.txt',
345-
tr_ts_infos, bs_ts_infos, cs_ts_infos,
346-
exclude_pay_tv).save()
360+
tr_ts_infos,
361+
bs_ts_infos,
362+
cs_ts_infos,
363+
exclude_pay_tv,
364+
).save()
347365
MirakurunChannelsYmlFormatter(
348366
output / 'Mirakurun/channels.yml',
349-
tr_ts_infos, bs_ts_infos, cs_ts_infos,
350-
exclude_pay_tv).save()
367+
tr_ts_infos,
368+
bs_ts_infos,
369+
cs_ts_infos,
370+
exclude_pay_tv,
371+
).save()
351372
MirakurunChannelsYmlFormatter(
352373
output / 'Mirakurun/channels_recpt1.yml',
353-
tr_ts_infos, bs_ts_infos, cs_ts_infos,
354-
exclude_pay_tv, recpt1_compatible = True).save()
374+
tr_ts_infos,
375+
bs_ts_infos,
376+
cs_ts_infos,
377+
exclude_pay_tv,
378+
recpt1_compatible=True,
379+
).save()
355380
MirakurunTunersYmlFormatter(
356-
output / 'Mirakurun/tuners.yml',
357-
available_isdbt_tuners, available_isdbs_tuners, available_multi_tuners).save()
381+
output / 'Mirakurun/tuners.yml', available_isdbt_tuners, available_isdbs_tuners, available_multi_tuners
382+
).save()
358383
MirakurunTunersYmlFormatter(
359384
output / 'Mirakurun/tuners_recpt1.yml',
360-
available_isdbt_tuners, available_isdbs_tuners, available_multi_tuners,
361-
recpt1_compatible = True).save()
385+
available_isdbt_tuners,
386+
available_isdbs_tuners,
387+
available_multi_tuners,
388+
recpt1_compatible=True,
389+
).save()
362390
MirakcConfigYmlFormatter(
363391
output / 'mirakc/config.yml',
364-
available_isdbt_tuners, available_isdbs_tuners, available_multi_tuners,
365-
tr_ts_infos, bs_ts_infos, cs_ts_infos,
366-
exclude_pay_tv).save()
392+
available_isdbt_tuners,
393+
available_isdbs_tuners,
394+
available_multi_tuners,
395+
tr_ts_infos,
396+
bs_ts_infos,
397+
cs_ts_infos,
398+
exclude_pay_tv,
399+
).save()
367400
MirakcConfigYmlFormatter(
368401
output / 'mirakc/config_recpt1.yml',
369-
available_isdbt_tuners, available_isdbs_tuners, available_multi_tuners,
370-
tr_ts_infos, bs_ts_infos, cs_ts_infos,
371-
exclude_pay_tv, recpt1_compatible = True).save()
402+
available_isdbt_tuners,
403+
available_isdbs_tuners,
404+
available_multi_tuners,
405+
tr_ts_infos,
406+
bs_ts_infos,
407+
cs_ts_infos,
408+
exclude_pay_tv,
409+
recpt1_compatible=True,
410+
).save()
372411

373412
print(Rule(characters='=', style=Style(color='#E33157')))
374413
print(f'Finished in {time.time() - scan_start_time:.2f} seconds.')
375414
print(Rule(characters='=', style=Style(color='#E33157')))
376415

377416

378-
if __name__ == "__main__":
417+
if __name__ == '__main__':
379418
app()

0 commit comments

Comments
 (0)