Google DriveからMIDIファイルとQRコードPNGをダウンロードし、楽譜PDFの生成・QRコード埋め込み・印刷管理を自動化するツールです。
- Google Drive連携: Google Drive APIを使用してMIDIファイルとQRコードPNGを自動ダウンロード
- MIDI→PDF変換:
music21ライブラリを使用してMIDIファイルを楽譜PDFに変換 - メタデータ編集: XMLパーサーによるMusicXMLの曲名・作曲者名・テンポ位置の編集
- QRコード埋め込み: 楽譜画像にQRコードを自動合成
- 印刷管理: 処理済みファイルのディレクトリ管理と印刷準備
- Python 3.8+
- MuseScore v3.6.2: MusicXML/PDF変換に必要。ダウンロード
pip install -r requirements.txt主要な依存ライブラリ:
music21- 音楽記譜処理Pillow- 画像処理pdf2image- PDF→画像変換google-api-python-client/google-auth- Google Drive API
-
Google API認証情報の配置:
mkdir credentials # サービスアカウントのcredentials.jsonを配置 cp /path/to/credentials.json credentials/ -
設定ファイルの編集 (
config.json):{ "data_dir": "./data", "output_dir": "./output", "credentials_path": "credentials/credentials.json", "song_name_pattern": "(.+?)_output_", "composer_name": "東京都市大学 大谷研究室", "polling_interval_sec": 10, "drive_page_size": 10 }項目 説明 data_dirダウンロードファイルの保存先 output_dir処理済みファイルの出力先 credentials_pathGoogle API認証ファイルのパス song_name_patternファイル名から曲名を抽出する正規表現 composer_name楽譜に表示する作曲者名 polling_interval_secGoogle Driveのポーリング間隔(秒) drive_page_sizeGoogle Drive APIのページサイズ
python main.py起動後、config.jsonで指定した間隔でGoogle Driveを監視し、新しいファイルを自動処理します。Ctrl+Cで安全に停止できます。
Google Drive → download() → [.mid + .png]
↓
make_score() → [.musicxml + .pdf]
↓
pdf_to_jpg() → [.jpg]
↓
embed_qr() → [.jpg with QR]
↓
print_score() → ./output/printed/
.
├── main.py # メインスクリプト
├── config.json # 設定ファイル
├── requirements.txt # 依存パッケージ
├── tests/ # テストコード
│ ├── conftest.py # テスト用モック設定
│ ├── test_download.py
│ ├── test_make_score.py
│ ├── test_pdf_to_jpg.py
│ ├── test_embed_qr.py
│ ├── test_print_score.py
│ ├── test_get_extensions.py
│ └── test_main.py
├── credentials/ # Google API認証情報 (git管理外)
├── data/ # ダウンロードデータ (git管理外)
└── output/ # 出力ファイル (git管理外)
├── unprint/ # 印刷待ち
└── printed/ # 印刷済み
| 関数 | 説明 |
|---|---|
download() |
Google Driveからmid/pngファイルをダウンロード |
make_score(path) |
MIDIファイルをパースし、MusicXMLメタデータを編集してPDFを生成 |
pdf_to_jpg(path) |
PDFをJPG画像に変換 |
embed_qr(path) |
楽譜画像にQRコードPNGを埋め込み |
print_score(path) |
印刷処理とファイル移動 |
get_extensions(path) |
ディレクトリ内のファイル拡張子セットを取得 |
main() |
パイプライン全体を実行 |
python -m unittest discover -s tests -v外部依存パッケージ(music21, Pillow等)がインストールされていない環境でも、モックにより全テストが実行可能です。
Google Drive APIの利用にはサービスアカウントの認証情報が必要です。認証情報はcredentials/ディレクトリに配置し、Gitリポジトリにはコミットしないでください。