Hey,
MythTV store recorded files in this format: <channel_no>_<date_as_number>.mpg
Where
date_as_number has milisecond granularity. For example: 1004_20121031120000.mpg -- Oct 31th 2012, noon.
This date is the start date of the recording.
This is referenced in recorded database table in the mythconverg database.
Is there anyone on the world who can work with such a filename when one want to archive recordings, move to another machine? I can't.
The Goal
1., Rename the filenames into meaningful filenames: Series Name-SxEy.mpg
a., Easier to understand
b., Easier to maintain
c., Easier to lookup Video / TV Series metadata from the Internet
d., Easier to identify
2., Enter this changes into database
3., Copy files to my secondary MythTV backend (mostly store archived and/or seen TV programmes, the ones I would like to keep for the future)
4., Change the hostname field in the recorded table to the new host.
Step #1 - Figure out the real Episode numbers
Here is a little SQL query example how to cut the Episode No#, Season No# from the subtitle, title.
Sometimes the EIT does not contain (or not precisely) the season/episode information, at least where I live.
I live the hungarian serie "Kisváros" (~ Small Town), the EIT gives me this for the following query:
SELECT title,subtitle
FROM recorded
WHERE title = 'Kisváros';
'Kisváros', '(magyar filmsor., 2. rész, 1994) - A belga - Veszedelmes gyilkos közeledik a kisvárosfelé, hátizsákjában nagyértékű vöröshigany'
In this field data, the episode number is before the ".rész" string, so l parsed out the episode number from that:
SELECT CAST(TRIM(SUBSTRING(qry.str,LOCATE(',',qry.str) + 1)) AS UNSIGNED) episode_no
FROM
(SELECT SUBSTRING_INDEX(subtitle, '. rész', 1) AS str,title,hostname,basename
FROM recorded
WHERE title LIKE 'Kisváros') qry;
Step #2 - Fix the episode, season fields in the database
UPDATE recorded AS r
,(SELECT CAST(TRIM(SUBSTRING(qry.str,LOCATE(',',qry.str) + 1)) AS UNSIGNED) episode_no,title,subtitle,basename
FROM
(SELECT SUBSTRING_INDEX(subtitle, '. rész', 1) AS str,title,subtitle,hostname,basename
FROM recorded
WHERE title = 'Kisváros') qry) AS results
SET episode = results.episode_no
WHERE r.basename = results.basename
AND r.title = 'Kisváros';
--Verification: SELECT title,episode,subtitle FROM recorded WHERE title = --'Kisváros';
Step #3 - Renaming the files on the filesystem
Side A: Generate out the rename statements for OS execution
(Hint: New Filename - Old Filename mapping:)
SELECT CONCAT('Kisvaros-S',season,'E', episode) as newfilename
,basename as oldfilename
FROM recorded
WHERE title = 'Kisváros'
ORDER BY episode;
Bash Script generation:
SELECT CONCAT('mv ',basename,' ',CONCAT('Kisvaros-S',season,'E', episode),'.mpg;')
FROM recorded
WHERE title = 'Kisváros'
ORDER BY episode;
Renaming the icons too:
SELECT CONCAT('rename ','''s/',REPLACE('.','\.',basename),'/',CONCAT('Kisvaros-S',season,'E', episode),'\.mpg/''',' *.png;')
FROM recorded
WHERE title = 'Kisváros'
ORDER BY episode;
Execute result of these two on OS console in your Default Storage Group folder.
Step #4 - Renaming the filenames in the database
UPDATE recorded SET basename = CONCAT('Kisvaros-S',season,'E', episode,'.mpg')
WHERE title = 'Kisváros';
Step #5 - Change the host name in the database
Now update the hostname where we will copy the files physically to.
In my case the target hostname is the ironclad;
UPDATE recorded SET hostname = 'ironclad'
WHERE title = 'Kisváros';
Step #6 - Move the files
Now let's do the file copy via Samba share, NFS or the way you like it.
Done.