You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

203 lines
5.4 KiB

#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include "lint.h"
const char *
genre(unsigned char b)
{
switch (b)
{
case 0:
return "Unclassified";
case 0x10:
return "Film";
case 0x20:
return "News & Factual";
case 0x30:
return "Entertainment";
case 0x40:
return "Sport";
case 0x50:
return "Children";
case 0x60:
return "Education";
case 0xa0:
return "Lifestyle";
case 0xf0:
return "Drama";
default:
return "Unknown";
}
}
char *
ctimenl(time_t *tm)
{
static char buf[25];
char *p;
strcpy(buf, ctime(tm));
if ((p = strpbrk(buf, "\r\n")))
*p = '\0';
return buf;
}
uint8_t *
strip_string(uint8_t *str)
{
if (str[0] == 0x10 && str[1] == 0x69 && str[2] == 0x37)
return str + 3;
if (*str == 0x15)
return str + 1;
/* non freesat recordings seems to have a 0x05 as the header string */
if (*str == 0x05)
return str + 1;
return str;
}
void
display_hmt(struct hmt *hmt)
{
uint16_t i;
uint16_t j;
time_t tm;
char time_buf[256];
char fullpath[512]={0};
char filename[512]={0};
int posslash = -1;
/* title, epg, def, channel num, channel name, start, end, flags,
* guidance
*/
if (sysopts & SYSOPT_PARSABLE)
{
printf("%s\t", strip_string(hmt->bin + (HMT_TITLE)));
if (hmt->epgstart != NULL)
printf("%s\t", strip_string(hmt->epgstart + HMT_EPG));
else
printf("\t");
printf("%s\t", hmt->bin[HMT_FLAGS2] & HMT_FLAGS2_HD ? "HD" : "SD");
i = read_uint16(hmt->bin + HMT_CHANNEL_NUM, 0);
printf("%i\t%s\t", i,
strip_string(hmt->bin + HMT_CHANNEL_NAME));
tm = read_uint32(hmt->bin + HMT_RECORDING_START, 0);
(void) strftime(time_buf, sizeof(time_buf), "%a %b %d %H:%M:%S %Y", gmtime(&tm));
printf("%s\t", time_buf);
printf("%lu\t", tm);
tm = read_uint32(hmt->bin + HMT_RECORDING_END, 0);
(void) strftime(time_buf, sizeof(time_buf), "%a %b %d %H:%M:%S %Y", gmtime(&tm));
printf("%s\t", time_buf);
printf("%lu\t", tm);
printf("%s%s%s%s%s",
hmt->bin[HMT_FLAGS1] & HMT_FLAGS1_LOCKED ? "Locked," : "",
hmt->bin[HMT_FLAGS1] & HMT_FLAGS1_NEW ? "" : "New,",
hmt->bin[HMT_FLAGS1] & HMT_FLAGS1_PROTECTED? "Protected," : "",
hmt->bin[HMT_FLAGS2] & HMT_FLAGS2_ENCRYPTED ? "Encrypted," : "",
hmt->epgguidance != NULL ? "Guidance," : ""
);
if (hmt->bin[HMT_CONVERT_FLAG] == 'P')
printf("Converting,\t");
else
if (hmt->bin[HMT_CONVERT_FLAG] == 'F')
printf("Converted,\t");
else
printf("Unconverted,\t");
if (hmt->epgguidance != NULL)
printf("%s\t", strip_string(hmt->epgguidance));
printf("\n");
return;
}
i = read_uint16(hmt->bin + HMT_CHANNEL_NUM, 0);
memcpy(fullpath, hmt->bin + HMT_FOLDER, sizeof(fullpath));
posslash = (strrchr(fullpath, '/') - fullpath);
memcpy(filename, hmt->bin + HMT_FOLDER + posslash + 1, (sizeof(fullpath) - posslash));
fullpath[posslash+1]=0;
printf("Format: %s\n", hmt->bin[HMT_FLAGS2] & HMT_FLAGS2_HD ? "HD" : "SD");
printf("Title: %s\n", strip_string(hmt->bin + (HMT_TITLE)));
printf("Channel: %i (%s)\n", i, hmt->bin + HMT_CHANNEL_NAME);
printf("Folder: %s\n", fullpath);
printf("Filename: %s.ts\n", filename);
if (hmt->epgstart != NULL) {
printf("EPG: %s\n", strip_string(hmt->epgstart + HMT_EPG));
} else {
printf("EPG:\n");
}
if (hmt->epgguidance != NULL)
printf("Guidance: %s\n", strip_string(hmt->epgguidance));
printf("\n");
printf("Flags: %s%s%s%s%s%s",
hmt->bin[HMT_FLAGS2] & HMT_FLAGS2_HD ? "HD," : "SD,",
hmt->bin[HMT_FLAGS1] & HMT_FLAGS1_LOCKED ? "Locked," : "",
hmt->bin[HMT_FLAGS1] & HMT_FLAGS1_NEW ? "" : "New,",
hmt->bin[HMT_FLAGS1] & HMT_FLAGS1_PROTECTED? "Protected," : "",
hmt->bin[HMT_FLAGS2] & HMT_FLAGS2_ENCRYPTED ? "Encrypted," : "",
hmt->epgguidance != NULL ? "Guidance," : ""
);
if (hmt->bin[HMT_CONVERT_FLAG] == 'P')
printf("Converting,\n");
else
if (hmt->bin[HMT_CONVERT_FLAG] == 'F')
printf("Converted,\n");
else
printf("Unconverted,\n");
printf("Copy count: %d\n", hmt->bin[HMT_COPYCOUNT]);
printf("\n");
tm = read_uint32(hmt->epgstart + HMT_SCHEDULED_START, 0);
(void) strftime(time_buf, sizeof(time_buf), "%a %b %d %H:%M:%S %Y", gmtime(&tm));
printf("Scheduled start: %s\n", time_buf);
/* printf("Scheduled start:%lu (%s)\n", tm, ctimenl(&tm)); */
tm = read_uint32(hmt->epgstart + HMT_SCHEDULED_DURATION, 0);
printf("Scheduled duration: %lu\n", tm);
tm = read_uint32(hmt->bin + HMT_RECORDING_START, 0);
(void) strftime(time_buf, sizeof(time_buf), "%a %b %d %H:%M:%S %Y", gmtime(&tm));
printf("Recording start: %s\n", time_buf);
/* printf("Recording start:%lu (%s)\n", tm, ctimenl(&tm)); */
tm = read_uint32(hmt->bin + HMT_RECORDING_END, 0);
(void) strftime(time_buf, sizeof(time_buf), "%a %b %d %H:%M:%S %Y", gmtime(&tm));
printf("Recording end: %s\n", time_buf);
/* printf("Recording end:%lu (%s)\n", tm, ctimenl(&tm)); */
/* printf("Play resumes at: %i seconds in.\n", read_uint16(hmt->bin + HMT_PLAYED_TIME, 0)); */
printf("\n");
j = read_uint16(hmt->bin + HMT_SID, 0);
printf("Service ID (SID): %u\n", j);
j = read_uint16(hmt->bin + HMT_TSID, 0);
printf("Transport Stream ID (TSID): %u\n", j);
j = read_uint16(hmt->bin + HMT_ONID, 0);
printf("Originating Network ID (ONID): %u\n", j);
j = read_uint16(hmt->bin + HMT_PMTPID, 0);
printf("Programme Map Table PID (PMTPID): %u\n", j);
j = read_uint16(hmt->bin + HMT_VIDEOPID, 0);
printf("Video PID: %u\n", j);
j = read_uint16(hmt->bin + HMT_AUDIOPID, 0);
printf("Audio PID: %u\n", j);
}