0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

EPGStationのDBの値と実ファイル名の差異を修正する

Posted at

この記事はZennに投稿したスクラップの内容と同じです。こちらの方が簡潔です。
https://zenn.dev/scm/scraps/bb769df31c3e26

EPGStationでは、config.ymlから、録画ファイル名のフォーマットを簡単に変更できます。

(参考)

ですが、ファイル名を手動で新しいフォーマットへ書き換えると、EPGStationで再生する際にファイルが見つからずエラーになってしまいます。

書き換え前 - 20240623-234500-ブルーアーカイブ The Animation[終]#12[字].mp4
書き換え後 - 2024-06-23_23-45-00_ブルーアーカイブ The Animation[終]#12[字].mp4
(下のエラー文で参照しているファイル名と異なっている)
:8888/#/recorded/watch?videoId=xxx&recordedId=xxxのDevツール→ネットワーク
{
    "code": 500,
    "message": "Internal Server Error",
    "errors": "ENOENT: no such file or directory, stat '/app/recorded/20240623-234500-ブルーアーカイブ The Animation[終]#12[字].mp4'"
}

正直、こんな事態に陥る方は少ないと思います。ですが、DBの書き換えは覚えておいたらいつか使えるかもしれない、ということで読んでいってください。

mysqlコンテナに接続

dockerのexecコマンドを使って

docker exec -it docker-mirakurun-epgstation-mysql-1 bash

rootでコンテナに入ります。
そしてmysqlにログインしましょう。パスワードはデフォルトでepgstationになります。ログインできない場合は/docker-mirakurun-epgstation/epgstation/config/config.ymlのmysqlの欄にpasswordが記載されているので確認してください。

root@d98e8610a824:/# mysql -uroot -p
Enter password:

ログインできると、MariaDBが操作可能になります。show DATABASES;を実行してみてください。存在するデータベースのリストが表示されたでしょうか。
(コマンドの最後のセミコロンを忘れないようにしてください。付けずに実行した際は、セミコロンを1つ入力しエンターを押してください。正しくコマンドが実行されます。)

Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 59
Server version: 10.5.26-MariaDB-ubu2004 mariadb.org binary distribution

Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

MariaDB [(none)]> show DATABASES;
+--------------------+
| Database           |
+--------------------+
| epgstation         |
| information_schema |
| mysql              |
| performance_schema |
+--------------------+
4 rows in set (0.012 sec)

SQLをゴリゴリ実行

操作したいデータベースを選択します。今回はepgstationが対象。

MariaDB [(none)]> use epgstation;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A

Database changed
役立ちそうなコマンド
# 指定したtable(ここではrecorded)のカラム一覧表示
show columns from recorded;
# 指定したカラム(ここではname)の値をすべて表示
select name from recorded

show TABLES;でテーブル一覧が確認できます。

MariaDB [epgstation]> show TABLES;
+----------------------------+
| Tables_in_epgstation       |
+----------------------------+
| channel                    |
| drop_log_file              |
| migrations                 |
| program                    |
| recorded                   |
| recorded_history           |
| recorded_tag               |
| recorded_tags_recorded_tag |
| reserve                    |
| rule                       |
| thumbnail                  |
| video_file                 |
+----------------------------+
12 rows in set (0.001 sec)

video_fileというテーブルにファイル情報があるので、記録されたファイル名とidを表示してみます。

MariaDB [epgstation]> select id,filePath from video_file
+-----+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| id  | filePath                                                                                                                                                                       |
+-----+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
|   1 | 20240615-130000-こころの時代 ひとりで生きる みんなで生きる 作家・若竹千佐子[字][再].m2ts                                                                                    |
|   2 | 20240615-130000-こころの時代 ひとりで生きる みんなで生きる 作家・若竹千佐子[字][再].mp4                                                                                     |
|   5 | 20240615-170000-ドラえもん 【ふたりっきりで月旅行】【ウルトラリング】[デ][字].mp4                                                                                              |
.
. (省略)
.
|  41 | 20241006-205500-ニュース・気象情報(関東甲信越)[字][手].mp4                                                                                                                   |
|  43 | 20241007-230000-tiny desk concerts JAPAN 総合版(2)KIRINJI[字].mp4                                                                           |

# ここで構築し直した
|  47 | 2024年10月13日13時00分00秒-ニュース・気象情報[字].mp4                                                                                                                          |
|  49 | 2024年10月13日18時45分00秒-ニュース645(関東・山梨)[字].mp4                                                                                                                |

# ここでフォーマットを変更した
|  51 | 2024-10-13_19-15-00_NHK総合1・東京-NHKニュース7[二][字].mp4                                                                                                            |
|  53 | 2024-10-14_15-00-00_NHK総合1・東京-ニュース・気象情報[字].mp4                                                                                                              |
|  56 | 2024-10-14_15-50-00_NHK総合1・東京-100カメ 東京メトロ 巨大地下鉄ネットワークを観察![解][字][再].mp4   |

ここまでくれば内容の変更はすぐです。今回は変更箇所が多くて自動化したかったので、
ChatGPTにSQL文を生成してもらいました。

UPDATE video_file
SET filePath = CONCAT(
    SUBSTRING(filePath, 1, 4), '-',               -- 年(前4文字)
    SUBSTRING(filePath, 5, 2), '-',               -- 月(5~6文字目)
    SUBSTRING(filePath, 7, 2), '_',               -- 日(7~8文字目)
    SUBSTRING(filePath, 10, 2), '-',              -- 時(10~11文字目)
    SUBSTRING(filePath, 12, 2), '-',              -- 分(12~13文字目)
    SUBSTRING(filePath, 14, 2), '_',              -- 秒(14~15文字目)
    SUBSTRING(filePath, 17)                       -- 残りの文字列(17文字目以降)
)
WHERE filePath LIKE '20240__________%.mp4';       -- 対象をフィルタリング

SQL文をターミナルにコピペすると、その瞬間に実行されますのでご注意ください(環境によって異なるかもしれません)。

結果(冒頭と同じです)

書き換え前 - 20240623-234500-ブルーアーカイブ The Animation[終]#12[字].mp4
書き換え後 - 2024-06-23_23-45-00_ブルーアーカイブ The Animation[終]#12[字].mp4

update文は対象のテーブル名、変更したいカラムと値、変更したい行のidを指定することで実行できます。

(例 - video_fileテーブルでidが10の行のカラム「name」を「test」にセットする)
update video_file set name='test' where id=10;

この修正により、実際にEPGStationから再生できるようになりました。お読みいただきありがとうございました。

参考

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?