Some basic python libs for htsmsg and htsp. Includes debug/support scripts for monitoring htsp async messages (support/htspmon) and epg dumping (support/epgdump).
This commit is contained in:
parent
07eca23aac
commit
5089291789
9 changed files with 1060 additions and 0 deletions
3
.gitignore
vendored
3
.gitignore
vendored
|
@ -5,3 +5,6 @@ build.*
|
|||
.project
|
||||
.settings
|
||||
data/dvb-scan
|
||||
|
||||
*.pyc
|
||||
.*.sw[op]
|
||||
|
|
0
lib/py/tvh/__init__.py
Normal file
0
lib/py/tvh/__init__.py
Normal file
353
lib/py/tvh/dvb_charset_tables.py
Normal file
353
lib/py/tvh/dvb_charset_tables.py
Normal file
|
@ -0,0 +1,353 @@
|
|||
conv_8859_table = [
|
||||
[
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x0104, 0x02D8, 0x0141, 0x00A4, 0x013D, 0x015A, 0x00A7,
|
||||
0x00A8, 0x0160, 0x015E, 0x0164, 0x0179, 0x00AD, 0x017D, 0x017B,
|
||||
0x00B0, 0x0105, 0x02DB, 0x0142, 0x00B4, 0x013E, 0x015B, 0x02C7,
|
||||
0x00B8, 0x0161, 0x015F, 0x0165, 0x017A, 0x02DD, 0x017E, 0x017C,
|
||||
0x0154, 0x00C1, 0x00C2, 0x0102, 0x00C4, 0x0139, 0x0106, 0x00C7,
|
||||
0x010C, 0x00C9, 0x0118, 0x00CB, 0x011A, 0x00CD, 0x00CE, 0x010E,
|
||||
0x0110, 0x0143, 0x0147, 0x00D3, 0x00D4, 0x0150, 0x00D6, 0x00D7,
|
||||
0x0158, 0x016E, 0x00DA, 0x0170, 0x00DC, 0x00DD, 0x0162, 0x00DF,
|
||||
0x0155, 0x00E1, 0x00E2, 0x0103, 0x00E4, 0x013A, 0x0107, 0x00E7,
|
||||
0x010D, 0x00E9, 0x0119, 0x00EB, 0x011B, 0x00ED, 0x00EE, 0x010F,
|
||||
0x0111, 0x0144, 0x0148, 0x00F3, 0x00F4, 0x0151, 0x00F6, 0x00F7,
|
||||
0x0159, 0x016F, 0x00FA, 0x0171, 0x00FC, 0x00FD, 0x0163, 0x02D9,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x0126, 0x02D8, 0x00A3, 0x00A4, 0x0000, 0x0124, 0x00A7,
|
||||
0x00A8, 0x0130, 0x015E, 0x011E, 0x0134, 0x00AD, 0x0000, 0x017B,
|
||||
0x00B0, 0x0127, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x0125, 0x00B7,
|
||||
0x00B8, 0x0131, 0x015F, 0x011F, 0x0135, 0x00BD, 0x0000, 0x017C,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x0000, 0x00C4, 0x010A, 0x0108, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x0000, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x0120, 0x00D6, 0x00D7,
|
||||
0x011C, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x016C, 0x015C, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x0000, 0x00E4, 0x010B, 0x0109, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x0000, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x0121, 0x00F6, 0x00F7,
|
||||
0x011D, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x016D, 0x015D, 0x02D9,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x0104, 0x0138, 0x0156, 0x00A4, 0x0128, 0x013B, 0x00A7,
|
||||
0x00A8, 0x0160, 0x0112, 0x0122, 0x0166, 0x00AD, 0x017D, 0x00AF,
|
||||
0x00B0, 0x0105, 0x02DB, 0x0157, 0x00B4, 0x0129, 0x013C, 0x02C7,
|
||||
0x00B8, 0x0161, 0x0113, 0x0123, 0x0167, 0x014A, 0x017E, 0x014B,
|
||||
0x0100, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x012E,
|
||||
0x010C, 0x00C9, 0x0118, 0x00CB, 0x0116, 0x00CD, 0x00CE, 0x012A,
|
||||
0x0110, 0x0145, 0x014C, 0x0136, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x0172, 0x00DA, 0x00DB, 0x00DC, 0x0168, 0x016A, 0x00DF,
|
||||
0x0101, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x012F,
|
||||
0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x012B,
|
||||
0x0111, 0x0146, 0x014D, 0x0137, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x0173, 0x00FA, 0x00FB, 0x00FC, 0x0169, 0x016B, 0x02D9,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x0401, 0x0402, 0x0403, 0x0404, 0x0405, 0x0406, 0x0407,
|
||||
0x0408, 0x0409, 0x040A, 0x040B, 0x040C, 0x00AD, 0x040E, 0x040F,
|
||||
0x0410, 0x0411, 0x0412, 0x0413, 0x0414, 0x0415, 0x0416, 0x0417,
|
||||
0x0418, 0x0419, 0x041A, 0x041B, 0x041C, 0x041D, 0x041E, 0x041F,
|
||||
0x0420, 0x0421, 0x0422, 0x0423, 0x0424, 0x0425, 0x0426, 0x0427,
|
||||
0x0428, 0x0429, 0x042A, 0x042B, 0x042C, 0x042D, 0x042E, 0x042F,
|
||||
0x0430, 0x0431, 0x0432, 0x0433, 0x0434, 0x0435, 0x0436, 0x0437,
|
||||
0x0438, 0x0439, 0x043A, 0x043B, 0x043C, 0x043D, 0x043E, 0x043F,
|
||||
0x0440, 0x0441, 0x0442, 0x0443, 0x0444, 0x0445, 0x0446, 0x0447,
|
||||
0x0448, 0x0449, 0x044A, 0x044B, 0x044C, 0x044D, 0x044E, 0x044F,
|
||||
0x2116, 0x0451, 0x0452, 0x0453, 0x0454, 0x0455, 0x0456, 0x0457,
|
||||
0x0458, 0x0459, 0x045A, 0x045B, 0x045C, 0x00A7, 0x045E, 0x045F,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x0000, 0x0000, 0x0000, 0x00A4, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x060C, 0x00AD, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x061B, 0x0000, 0x0000, 0x0000, 0x061F,
|
||||
0x0000, 0x0621, 0x0622, 0x0623, 0x0624, 0x0625, 0x0626, 0x0627,
|
||||
0x0628, 0x0629, 0x062A, 0x062B, 0x062C, 0x062D, 0x062E, 0x062F,
|
||||
0x0630, 0x0631, 0x0632, 0x0633, 0x0634, 0x0635, 0x0636, 0x0637,
|
||||
0x0638, 0x0639, 0x063A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0640, 0x0641, 0x0642, 0x0643, 0x0644, 0x0645, 0x0646, 0x0647,
|
||||
0x0648, 0x0649, 0x064A, 0x064B, 0x064C, 0x064D, 0x064E, 0x064F,
|
||||
0x0650, 0x0651, 0x0652,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x2018, 0x2019, 0x00A3, 0x20AC, 0x20AF, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x037A, 0x00AB, 0x00AC, 0x00AD, 0x0000, 0x2015,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x0384, 0x0385, 0x0386, 0x00B7,
|
||||
0x0388, 0x0389, 0x038A, 0x00BB, 0x038C, 0x00BD, 0x038E, 0x038F,
|
||||
0x0390, 0x0391, 0x0392, 0x0393, 0x0394, 0x0395, 0x0396, 0x0397,
|
||||
0x0398, 0x0399, 0x039A, 0x039B, 0x039C, 0x039D, 0x039E, 0x039F,
|
||||
0x03A0, 0x03A1, 0x0000, 0x03A3, 0x03A4, 0x03A5, 0x03A6, 0x03A7,
|
||||
0x03A8, 0x03A9, 0x03AA, 0x03AB, 0x03AC, 0x03AD, 0x03AE, 0x03AF,
|
||||
0x03B0, 0x03B1, 0x03B2, 0x03B3, 0x03B4, 0x03B5, 0x03B6, 0x03B7,
|
||||
0x03B8, 0x03B9, 0x03BA, 0x03BB, 0x03BC, 0x03BD, 0x03BE, 0x03BF,
|
||||
0x03C0, 0x03C1, 0x03C2, 0x03C3, 0x03C4, 0x03C5, 0x03C6, 0x03C7,
|
||||
0x03C8, 0x03C9, 0x03CA, 0x03CB, 0x03CC, 0x03CD, 0x03CE,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x0000, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00D7, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00F7, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x2017,
|
||||
0x05D0, 0x05D1, 0x05D2, 0x05D3, 0x05D4, 0x05D5, 0x05D6, 0x05D7,
|
||||
0x05D8, 0x05D9, 0x05DA, 0x05DB, 0x05DC, 0x05DD, 0x05DE, 0x05DF,
|
||||
0x05E0, 0x05E1, 0x05E2, 0x05E3, 0x05E4, 0x05E5, 0x05E6, 0x05E7,
|
||||
0x05E8, 0x05E9, 0x05EA, 0x0000, 0x0000, 0x200E, 0x200F,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x00A4, 0x00A5, 0x00A6, 0x00A7,
|
||||
0x00A8, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x00B4, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00B8, 0x00B9, 0x00BA, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x011E, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x0130, 0x015E, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x011F, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x0131, 0x015F, 0x00FF,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x0104, 0x0112, 0x0122, 0x012A, 0x0128, 0x0136, 0x00A7,
|
||||
0x013B, 0x0110, 0x0160, 0x0166, 0x017D, 0x00AD, 0x016A, 0x014A,
|
||||
0x00B0, 0x0105, 0x0113, 0x0123, 0x012B, 0x0129, 0x0137, 0x00B7,
|
||||
0x013C, 0x0111, 0x0161, 0x0167, 0x017E, 0x2015, 0x016B, 0x014B,
|
||||
0x0100, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x012E,
|
||||
0x010C, 0x00C9, 0x0118, 0x00CB, 0x0116, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x00D0, 0x0145, 0x014C, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x0168,
|
||||
0x00D8, 0x0172, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
|
||||
0x0101, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x012F,
|
||||
0x010D, 0x00E9, 0x0119, 0x00EB, 0x0117, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x00F0, 0x0146, 0x014D, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x0169,
|
||||
0x00F8, 0x0173, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x0138,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x0E01, 0x0E02, 0x0E03, 0x0E04, 0x0E05, 0x0E06, 0x0E07,
|
||||
0x0E08, 0x0E09, 0x0E0A, 0x0E0B, 0x0E0C, 0x0E0D, 0x0E0E, 0x0E0F,
|
||||
0x0E10, 0x0E11, 0x0E12, 0x0E13, 0x0E14, 0x0E15, 0x0E16, 0x0E17,
|
||||
0x0E18, 0x0E19, 0x0E1A, 0x0E1B, 0x0E1C, 0x0E1D, 0x0E1E, 0x0E1F,
|
||||
0x0E20, 0x0E21, 0x0E22, 0x0E23, 0x0E24, 0x0E25, 0x0E26, 0x0E27,
|
||||
0x0E28, 0x0E29, 0x0E2A, 0x0E2B, 0x0E2C, 0x0E2D, 0x0E2E, 0x0E2F,
|
||||
0x0E30, 0x0E31, 0x0E32, 0x0E33, 0x0E34, 0x0E35, 0x0E36, 0x0E37,
|
||||
0x0E38, 0x0E39, 0x0E3A, 0x0000, 0x0000, 0x0000, 0x0000, 0x0E3F,
|
||||
0x0E40, 0x0E41, 0x0E42, 0x0E43, 0x0E44, 0x0E45, 0x0E46, 0x0E47,
|
||||
0x0E48, 0x0E49, 0x0E4A, 0x0E4B, 0x0E4C, 0x0E4D, 0x0E4E, 0x0E4F,
|
||||
0x0E50, 0x0E51, 0x0E52, 0x0E53, 0x0E54, 0x0E55, 0x0E56, 0x0E57,
|
||||
0x0E58, 0x0E59, 0x0E5A, 0x0E5B,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x201D, 0x00A2, 0x00A3, 0x00A4, 0x201E, 0x00A6, 0x00A7,
|
||||
0x00D8, 0x00A9, 0x0156, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00C6,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x201C, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x00F8, 0x00B9, 0x0157, 0x00BB, 0x00BC, 0x00BD, 0x00BE, 0x00E6,
|
||||
0x0104, 0x012E, 0x0100, 0x0106, 0x00C4, 0x00C5, 0x0118, 0x0112,
|
||||
0x010C, 0x00C9, 0x0179, 0x0116, 0x0122, 0x0136, 0x012A, 0x013B,
|
||||
0x0160, 0x0143, 0x0145, 0x00D3, 0x014C, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x0172, 0x0141, 0x015A, 0x016A, 0x00DC, 0x017B, 0x017D, 0x00DF,
|
||||
0x0105, 0x012F, 0x0101, 0x0107, 0x00E4, 0x00E5, 0x0119, 0x0113,
|
||||
0x010D, 0x00E9, 0x017A, 0x0117, 0x0123, 0x0137, 0x012B, 0x013C,
|
||||
0x0161, 0x0144, 0x0146, 0x00F3, 0x014D, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x0173, 0x0142, 0x015B, 0x016B, 0x00FC, 0x017C, 0x017E, 0x2019,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x1E02, 0x1E03, 0x00A3, 0x010A, 0x010B, 0x1E0A, 0x00A7,
|
||||
0x1E80, 0x00A9, 0x1E82, 0x1E0B, 0x1EF2, 0x00AD, 0x00AE, 0x0178,
|
||||
0x1E1E, 0x1E1F, 0x0120, 0x0121, 0x1E40, 0x1E41, 0x00B6, 0x1E56,
|
||||
0x1E81, 0x1E57, 0x1E83, 0x1E60, 0x1EF3, 0x1E84, 0x1E85, 0x1E61,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x0174, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x1E6A,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x0176, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x0175, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x1E6B,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x0177, 0x00FF,
|
||||
],
|
||||
[
|
||||
0x00A0, 0x00A1, 0x00A2, 0x00A3, 0x20AC, 0x00A5, 0x0160, 0x00A7,
|
||||
0x0161, 0x00A9, 0x00AA, 0x00AB, 0x00AC, 0x00AD, 0x00AE, 0x00AF,
|
||||
0x00B0, 0x00B1, 0x00B2, 0x00B3, 0x017D, 0x00B5, 0x00B6, 0x00B7,
|
||||
0x017E, 0x00B9, 0x00BA, 0x00BB, 0x0152, 0x0153, 0x0178, 0x00BF,
|
||||
0x00C0, 0x00C1, 0x00C2, 0x00C3, 0x00C4, 0x00C5, 0x00C6, 0x00C7,
|
||||
0x00C8, 0x00C9, 0x00CA, 0x00CB, 0x00CC, 0x00CD, 0x00CE, 0x00CF,
|
||||
0x00D0, 0x00D1, 0x00D2, 0x00D3, 0x00D4, 0x00D5, 0x00D6, 0x00D7,
|
||||
0x00D8, 0x00D9, 0x00DA, 0x00DB, 0x00DC, 0x00DD, 0x00DE, 0x00DF,
|
||||
0x00E0, 0x00E1, 0x00E2, 0x00E3, 0x00E4, 0x00E5, 0x00E6, 0x00E7,
|
||||
0x00E8, 0x00E9, 0x00EA, 0x00EB, 0x00EC, 0x00ED, 0x00EE, 0x00EF,
|
||||
0x00F0, 0x00F1, 0x00F2, 0x00F3, 0x00F4, 0x00F5, 0x00F6, 0x00F7,
|
||||
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FD, 0x00FE, 0x00FF,
|
||||
]
|
||||
];
|
||||
|
||||
iso6937_single_byte = [
|
||||
0x00a0, 0x00a1, 0x00a2, 0x00a3, 0x0000, 0x00a5, 0x0000, 0x00a7,
|
||||
0x00a4, 0x2018, 0x201c, 0x00ab, 0x2190, 0x2191, 0x2192, 0x2193,
|
||||
0x00b0, 0x00b1, 0x00b2, 0x00b3, 0x00d7, 0x00b5, 0x00b6, 0x00b7,
|
||||
0x00f7, 0x2019, 0x201d, 0x00bb, 0x00bc, 0x00bd, 0x00be, 0x00bf,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000, 0x0000,
|
||||
0x2014, 0x00b9, 0x00ae, 0x00a9, 0x2122, 0x266a, 0x00ac, 0x00a6,
|
||||
0x0000, 0x0000, 0x0000, 0x0000, 0x215b, 0x215c, 0x215d, 0x215e,
|
||||
0x2126, 0x00c6, 0x00d0, 0x00aa, 0x0126, 0x0000, 0x0132, 0x013f,
|
||||
0x0141, 0x00d8, 0x0152, 0x00ba, 0x00de, 0x0166, 0x014a, 0x0149,
|
||||
0x0138, 0x00e6, 0x0111, 0x00f0, 0x0127, 0x0131, 0x0133, 0x0140,
|
||||
0x0142, 0x00f8, 0x0153, 0x00df, 0x00fe, 0x0167, 0x014b, 0x00ad,
|
||||
];
|
||||
|
||||
iso6937_lone_accents = [
|
||||
0x0000, 0x00B4, 0x0000, 0x0000, 0x0000, 0x00Af, 0x02D8, 0x02D9,
|
||||
0x00A8, 0x0000, 0x02DA, 0x00B8, 0x0000, 0x02DD, 0x02DB, 0x02C7,
|
||||
];
|
||||
|
||||
iso6937_multi_byte = [
|
||||
[
|
||||
0x00,
|
||||
],
|
||||
[
|
||||
|
||||
0xc0, 0x00, 0x00, 0x00, 0xc8, 0x00, 0x00, 0x00, 0xcc, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xd2, 0x00, 0x00, 0x00, 0x00, 0x00, 0xd9, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0xe0, 0x00, 0x00, 0x00, 0xe8, 0x00, 0x00, 0x00, 0xec, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xf2, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf9, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0xc1, 0x00, 0x0106, 0x00, 0xc9, 0x00, 0x00, 0x00, 0xcd, 0x00, 0x00, 0x0139,
|
||||
0x00, 0x0143, 0xd3, 0x00, 0x00, 0x0154, 0x015a, 0x00, 0xda, 0x00, 0x00, 0x00,
|
||||
0xdd, 0x0179,
|
||||
|
||||
0xe1, 0x00, 0x0107, 0x00, 0xe9, 0x00, 0x00, 0x00, 0xed, 0x00, 0x00, 0x013a,
|
||||
0x00, 0x0144, 0xf3, 0x00, 0x00, 0x0155, 0x015b, 0x00, 0xfa, 0x00, 0x00, 0x00,
|
||||
0xfd, 0x017a
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0xc2, 0x00, 0x0108, 0x00, 0xca, 0x00, 0x011c, 0x0124, 0xce, 0x0134, 0x00,
|
||||
0x00, 0x00, 0x00, 0xd4, 0x00, 0x00, 0x00, 0x015c, 0x00, 0xdb, 0x00, 0x0174,
|
||||
0x00, 0x0176, 0x00,
|
||||
|
||||
0xe2, 0x00, 0x0109, 0x00, 0xea, 0x00, 0x011d, 0x0125, 0xee, 0x0135, 0x00,
|
||||
0x00, 0x00, 0x00, 0xf4, 0x00, 0x00, 0x00, 0x015d, 0x00, 0xfb, 0x00, 0x0175,
|
||||
0x00, 0x0177, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0xc3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0128, 0x00, 0x00, 0x00, 0x00,
|
||||
0xd1, 0xd5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0168, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0xe3, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0129, 0x00, 0x00, 0x00, 0x00,
|
||||
0xf1, 0xf5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0169, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0x0100, 0x00, 0x00, 0x00, 0x0112, 0x00, 0x00, 0x00, 0x012a, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x014c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x016a, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x0101, 0x00, 0x00, 0x00, 0x0113, 0x00, 0x00, 0x00, 0x012b, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x014d, 0x00, 0x00, 0x00, 0x00, 0x00, 0x016b, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0x0102, 0x00, 0x00, 0x00, 0x00, 0x00, 0x011e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x016c, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x0103, 0x00, 0x00, 0x00, 0x00, 0x00, 0x011f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x016d, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0x00, 0x010a, 0x00, 0x0116, 0x00, 0x0120, 0x00, 0x0130, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x017b,
|
||||
|
||||
0x00, 0x010b, 0x00, 0x0117, 0x00, 0x0121, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x017c
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0xc4, 0x00, 0x00, 0x00, 0xcb, 0x00, 0x00, 0x00, 0xcf, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xd6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x00, 0x00, 0x00, 0x0178, 0x00,
|
||||
|
||||
0xe4, 0x00, 0x00, 0x00, 0xeb, 0x00, 0x00, 0x00, 0xef, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0xf6, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfc, 0x00, 0x00, 0x00, 0xff, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
0x00,
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0xc5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x016e, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0xe5, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x016f, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0x00, 0x00, 0xc7, 0x00, 0x00, 0x00, 0x0122, 0x00, 0x00, 0x00, 0x0136, 0x013b, 0x00,
|
||||
0x0145, 0x00, 0x00, 0x00, 0x0156, 0x015e, 0x0162, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x00, 0x00, 0xe7, 0x00, 0x00, 0x00, 0x0123, 0x00, 0x00, 0x00, 0x0137, 0x013c, 0x00,
|
||||
0x0146, 0x00, 0x00, 0x00, 0x0157, 0x015f, 0x0163, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
0x00,
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0150, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0170, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x0151, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0171, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0x0104, 0x00, 0x00, 0x00, 0x0118, 0x00, 0x00, 0x00, 0x012e, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0172, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
|
||||
0x0105, 0x00, 0x00, 0x00, 0x0119, 0x00, 0x00, 0x00, 0x012f, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0173, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
],
|
||||
|
||||
[
|
||||
|
||||
0x00, 0x00, 0x010c, 0x010e, 0x011a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x013d,
|
||||
0x00, 0x0147, 0x00, 0x00, 0x00, 0x0158, 0x0160, 0x0164, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x017d,
|
||||
|
||||
0x00, 0x00, 0x010d, 0x010f, 0x011b, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x013e,
|
||||
0x00, 0x0148, 0x00, 0x00, 0x00, 0x0159, 0x0161, 0x0165, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x017e
|
||||
]
|
||||
]
|
207
lib/py/tvh/htsmsg.py
Normal file
207
lib/py/tvh/htsmsg.py
Normal file
|
@ -0,0 +1,207 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2012 Adam Sutton <dev@adamsutton.me.uk>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Support for processing HTSMSG binary format
|
||||
"""
|
||||
|
||||
# ###########################################################################
|
||||
# Utilities
|
||||
# ###########################################################################
|
||||
|
||||
def int2bin ( i ):
|
||||
return chr(i >> 24 & 0xFF) + chr(i >> 16 & 0xFF)\
|
||||
+ chr(i >> 16 & 0xFF) + chr(i & 0xFF)
|
||||
|
||||
def bin2int ( d ):
|
||||
return (ord(d[0]) << 24) + (ord(d[1]) << 16)\
|
||||
+ (ord(d[2]) << 8) + ord(d[3])
|
||||
|
||||
# ###########################################################################
|
||||
# HTSMSG Binary handler
|
||||
#
|
||||
# Note: this will work with the python native types:
|
||||
# dict => HMF_MAP
|
||||
# list => HMF_LIST
|
||||
# str => HMF_STR
|
||||
# int => HMF_S64
|
||||
# hmf_bin => HMF_BIN
|
||||
#
|
||||
# Note: BIN/STR are both equated to str in python
|
||||
# ###########################################################################
|
||||
|
||||
# HTSMSG types
|
||||
HMF_MAP = 1
|
||||
HMF_S64 = 2
|
||||
HMF_STR = 3
|
||||
HMF_BIN = 4
|
||||
HMF_LIST = 5
|
||||
|
||||
# Light wrapper for binary type
|
||||
class hmf_bin(str):
|
||||
pass
|
||||
|
||||
# Convert python to HTSMSG type
|
||||
def hmf_type ( f ):
|
||||
if type(f) == list:
|
||||
return HMF_MAP
|
||||
elif type(f) == dict:
|
||||
return HMF_LIST
|
||||
elif type(f) == str:
|
||||
return HMF_STR
|
||||
elif type(f) == int:
|
||||
return HMF_S64
|
||||
elif type(f) == hmf_bin:
|
||||
return HMF_BIN
|
||||
else:
|
||||
raise Exception('invalid type')
|
||||
|
||||
# Size for field
|
||||
def _binary_count ( f ):
|
||||
ret = 0
|
||||
if type(f) in [ str, hmf_bin ]:
|
||||
ret = ret + len(f)
|
||||
elif type(f) == int:
|
||||
while (f):
|
||||
ret = ret + 1
|
||||
f = f >> 8
|
||||
elif type(f) in [ list, map ]:
|
||||
ret = ret + binary_count(f)
|
||||
else:
|
||||
raise Exception('invalid data type')
|
||||
return ret
|
||||
|
||||
# Recursively determine size of message
|
||||
def binary_count ( msg ):
|
||||
ret = 0
|
||||
lst = type(msg) == list
|
||||
for f in msg:
|
||||
ret = ret + 6
|
||||
if not lst:
|
||||
ret = ret + len(f)
|
||||
f = msg[f]
|
||||
ret = ret + _binary_count(f)
|
||||
return ret
|
||||
|
||||
# Write out field in binary form
|
||||
def binary_write ( msg ):
|
||||
ret = ''
|
||||
lst = type(msg) == list
|
||||
for f in msg:
|
||||
na = ''
|
||||
if not lst:
|
||||
na = f
|
||||
f = msg[f]
|
||||
ret = ret + chr(hmf_type(f))
|
||||
ret = ret + chr(len(na) & 0xFF)
|
||||
l = _binary_count(f)
|
||||
ret = ret + int2bin(l)
|
||||
ret = ret + na
|
||||
|
||||
if type(f) in [ list, dict ]:
|
||||
ret = ret + binary_write(f)
|
||||
elif type(f) in [ str, hmf_bin ]:
|
||||
ret = ret + f
|
||||
elif type(f) == int:
|
||||
while f:
|
||||
ret = ret + chr(f & 0xFF)
|
||||
f = f >> 8
|
||||
else:
|
||||
raise Exception('invalid type')
|
||||
return ret
|
||||
|
||||
# Serialize a htsmsg
|
||||
def serialize ( msg ):
|
||||
cnt = binary_count(msg)
|
||||
return int2bin(cnt) + binary_write(msg)
|
||||
|
||||
# Deserialize an htsmsg
|
||||
def deserialize0 ( data ):
|
||||
msg = {}
|
||||
while len(data) > 5:
|
||||
typ = ord(data[0])
|
||||
nlen = ord(data[1])
|
||||
dlen = bin2int(data[2:6])
|
||||
data = data[6:]
|
||||
|
||||
if len < nlen + dlen: raise Exception('not enough data')
|
||||
|
||||
name = data[:nlen]
|
||||
data = data[nlen:]
|
||||
if typ == HMF_STR:
|
||||
item = data[:dlen]
|
||||
elif typ == HMF_BIN:
|
||||
item = hmf_bin(data[:dlen])
|
||||
elif typ == HMF_S64:
|
||||
item = 0
|
||||
i = dlen - 1
|
||||
while i >= 0:
|
||||
item = (item << 8) | ord(data[i])
|
||||
i = i - 1
|
||||
elif typ in [ HMF_LIST, HMF_MAP ]:
|
||||
item = deserialize0(data[:dlen])
|
||||
else:
|
||||
raise Exception('invalid data type %d' % typ)
|
||||
msg[name] = item
|
||||
data = data[dlen:]
|
||||
return msg
|
||||
|
||||
# Deserialize a series of message
|
||||
def deserialize ( fp, rec = False ):
|
||||
class _deserialize:
|
||||
def __init__ ( self, fp, rec = False ):
|
||||
self._fp = fp
|
||||
self._rec = rec
|
||||
def __iter__ ( self ):
|
||||
print '__iter__()'
|
||||
return self
|
||||
def _read ( self, num ):
|
||||
r = None
|
||||
if hasattr(self._fp, 'read'):
|
||||
r = self._fp.read(num)
|
||||
elif hasattr(self._fp, 'recv'):
|
||||
r = self._fp.recv(num)
|
||||
elif type(self._fp) is list:
|
||||
r = self._fp[:num]
|
||||
self._fp = self._fp[num:]
|
||||
else:
|
||||
raise Exception('invalid data type')
|
||||
return r
|
||||
def next ( self ):
|
||||
if not self._fp: raise StopIteration()
|
||||
tmp = self._read(4)
|
||||
if len(tmp) != 4:
|
||||
self._fp = None
|
||||
raise StopIteration()
|
||||
num = bin2int(tmp)
|
||||
data = ''
|
||||
while len(data) < num:
|
||||
tmp = self._read(num - len(data))
|
||||
if not tmp:
|
||||
raise Exception('failed to read from fp')
|
||||
data = data + tmp
|
||||
if not self._rec: self._fp = None
|
||||
return deserialize0(data)
|
||||
ret = _deserialize(fp, rec)
|
||||
if not rec:
|
||||
ret = ret.next()
|
||||
return ret
|
||||
|
||||
# ############################################################################
|
||||
# Editor Configuration
|
||||
#
|
||||
# vim:sts=2:ts=2:sw=2:et
|
||||
# ############################################################################
|
105
lib/py/tvh/htsp.py
Normal file
105
lib/py/tvh/htsp.py
Normal file
|
@ -0,0 +1,105 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2012 Adam Sutton <dev@adamsutton.me.uk>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
This is a very simple HTSP client library written in python mainly just
|
||||
for demonstration purposes.
|
||||
|
||||
Much of the code is pretty rough, but might help people get started
|
||||
with communicating with HTSP server
|
||||
"""
|
||||
|
||||
import htsmsg
|
||||
import log
|
||||
|
||||
# ###########################################################################
|
||||
# HTSP Client
|
||||
# ###########################################################################
|
||||
|
||||
HTSP_PROTO_VERSION = 5
|
||||
|
||||
# Create passwd digest
|
||||
def htsp_digest ( user, passwd, chal ):
|
||||
import hashlib
|
||||
ret = hashlib.sha1(passwd + chal).digest()
|
||||
return ret
|
||||
|
||||
# Client object
|
||||
class HTSPClient:
|
||||
|
||||
# Setup connection
|
||||
def __init__ ( self, addr, name = 'HTSP PyClient' ):
|
||||
import socket
|
||||
|
||||
# Setup
|
||||
self._sock = socket.create_connection(addr)
|
||||
self._name = name
|
||||
self._auth = None
|
||||
self._user = None
|
||||
self._pass = None
|
||||
|
||||
# Send
|
||||
def send ( self, func, args = {} ):
|
||||
args['method'] = func
|
||||
if self._user: args['username'] = self._user
|
||||
if self._pass: args['digest'] = htsmsg.hmf_bin(self._pass)
|
||||
log.debug('htsp tx:')
|
||||
log.debug(args, pretty=True)
|
||||
self._sock.send(htsmsg.serialize(args))
|
||||
|
||||
# Receive
|
||||
def recv ( self ):
|
||||
ret = htsmsg.deserialize(self._sock, False)
|
||||
log.debug('htsp rx:')
|
||||
log.debug(ret, pretty=True)
|
||||
return ret
|
||||
|
||||
# Setup
|
||||
def hello ( self ):
|
||||
args = {
|
||||
'htspversion' : HTSP_PROTO_VERSION,
|
||||
'clientname' : self._name
|
||||
}
|
||||
self.send('hello', args)
|
||||
resp = self.recv()
|
||||
|
||||
# Validate
|
||||
if resp['htspversion'] != HTSP_PROTO_VERSION:
|
||||
raise Exception('version mismatch')
|
||||
self._auth = resp['challenge']
|
||||
|
||||
# Return response
|
||||
return resp
|
||||
|
||||
# Authenticate
|
||||
def authenticate ( self, user, passwd = None ):
|
||||
self._user = user
|
||||
if passwd:
|
||||
self._pass = htsp_digest(user, passwd, self._auth)
|
||||
self.send('authenticate')
|
||||
resp = self.recv()
|
||||
if 'noaccess' in resp:
|
||||
raise Exception('Authentication failed')
|
||||
|
||||
# Enable async receive
|
||||
def enableAsyncMetadata ( self ):
|
||||
self.send('enableAsyncMetadata')
|
||||
|
||||
# ############################################################################
|
||||
# Editor Configuration
|
||||
#
|
||||
# vim:sts=2:ts=2:sw=2:et
|
||||
# ############################################################################
|
67
lib/py/tvh/log.py
Normal file
67
lib/py/tvh/log.py
Normal file
|
@ -0,0 +1,67 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2012 Adam Sutton <dev@adamsutton.me.uk>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Some very basic logging routines
|
||||
"""
|
||||
|
||||
#
|
||||
# Enable debug
|
||||
#
|
||||
DEBUG_LVL = None
|
||||
|
||||
def debug_init ( lvl = None ):
|
||||
global DEBUG_LVL
|
||||
DEBUG_LVL = lvl
|
||||
|
||||
#
|
||||
# Output message
|
||||
#
|
||||
def out ( pre, msg, **dargs ):
|
||||
import sys
|
||||
import datetime, pprint
|
||||
now = datetime.datetime.now()
|
||||
if 'pretty' in dargs and dargs['pretty']:
|
||||
ind = 2
|
||||
if 'indent' in dargs: ind = dargs['indent']
|
||||
msg = pprint.pformat(msg, indent=ind, width=70)
|
||||
out = '%s %-6s: %s\n' % (now.strftime('%F %T'), pre, msg)
|
||||
sys.stderr.write(out)
|
||||
|
||||
#
|
||||
# Debug
|
||||
#
|
||||
def debug ( msg, lvl=1, **dargs ):
|
||||
if DEBUG_LVL and lvl <= DEBUG_LVL:
|
||||
out('DEBUG', msg, **dargs)
|
||||
|
||||
#
|
||||
# Info
|
||||
#
|
||||
def info ( msg, **dargs ):
|
||||
out('INFO', msg, **dargs)
|
||||
|
||||
#
|
||||
# Error
|
||||
#
|
||||
def error ( msg, **dargs ):
|
||||
out('ERROR', msg, **dargs)
|
||||
|
||||
# ############################################################################
|
||||
# Editor Configuration
|
||||
#
|
||||
# vim:sts=2:ts=2:sw=2:et
|
||||
# ############################################################################
|
209
lib/py/tvh/tsreader.py
Normal file
209
lib/py/tvh/tsreader.py
Normal file
|
@ -0,0 +1,209 @@
|
|||
from dvb_charset_tables import conv_8859_table
|
||||
|
||||
def str2hex ( s, n = None ):
|
||||
r = ''
|
||||
i = 0
|
||||
for c in s:
|
||||
r = r + ('%02X ' % ord(c))
|
||||
i = i + 1
|
||||
if n is not None and i % n == 0:
|
||||
r = r + '\n'
|
||||
return r
|
||||
|
||||
def dvb_convert_date ( data ):
|
||||
return 0
|
||||
|
||||
convert_iso_8859 = [
|
||||
-1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, -1, 11, 12, 13
|
||||
]
|
||||
|
||||
|
||||
def encode_utf8 ( c ):
|
||||
if c <= 0x7f:
|
||||
return chr(c)
|
||||
elif c <= 0x7ff:
|
||||
return unichr((c >> 6 & 0x1f) | 0xc0) + unichr((c & 0x3f) | 0x80)
|
||||
return ''
|
||||
|
||||
def conv_8859 ( tnum, data ):
|
||||
r = u''
|
||||
print 'TBL %d' % tnum
|
||||
tbl = conv_8859_table[tnum]
|
||||
for c in data:
|
||||
if ord(c) <= 0x7f:
|
||||
r = r + c
|
||||
elif ord(c) <= 0x9f:
|
||||
r = r + ' '
|
||||
else:
|
||||
uc = tbl[ord(c) - 0xa0]
|
||||
if uc:
|
||||
r = r + encode_utf8(uc)
|
||||
return r
|
||||
|
||||
|
||||
def dvb_convert_string ( data, conv ):
|
||||
print 'convert(%d)' % conv
|
||||
print repr(data)
|
||||
if not conv: return data
|
||||
return conv_8859(conv, data)
|
||||
|
||||
class TsPacket:
|
||||
def __init__ ( self, data ):
|
||||
#print 'TS Packet:'
|
||||
#print str2hex(data, 16)
|
||||
hdr = map(ord, data[:4])
|
||||
if hdr[0] != 0x47:
|
||||
raise Exception('not valid TS packet')
|
||||
self.tx_err = (hdr[1] & 0x80) == 0x80
|
||||
self.pl_init = (hdr[1] & 0x40) == 0x40
|
||||
self.tx_prio = (hdr[1] & 0x20) == 0x20
|
||||
self.pid = ((hdr[1] & 0x1F) << 8) + hdr[2]
|
||||
self.tx_scr = (hdr[3] & 0xC0) >> 6
|
||||
self.adapt = (hdr[3] & 0x30) >> 4
|
||||
self.cont = (hdr[3] & 0x0F)
|
||||
self.data = data[4:]
|
||||
|
||||
class TsSection:
|
||||
def __init__ ( self, pid, data ):
|
||||
hdr = map(ord, data[:3])
|
||||
self.pid = pid
|
||||
self.tid = hdr[0]
|
||||
self.iscrc = (hdr[1] & 0x80) == 0x80
|
||||
self.len = ((hdr[1] & 0x0F) << 8) + hdr[2]
|
||||
self.data = data[3:]
|
||||
#print 'TS Section:'
|
||||
#print hdr
|
||||
#print self.tid, self.len, len(data)
|
||||
|
||||
def process ( self ):
|
||||
print 'TS Section:'
|
||||
print self.tid, self.len, len(self.data)
|
||||
#print str2hex(self.data, 16)
|
||||
#print self.data
|
||||
|
||||
# Strip header
|
||||
hdr = map(ord, self.data[:11])
|
||||
plen = self.len - 11
|
||||
data = self.data[11:]
|
||||
#print str2hex(data, 16)
|
||||
|
||||
# Process each event
|
||||
while plen:
|
||||
r = self.process_event(data, plen)
|
||||
if r < 0: break
|
||||
plen = plen - r
|
||||
data = data[r:]
|
||||
|
||||
def get_string ( self, data, dlen, charset ):
|
||||
#print 'get_string():'
|
||||
#print str2hex(data, 16)
|
||||
l = ord(data[0])
|
||||
if not l: return (None, 0)
|
||||
#print l, dlen
|
||||
if l + 1 > dlen: return (None, -1)
|
||||
c = ord(data[1])
|
||||
print c
|
||||
conv = None
|
||||
if c == 0: return (None, -1)
|
||||
elif c <= 0xb:
|
||||
conv = convert_iso_8859[c + 4]
|
||||
data = data[1:]
|
||||
dlen = dlen - 1
|
||||
elif c <= 0xf: return (None, -1)
|
||||
elif c == 0x10: conv = 0
|
||||
elif c <= 0x14: return (None, -1)
|
||||
elif c == 0x15: conv = 0
|
||||
elif c <= 0x1f: return (None, -1)
|
||||
else:
|
||||
conv = 'default'
|
||||
s = dvb_convert_string(data[1:1+l], conv)
|
||||
return (s, l+1)
|
||||
|
||||
def short_event ( self, data, dlen ):
|
||||
if dlen < 5: return None
|
||||
lang = data[:3]
|
||||
(title, l) = self.get_string(data[3:], dlen-3, None)
|
||||
if l < 0: return None
|
||||
(sumry, l) = self.get_string(data[3+l:], dlen-3-l, None)
|
||||
return (title, sumry)
|
||||
|
||||
def process_event ( self, data, elen ):
|
||||
if (elen < 12): return -1
|
||||
|
||||
# Get lengths
|
||||
hdr = map(ord, data[:12])
|
||||
dllen = ((hdr[10] & 0x0F) << 8) + hdr[11]
|
||||
data = data[12:]
|
||||
elen = elen - 12
|
||||
if elen < dllen: return -1
|
||||
ret = 12 + dllen
|
||||
|
||||
# Header info
|
||||
eid = (hdr[0] << 8) + hdr[1]
|
||||
start = dvb_convert_date(hdr[2:])
|
||||
|
||||
print 'process event (%d):' % dllen
|
||||
print ' EID : %d' % eid
|
||||
print ' START : %d' % start
|
||||
|
||||
while dllen > 2:
|
||||
dtag = ord(data[0])
|
||||
dlen = ord(data[1])
|
||||
print 'dtag = 0x%02x, dlen = %d' % (dtag, dlen)
|
||||
|
||||
dllen = dllen - 2
|
||||
data = data[2:]
|
||||
if dllen < dlen: return ret
|
||||
|
||||
if dtag == 0x4d:
|
||||
(title, summary) = self.short_event(data, dlen)
|
||||
print ' TITLE : %s' % title
|
||||
print ' SUMMARY : %s' % summary
|
||||
|
||||
dllen = dllen - dlen
|
||||
data = data[dlen:]
|
||||
|
||||
return ret
|
||||
|
||||
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
import os, sys
|
||||
fp = open(sys.argv[1])
|
||||
cur = nxt = None
|
||||
while True:
|
||||
pkt = TsPacket(fp.read(188))
|
||||
|
||||
# Restrict to EIT
|
||||
if pkt.pid != 0x12: continue
|
||||
|
||||
# Start/End
|
||||
if pkt.pl_init:
|
||||
ptr = ord(pkt.data[0])
|
||||
if ptr == 0x00:
|
||||
cur = TsSection(pkt.pid, pkt.data[1:])
|
||||
else:
|
||||
if cur:
|
||||
cur.data = cur.data + pkt.data[:1+ptr]
|
||||
nxt = TsSection(pkt.pid, pkt.data[1+ptr:])
|
||||
|
||||
# Middle
|
||||
elif cur:
|
||||
cur.data = cur.data + pkt.data
|
||||
|
||||
# Complete?
|
||||
if cur:
|
||||
if len(cur.data) >= cur.len:
|
||||
print 'Process Section:'
|
||||
#try:
|
||||
cur.process()
|
||||
#except: pass
|
||||
cur = None
|
||||
print
|
||||
sys.exit(0)
|
||||
else:
|
||||
print 'waiting for %d bytes' % (cur.len - len(cur.data))
|
||||
|
||||
# Next
|
||||
if nxt: cur = nxt
|
38
support/epgdump
Executable file
38
support/epgdump
Executable file
|
@ -0,0 +1,38 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2012 Adam Sutton <dev@adamsutton.me.uk>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Dump EPG in human readable format for analysis
|
||||
"""
|
||||
|
||||
# System libs
|
||||
import os, sys
|
||||
import pprint
|
||||
|
||||
# Tvheadend libs
|
||||
sys.path.append(os.path.join(os.path.dirname(__file__), '..', 'lib', 'py'))
|
||||
import tvh.htsmsg as htsmsg
|
||||
|
||||
# Open file
|
||||
fp = open(sys.argv[1], 'rb')
|
||||
for msg in htsmsg.deserialize(fp, True):
|
||||
pprint.pprint(msg, indent=2)
|
||||
|
||||
# ############################################################################
|
||||
# Editor Configuration
|
||||
#
|
||||
# vim:sts=2:ts=2:sw=2:et
|
||||
# ############################################################################
|
78
support/htspmon
Executable file
78
support/htspmon
Executable file
|
@ -0,0 +1,78 @@
|
|||
#!/usr/bin/env python
|
||||
#
|
||||
# Copyright (C) 2012 Adam Sutton <dev@adamsutton.me.uk>
|
||||
#
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation, version 3 of the License.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
#
|
||||
"""
|
||||
Connect to a HTSP server and monitor the asynchronous traffic
|
||||
"""
|
||||
|
||||
# System imports
|
||||
import os, sys, pprint
|
||||
from optparse import OptionParser
|
||||
|
||||
# System path
|
||||
sys.path.insert(0, os.path.join(os.path.dirname(__file__), '..', 'lib', 'py'))
|
||||
import tvh
|
||||
print sys.path
|
||||
|
||||
# TVH imports
|
||||
from tvh.htsp import HTSPClient
|
||||
import tvh.log as log
|
||||
|
||||
try:
|
||||
|
||||
# Command line
|
||||
optp = OptionParser()
|
||||
optp.add_option('-t', '--host', default='localhost',
|
||||
help='Specify HTSP server hostname')
|
||||
optp.add_option('-o', '--port', default=9982, type='int',
|
||||
help='Specify HTSP server port')
|
||||
optp.add_option('-u', '--user', default=None,
|
||||
help='Specify HTSP authentication username')
|
||||
optp.add_option('-p', '--passwd', default=None,
|
||||
help='Specify HTSP authentication password')
|
||||
(opts, args) = optp.parse_args()
|
||||
|
||||
# Connect
|
||||
htsp = HTSPClient((opts.host, opts.port))
|
||||
msg = htsp.hello()
|
||||
log.info('connected to %s [%s]' % (msg['servername'], msg['serverversion']))
|
||||
|
||||
# Authenticate
|
||||
if opts.user:
|
||||
htsp.authenticate(opts.user, opts.passwd)
|
||||
log.info('authenticated as %s' % opts.user)
|
||||
|
||||
# Enable async
|
||||
htsp.enableAsyncMetadata()
|
||||
log.info('enabled async data')
|
||||
|
||||
# Process messages
|
||||
while True:
|
||||
msg = htsp.recv()
|
||||
log.info('message:')
|
||||
log.info(msg, pretty=True)
|
||||
|
||||
except KeyboardInterrupt: pass
|
||||
except Exception, e:
|
||||
log.error(e)
|
||||
sys.exit(1)
|
||||
|
||||
# ############################################################################
|
||||
# Editor Configuration
|
||||
#
|
||||
# vim:sts=2:ts=2:sw=2:et
|
||||
# ############################################################################
|
||||
|
Loading…
Add table
Reference in a new issue