Skip to content

Commit

Permalink
Refactor: [Server] クラスのインポート記法を変更
Browse files Browse the repository at this point in the history
今までモジュール名だけでクラスをインポートできるようにしていたが、循環参照・モジュールが意図せずインポートされる・タイミング次第でインポートが壊れるなど多発する問題に耐えかねて諦めた
  • Loading branch information
tsukumijima committed Jul 3, 2023
1 parent e17cf2f commit 3f8664a
Show file tree
Hide file tree
Showing 30 changed files with 98 additions and 870 deletions.
4 changes: 2 additions & 2 deletions client/src/utils/ProgramUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ export class ProgramUtils {

/**
* 文字列に含まれる英数や記号を半角に置換し、一律な表現に整える
* server/app/utils/TSInformation.py の TSInformation.formatString() と同等の処理を行う
* server/app/metadata/TSInfoAnalyzer.py の TSInfoAnalyzer.formatString() と同等の処理を行う
* @param string 変換する文字列
* @returns 置換した文字列
*/
Expand All @@ -185,7 +185,7 @@ export class ProgramUtils {

/**
* formatString() で使用する変換テーブルを取得する
* server/app/utils/TSInformation.py の TSInformation.__getFormatStringTranslationTable() と同等の処理を行う
* server/app/metadata/TSInfoAnalyzer.py の TSInfoAnalyzer.__getFormatStringTranslationTable() と同等の処理を行う
* @returns 変換テーブル
*/
private static getFormatStringTranslationTable(): {[key: string]: string} {
Expand Down
2 changes: 0 additions & 2 deletions server/KonomiTV.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,6 @@ def main(
## ロギング設定は Logging.py が読み込まれた瞬間に行われるが、その際に前回のログファイルが残っているとエラーになる
## constants.py は内部モジュールへの依存がなく、config.py も constants.py 以外への依存はないので、この2つのみトップレベルでインポートしている
## 前回のログをすべて削除する処理を Logging.py 自体に記述してしまうとマルチプロセス実行時や自動リロードモード時に意図せずファイルが削除されてしまう
## from app import models を最初に実行しておかないと、なぜか app.utils 配下のモジュールへのアクセスがうまくいかない
from app import models # type: ignore # import magic!!!
from app.utils import IsRunningAsWindowsService
from app.utils import Logging

Expand Down
8 changes: 4 additions & 4 deletions server/app/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
from app.config import Config
from app.config import LoadConfig
from app.constants import CLIENT_DIR, DATABASE_CONFIG, QUALITY, VERSION
from app.models import Channel
from app.models import LiveStream
from app.models import Program
from app.models import TwitterAccount
from app.models.Channel import Channel
from app.models.LiveStream import LiveStream
from app.models.Program import Program
from app.models.TwitterAccount import TwitterAccount
from app.routers import CapturesRouter
from app.routers import ChannelsRouter
from app.routers import LiveStreamsRouter
Expand Down
2 changes: 1 addition & 1 deletion server/app/metadata/CMSectionsDetector.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@

from pathlib import Path

from app.models import RecordedVideo
from app.models.RecordedVideo import RecordedVideo


class CMSectionsDetector:
Expand Down
15 changes: 8 additions & 7 deletions server/app/metadata/MetadataAnalyzer.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
from datetime import datetime
from datetime import timedelta
from pathlib import Path
from pprint import pprint
from pymediainfo import MediaInfo
from typing import cast

from app.constants import LIBRARY_DIR
from app.metadata import CMSectionsDetector
from app.metadata import TSInfoAnalyzer
from app.models import Channel
from app.models import RecordedProgram
from app.models import RecordedVideo
from app.metadata.CMSectionsDetector import CMSectionsDetector
from app.metadata.TSInfoAnalyzer import TSInfoAnalyzer
from app.models.Channel import Channel
from app.models.RecordedProgram import RecordedProgram
from app.models.RecordedVideo import RecordedVideo
from app.utils import GetPlatformEnvironment
from app.utils.TSInformation import TSInformation


class MetadataAnalyzer:
Expand Down Expand Up @@ -152,7 +154,7 @@ def analyze(self) -> tuple[RecordedVideo, RecordedProgram, Channel | None] | Non
## ファイルの作成日時を録画開始時刻として使用する
start_time = datetime.fromtimestamp(self.recorded_file_path.stat().st_ctime)
## 拡張子を除いたファイル名をフォーマットした上でタイトルとして使用する
title = TSInfoAnalyzer.formatString(self.recorded_file_path.stem)
title = TSInformation.formatString(self.recorded_file_path.stem)
recorded_program = RecordedProgram(
title = title,
description = '番組情報を取得できませんでした。',
Expand Down Expand Up @@ -276,7 +278,6 @@ def main(recorded_file_path: Path = typer.Argument(..., exists=True, file_okay=T
metadata_analyzer = MetadataAnalyzer(recorded_file_path)
results = metadata_analyzer.analyze()
if results:
from pprint import pprint
for result in results:
if result is not None:
pprint(dict(result))
Expand Down
Loading

0 comments on commit 3f8664a

Please sign in to comment.