This repository has been archived by the owner on Aug 28, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 6
/
dump_md.py
57 lines (51 loc) · 1.64 KB
/
dump_md.py
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
#-------------------------------------------------------------------------------
# Simple Tool to dump the meta data from an SD HDHomeRun DVR TS (.mpg) File
#
#########
#
#-------------------------------------------------------------------------------
import os
import platform
import logging
import sys
import time
from time import strftime
import hdhr_tsparser
import hdhr_md
HDHR_TS_METADATA_PID = 0x1FFA
def parse_file_for_data(filename):
parser = hdhr_tsparser.TSParser(filename)
payloads = 0
tempMD = []
pid_found = False
for b in parser.read_next_section():
payloads+=1
header = parser.parse_ts_header(b)
if parser.header_contains_pid(header,HDHR_TS_METADATA_PID):
# found a matching program ID - need to reconstruct the payload
tempMD += parser.extract_payload(b)
pid_found = True
else:
# Didn't find HDHR MetaData PID.. so break if we found already
if pid_found == True:
break
return parser.extract_metadata(tempMD)
if __name__ == "__main__":
print '- HDHR TS MetaData Dump Tool '+strftime("%Y-%m-%d %H:%M:%S")+'-'
logging.basicConfig(stream=sys.stdout, level=logging.DEBUG)
md_file = ''
if (len(sys.argv) == 2):
md_file=sys.argv[1]
print 'Parsing ' + md_file
metaData = parse_file_for_data(md_file)
md = hdhr_md.HDHomeRunMD(metaData)
md.print_metaData()
else:
print 'Unexpected number of parameters - please just provide single input filename.'
print 'Usage:'
print ' dump_md.py <filename>'
print ''
print 'Script will parse the TS file for the SD program, extrat the metadata and'
print 'dump to stdout'
sys.exit(0)
print '- Complete -'