-
Notifications
You must be signed in to change notification settings - Fork 0
/
notes.txt
61 lines (52 loc) · 2.62 KB
/
notes.txt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
What has to happen to transfer a program from MythTV to MythVideo:
1. Copy the file from the program's storage directory to the Videos storage directory.
2. If step 1 succeeded, call the API::Video/AddVideo to tell MythVideo about the file.
3. If step 2 succeeded, add metadata (title, subtitle, year, contenttype...)
Step 1 can be done with shutil.copy() or shutil.copy2(). The source is the recording's filespec property.
The destination is the Videos storage directory + the recording's filename property.
The shutil methods return the destination path if successful; otherwise they raise an exception.
An alternate way of doing Step 1 is via SSH. Use the 'paramiko' library to construct and execute
the SSH commands on the server containing the TV recording. For example:
import paramiko
import os
from mythcontent.dto import Video, TvRecording
from nonpublic.settings import SSH_INFOS
source_host = prog.hostname
source_filespec = prog.filespec
vid = Video()
dest_dir = vid.video_directory + p.title.replace(' ','_') + os.sep
dest_host = vid.host_name
ssh_client = paramiko.SSHClient()
ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy())
port = (SSH_INFOS[hostname]).get('port', '22')
ssh_client.connect(
source_host,
username=SSH_INFOS[hostname][user],
password=SSH_INFOS[hostname][password],
port=port,
allow_agent=False,
look_for_keys=False
)
mkdir_command = 'mkdir -p {}'.format(dest_dir)
copy_command = 'cp -v {} {}'.format(source_filespec,dest_dir)
stdin,stdout,stderr=ssh.exec_command(mkdir_command)
stdout.readlines()
stdin,stdout,stderr=ssh.exec_command(copy_command)
stdout.readlines()
(The above example assumes that the source host and destination host are the same.)
The Video/AddVideo call returns { 'bool':'true' } if it succeeds. Assuming that it
does succeed, then we can go to Step 3. Step 3 will need to be done with a database
call (i.e., with an ORM Model) since the API doesn't expose any methods to set
metadata the way we want to do.
So, we retrieve from the database the row that was created by the API call in step 2. We
do this by filtering on the file name and host name:
vlist = VideoDao.objects.filter(filename='Baseball/Home_Run_Derby-July_13_2015/Home-Run_Derby-July_13_2015.mpg').filter(host='mythbackend1')
if len(vlist) != 1:
# uh oh -- problem
raise('Could not find video')
v = vlist[0]
v.title='2015 Home Run Derby' # from prog.title
v.subtitle='July 13, 2015 -- Great American Ballpark. Todd Frazier Lights Up the House!' # from prog.subtitle
v.year=...
v.contenttype='TELEVISION'
v.save() # May need to massage format of v.insertdate prior to save -- will need to be time-zone aware