Difference between revisions of "Custom Channel Configuration Backup and Restore"

From MythTV Official Wiki
Jump to: navigation, search
(Backup Script)
(Restore Script)
Line 31: Line 31:
 
Expects to read a file called channels.csv in the current working directory. Change the 'password' in your connection string to match your mythconverg password.  
 
Expects to read a file called channels.csv in the current working directory. Change the 'password' in your connection string to match your mythconverg password.  
  
#!/usr/bin/python
+
{{Code box|restore_channels.py|
 +
<pre>
 +
#!/usr/bin/python
 +
 
 +
import csv
 +
import MySQLdb
 +
 
 +
conn = MySQLdb.connect (host = "localhost",
 +
                          user = "mythtv",
 +
                          passwd = "password",
 +
                          db = "mythconverg")
 +
 
 +
cursor = conn.cursor()
 +
 
 +
cursor.execute("UPDATE channel SET visible=0")
 +
 
 +
data = csv.reader(file("channels.csv"))
 +
for row in data:
 +
#CSV Format: "channum","callsign","serviceid","name","default_authority","xmltvid","icon","commmethod"
 +
cursor.execute("UPDATE channel SET visible=1, channum=%s, callsign=%s, name=%s, default_authority=%s, xmltvid=%s, icon=%s, commmethod=%s, useonairguide=%s WHERE serviceid=%s",(row[0],row[1],row[3],row[4],row[5],row[6],row[7],row[8],row[2]))
 
   
 
   
import csv
+
cursor.close()
import MySQLdb
+
conn.close()
+
</pre>
conn = MySQLdb.connect (host = "localhost",
+
}}
                            user = "mythtv",
+
                            passwd = "password",
+
                            db = "mythconverg")
+
+
cursor = conn.cursor()
+
+
cursor.execute("UPDATE channel SET visible=0")
+
+
data = csv.reader(file("channels.csv"))
+
for row in data:
+
#CSV Format: "channum","callsign","serviceid","name","default_authority","xmltvid","icon","commmethod"
+
cursor.execute("UPDATE channel SET visible=1, channum=%s, callsign=%s, name=%s, default_authority=%s, xmltvid=%s, icon=%s, commmethod=%s, useonairguide=%s WHERE serviceid=%s",(row[0],row[1],row[3],row[4],row[5],row[6],row[7],row[8],row[2]))
+
+
cursor.close ()
+
conn.close ()
+
 
+
  
 
[[Category:Scripts]]
 
[[Category:Scripts]]

Revision as of 10:18, 31 January 2013

These scripts are to help restore customised channel logos, names, xmltv config, commercial skip, use of on air guide and channel numbering after a channel scan, based on serviceid. These script will restore the majority of your channel configuration and if a channel moves and it service id changes, you can easily update that channel's service id in the CSV file and restore the rest of the configuration.

It is also useful in validating a rescan has recaptured all your wanted channels, i.e. running the backup before and after a rescan and restore and performing a diff. I found some channels didn't reappear first scan.

Also this will hide all channels not listed in the csv file. The backup script will only output channels which are visible and have a different channel number to the service id - i.e. it thinks you've edited that one.

Backup Script

Run this script before your perform a channel rescan and redirect the output to channels.csv. You can edit this file for easier channel logo and name management.


Script.png backup_channels.sh

#!/bin/sh
 
. ~/.mythtv/mysql.txt
 
mysql -u $DBUserName --password=$DBPassword $DBName -B -e "select channum, callsign, serviceid, name, default_authority, xmltvid, icon, commmethod, useonairguide from channel where visible=1 and channum!=serviceid order by (channum+0),serviceid;" | sed 's/\t/","/g;s/^/"/;s/$/"/;s/\n//g'

Example Output

"channum","callsign","serviceid","name","default_authority","xmltvid","icon","commmethod","useonairguide"
"101","BBC 1 Scotland","4220","BBC 1 Scotland","fp.bbc.co.uk","","bbc_one_scotland.jpg","-2","1"
"101","BBC 1 Scotland","6421","BBC 1 Scotland","fp.bbc.co.uk","","bbc_one_scotland.jpg","-2","0"
"102","BBC 2 Scotland","4284","BBC 2 Scotland","fp.bbc.co.uk","","bbc2_scotland.jpg","-2","1"
"102","BBC 2 Scotland","6422","BBC 2 Scotland","fp.bbc.co.uk","","bbc2_scotland.jpg","-2","0"

Restore Script

Expects to read a file called channels.csv in the current working directory. Change the 'password' in your connection string to match your mythconverg password.


Script.png restore_channels.py

#!/usr/bin/python

import csv
import MySQLdb

conn = MySQLdb.connect (host = "localhost",
                           user = "mythtv",
                           passwd = "password",
                           db = "mythconverg")

cursor = conn.cursor()

cursor.execute("UPDATE channel SET visible=0")

data = csv.reader(file("channels.csv"))
for row in data:
	#CSV Format: "channum","callsign","serviceid","name","default_authority","xmltvid","icon","commmethod"
	cursor.execute("UPDATE channel SET visible=1, channum=%s, callsign=%s, name=%s, default_authority=%s, xmltvid=%s, icon=%s, commmethod=%s, useonairguide=%s WHERE serviceid=%s",(row[0],row[1],row[3],row[4],row[5],row[6],row[7],row[8],row[2]))
 
cursor.close()
conn.close()