/
GuideParser.cpp
1588 lines (1299 loc) · 50.8 KB
/
GuideParser.cpp
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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** ReplayTV 5000
** Guide Parser
** by Lee Thompson <thompsonl@logh.net> Dan Frumin <rtv@frumin.com>, Todd Larason <jtl@molehill.org>
**
** 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.
**
** If you distribute a modified version of this program, the program MUST tell the user
** in the usage summary how the program has been modified, and who performed the modification.
** Modified source code MUST be distributed with the modified program.
**
** For additional detail on the Replay 4000/4500/5000 internals, protocols and structures I highly recommend
** visiting Todd's site: http://www.molehill.org/twiki/bin/view/Replay/WebHome
**
***************************************************************************************************************
**
** IMPORTANT NOTE: This is the last version of GuideParser with this codebase.
**
** GuideParser was originally just a research project to learn the Guide Snapshot format. This research
** phase is pretty much at a close and this code is very ugly.
**
** Others wishing to continue development of GuideParser with this code are welcome to do so under the above
** limitations.
**
***************************************************************************************************************
**
** Revision History:
**
** 1.02 - LT Updated for 5.0 Software
** 1.01 - LT ReplayTV 5000
** 1.0 - LT Final version with this codebase.
** Organized the structures a bit better.
** Fixed some annoying bugs.
** Added -combined option which does a mini replayChannel lookup, best used with -ls
** .11 - LT Whoops! ReplayChannel had the wrong number for szThemeInfo, should've been 64 not 60! (Thanks Clem!)
** Todd corrected a mis-assigned bitmask for TV rating "TV-G"
** Todd's been knocking himself out with research... as a result no more unknowns in tagProgramInfo!
** Added Genre lookups
** .10 - LT Works on FreeBSD now (thanks Andy!)
** Fixed a minor display bug.
** Supports MPAA "G" ratings.
** Added -d option for dumping unknowns as numbers.
** Added -x (Xtra) option for displaying TMSIDs and so forth.
** Added -nowrap to supress word wrap.
** Added STDIN support!
** Added Input Source lookup.
** Better organized sub-structures.
** Channel/Show Output now uses the word wrapper for everything.
** Some minor tweaks.
** Less unknowns. (Thanks in large part to Todd)
** Released on Mar 10th 2002
** .09 - LT Wrote an int64 Big->Small Endian converter.
** UNIX/WIN32 stuff sorted out.
** Cleaned up some code.
** Dependency on stdafx.h removed.
** Improved Word Wrapper.
** Fixed some bugs.
** Less unknowns.
** Released on Jan 13th 2002
** .08 - LT More fixes!
** Better wordwrapping!
** Less unknowns!
** Released on Jan 10th 2002
** .07 - LT Categories :)
** Dan added the extraction command line switches and code.
** Released on Jan 8th 2002
** .06 - LT Timezone fixes
** Released on Jan 5th 2002
** .05 - LT Checking to see if guide file is damaged (some versions of ReplayPC have a problem in this area)
** Found a case where GuideHeader.replayshows is not accurate!
** Lots of other fixes.
** Released on Jan 4th 2002
** .04 - LT Day of Week implemented.
** Categories are loaded but lookup isn't working.
** .03 - LT Private build.
** .02 - LT Private build.
** .01 - LT Private build.
** Initial Version
** 01/03/2002
**
**
***************************************************************************************************************
**
** TO DO:
**
** 1. Rewrite!
**
**
** BUGS
** Piping from replaypc to guideparser gets a few replaychannels in and somehow loses it's alignment -- looks
** like the 'file' is being truncated.
**
***************************************************************************************************************
** FreeBSD fixes by Andrew Tulloch <andrew@biliskner.demon.co.uk>
***************************************************************************************************************
*/
#ifdef _XBOX
#include <Xtl.h>
#pragma pack(1) // don't use byte alignments on the structs
#endif
#ifdef _WIN32
#if !defined(AFX_STDAFX_H__11AD8D81_EA54_4CD0_9A74_44F7170DE43F__INCLUDED_)
#define AFX_STDAFX_H__11AD8D81_EA54_4CD0_9A74_44F7170DE43F__INCLUDED_
#endif
#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000
#pragma pack(1) // don't use byte alignments on the structs
#define WIN32_LEAN_AND_MEAN
#if defined (_WIN32) && !defined(_XBOX)
#include <winsock2.h>
#endif
#include <winnt.h>
#include <winbase.h>
#endif
#if (defined(__unix__) || defined(__APPLE__))
#include <netinet/in.h>
#endif
#include <string.h>
#include <memory.h>
#include <math.h>
#include <stdio.h>
#include <time.h>
#include <fcntl.h>
#if defined (_WIN32) && !defined(_XBOX)
#pragma comment(lib, "ws2_32.lib") // load winsock2 (we only use it for endian conversion)
#define FILEPOS fpos_t
#endif
#ifdef __APPLE__
#include <AvailabilityMacros.h>
#endif
#if defined(__unix__) || defined(__APPLE__)
typedef unsigned char BYTE;
typedef unsigned long long DWORD64;
typedef unsigned long DWORD;
typedef unsigned short WORD;
#define FILEPOS unsigned long
#define _tzset() tzset()
#define _tzname tzname
#define _timezone timezone
#define MoveMemory(dst,src,len) memmove(dst,src,len)
#define HIWORD(x) (WORD)(x >> 16)
#endif
extern int _daylight;
#if defined(__APPLE__) && (MAC_OS_X_VERSION_MAX_ALLOWED > 1040)
extern long _timezone;
#endif
#ifndef _WIN32
extern char *_tzname[2];
#endif
#define SHOWSTRUCTURESIZES 1 // this is for debugging...
#undef SHOWSTRUCTURESIZES // ...uncomment this line for structure sizes to be shown
// 5.0
#define REPLAYSHOW 512 // needed size of replayshow structure
#define GUIDEHEADER 840 // needed size of guideheader structure
#define PROGRAMINFO 272 // needed size of programinfo structure
#define CHANNELINFO 80 // needed size of channelinfo structure
// 4.5
#define GUIDEHEADER45 808 // needed size of guideheader structure
// 4.3
#define GUIDEHEADER43 808 // needed size of guideheader structure
#define REPLAYSHOW43 444 // needed size of replayshow structure
#define MAXCHANNELS 99
#define lpszTitle "ReplayTV 5000 (Alpha) GuideParser v1.02 (Build 17)"
#define lpszCopyright "(C) 2002 Lee Thompson, Dan Frumin, Todd Larason, and Andrew Tulloch"
#define lpszComment ""
//-------------------------------------------------------------------------
// Data Structures
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
//******************** COMMENTS *******************************************
//-------------------------------------------------------------------------
/*
** General ReplayTV Notes
**
** The RTV4K/5K platforms are capable of supporting NTSC, PAL and SECAM so
** in theory there may be one or more bytes always set a certain way as they
** reflect NTSC.
**
** On the subject of recorded time: The ReplayTV units appear to
** automatically pad shows by 3 seconds. e.g. If you schedule a show that
** airs at 6:00 PM, the recording will actually begin at 5:59:57 PM.
** Because of this, even an unpadded show will have a 3 second discrepency
** between ReplayShow.recorded and ReplayShow.eventtime.
**
**
** Categories
**
** There appears to be an *internal* maximum of 32 but the units appear
** to only use 17 total.
**
** Secondary Offset (GuideHeader)
**
** If you jump to this absolute location this repeats the first 12 bytes of
** this header, null terminates and then 4 unknown DWORDs.
**
** You will then be at the first byte of the first ReplayChannel record.
**
**
** Genre Codes
** Todd Larason's been slowly figuring these out, you can see the list at
** http://www.molehill.org/twiki/bin/view/Replay/RnsGetCG2
**
*/
/**************************************************************************
**
** GUIDE HEADER
**
**
** Most of the unknowns in the GuideHeader are garbage/junk. Why
** these aren't initialized to null I have no idea.
**
** They may also be a memory structure that has no meaning on a 'remote unit'.
**
**************************************************************************/
// 5000 OS Version 5.0
typedef struct tagGuideSnapshotHeader {
WORD osversion; // OS Version (5 for 4.5, 3 for 4.3, 0 on 5.0)
WORD snapshotversion; // Snapshot Version (1) (2 on 5.0) This might be better termed as snapshot version
DWORD structuresize; // Should always be 64
DWORD unknown1; // 0x00000002
DWORD unknown2; // 0x00000005
DWORD channelcount; // Number of Replay Channels
DWORD channelcountcheck; // Should always be equal to channelcount, it's incremented as the snapshot is built.
DWORD unknown3; // 0x00000000
DWORD groupdataoffset; // Offset of Group Data
DWORD channeloffset; // Offset of First Replay Channel (If you don't care about categories, jump to this)
DWORD showoffset; // Offset of First Replay Show (If you don't care about ReplayChannels, jump to this)
DWORD snapshotsize; // Total Size of the Snapshot
DWORD unknown4; // 0x00000001
DWORD unknown5; // 0x00000004
DWORD flags; // Careful, this is uninitialized, ignore invalid bits
DWORD unknown6; // 0x00000002
DWORD unknown7; // 0x00000000
} GuideSnapshotHeader;
typedef struct tagGroupData {
DWORD structuresize; // Should always be 776
DWORD categories; // Number of Categories (MAX: 32 [ 0 - 31 ] )
DWORD category[32]; // category lookup 2 ^ number, position order = text
DWORD categoryoffset[32]; // Offsets for the GuideHeader.catbuffer
char catbuffer[512]; // GuideHeader.categoryoffset contains the starting position of each category.
} GroupData;
typedef struct tagGuideHeader {
struct tagGuideSnapshotHeader GuideSnapshotHeader;
struct tagGroupData GroupData;
} GuideHeader;
// 4000 OS Version 4.3 / 5000 OS Version 4.5
typedef struct tagGuideSnapshotHeader45 {
WORD osversion; // Major Revision (5 for Replay5000s, 3 for Replay 4000/4500s)
WORD snapshotversion; // Minor Revision (1)
DWORD structuresize; // Should always be 32
DWORD channelcount; // Number of Replay Channels
DWORD channelcountcheck; // Number of Replay Channels (Copy 2; should always match)
DWORD groupdataoffset; // Offset of Group Data
DWORD channeloffset; // Offset of First Replay Channel (If you don't care about categories, jump to this)
DWORD showoffset; // Offset of First Replay Show (If you don't care about ReplayChannels, jump to this)
DWORD flags; // Careful, this is uninitialized, ignore invalid bits
} GuideSnapshotHeader45;
// GroupData structure is the same for 4.3/4.5 and 5.0
typedef struct tagGuideHeader45 {
struct tagGuideSnapshotHeader45 GuideSnapshotHeader;
struct tagGroupData GroupData;
} GuideHeader45;
/*******************************************************************************
**
** SUB-STRUCTURES
**
*******************************************************************************/
//-------------------------------------------------------------------------
// Movie Extended Info Structure
typedef struct tagMovieInfo {
WORD mpaa; // MPAA Rating
WORD stars; // Star Rating * 10 (i.e. value of 20 = 2 stars)
WORD year; // Release Year
WORD runtime; // Strange HH:MM format
} MovieInfo;
//-------------------------------------------------------------------------
// Has Parts Info Structure
typedef struct tagPartsInfo {
WORD partnumber; // Part X [Of Y]
WORD maxparts; // [Part X] Of Y
} PartsInfo;
//--------------------------------------------------------------------------
// Program Info Structure
typedef struct tagProgramInfo {
DWORD structuresize; // Should always be 272 (0x0110)
DWORD autorecord; // If non-zero it is an automatic recording, otherwise it is a manual recording.
DWORD isvalid; // Not sure what it actually means! (should always be 1 in exported guide)
DWORD tuning; // Tuning (Channel Number) for the Program
DWORD flags; // Program Flags
DWORD eventtime; // Scheduled Time of the Show
DWORD tmsID; // Tribune Media Services ID (inherited from ChannelInfo)
WORD minutes; // Minutes (add with show padding for total)
BYTE genre1; // Genre Code 1
BYTE genre2; // Genre Code 2
BYTE genre3; // Genre Code 3
BYTE genre4; // Genre Code 4
WORD recLen; // Record Length of Description Block
BYTE titleLen; // Length of Title
BYTE episodeLen; // Length of Episode
BYTE descriptionLen; // Length of Description
BYTE actorLen; // Length of Actors
BYTE guestLen; // Length of Guest
BYTE suzukiLen; // Length of Suzuki String (Newer genre tags)
BYTE producerLen; // Length of Producer
BYTE directorLen; // Length of Director
char szDescription[228]; // This can have parts/movie sub-structure
} ProgramInfo;
//--------------------------------------------------------------------------
// Channel Info Structure
typedef struct tagChannelInfo {
DWORD structuresize; // Should always be 80 (0x50)
DWORD usetuner; // If non-zero the tuner is used, otherwise it's a direct input.
DWORD isvalid; // Record valid if non-zero
DWORD tmsID; // Tribune Media Services ID
WORD channel; // Channel Number
BYTE device; // Device
BYTE tier; // Cable/Satellite Service Tier
char szChannelName[16]; // Channel Name
char szChannelLabel[32]; // Channel Description
char cablesystem[8]; // Cable system ID
DWORD channelindex; // Channel Index (USUALLY tagChannelinfo.channel repeated)
} ChannelInfo;
/*******************************************************************************
**
** REPLAY SHOW
**
*******************************************************************************/
typedef struct tagReplayShow {
DWORD created; // ReplayChannel ID (tagReplayChannel.created)
DWORD recorded; // Filename/Time of Recording (aka ShowID)
DWORD inputsource; // Replay Input Source
DWORD quality; // Recording Quality Level
DWORD guaranteed; // (0xFFFFFFFF if guaranteed)
DWORD playbackflags; // Not well understood yet.
struct tagChannelInfo ChannelInfo;
struct tagProgramInfo ProgramInfo;
DWORD ivsstatus; // Always 1 in a snapshot outside of a tagReplayChannel
DWORD guideid; // The show_id on the original ReplayTV for IVS shows. Otherwise 0
DWORD downloadid; // Valid only during actual transfer of index or mpeg file; format/meaning still unknown
DWORD timessent; // Times sent using IVS
DWORD seconds; // Show Duration in Seconds (this is the exact actual length of the recording)
DWORD GOP_count; // MPEG Group of Picture Count
DWORD GOP_highest; // Highest GOP number seen, 0 on a snapshot.
DWORD GOP_last; // Last GOP number seen, 0 on a snapshot.
DWORD checkpointed; // 0 in possibly-out-of-date in-memory copies; always -1 in snapshots
DWORD intact; // 0xffffffff in a snapshot; 0 means a deleted show
DWORD upgradeflag; // Always 0 in a snapshot
DWORD instance; // Episode Instance Counter (0 offset)
WORD unused; // Not preserved when padding values are set, presumably not used
BYTE beforepadding; // Before Show Padding
BYTE afterpadding; // After Show Padding
DWORD64 indexsize; // Size of NDX file (IVS Shows Only)
DWORD64 mpegsize; // Size of MPG file (IVS Shows Only)
char szReserved[68]; // Show Label (NOT PRESENT in 4k 4.3 version, work around it)
} ReplayShow;
//-------------------------------------------------------------------------
// WIN32 Functions
//-------------------------------------------------------------------------
#ifdef _WIN32
//-------------------------------------------------------------------------
void UnixTimeToFileTime(time_t t, LPFILETIME pft)
{
LONGLONG ll;
ll = Int32x32To64(t, 10000000) + 116444736000000000;
pft->dwLowDateTime = (DWORD)ll;
pft->dwHighDateTime = (DWORD)(ll >> 32);
}
//-------------------------------------------------------------------------
void UnixTimeToSystemTime(time_t t, LPSYSTEMTIME pst)
{
FILETIME ft;
UnixTimeToFileTime(t, &ft);
FileTimeToSystemTime(&ft, pst);
}
//-------------------------------------------------------------------------
char * UnixTimeToString(time_t t)
{
static char sbuf[17];
char szTimeZone[32];
SYSTEMTIME st;
int tzbias;
_tzset();
memset(szTimeZone,0,sizeof(szTimeZone));
MoveMemory(szTimeZone,_tzname[0],1);
strcat(szTimeZone,"T");
#if (MAC_OS_X_VERSION_MAX_ALLOWED <= 1040) && !defined(_WIN32)
struct timezone tz;
gettimeofday(NULL, &tz);
tzbias = tz.tz_minuteswest;
#else
tzbias = _timezone;
#endif
UnixTimeToSystemTime(t - tzbias, &st);
sprintf(sbuf, "%d-%.2d-%.2d %.2d:%.2d:%.2d",
st.wYear, st.wMonth, st.wDay, st.wHour, st.wMinute, st.wSecond);
return sbuf;
}
#endif
//-------------------------------------------------------------------------
// UNIX Functions
//-------------------------------------------------------------------------
#if defined(__unix__) || defined(__APPLE__)
char * UnixTimeToString(time_t t)
{
static char sbuf[17];
struct tm * tm;
tm = localtime(&t);
strftime(sbuf, sizeof(sbuf), "%Y-%m-%d %H:%M:%S", tm);
return sbuf;
}
#endif
//-------------------------------------------------------------------------
// Common Functions
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// Lookup Tables
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
void DisplayQuality(int quality, char *szQuality)
{
switch( quality )
{
case 0:
strcpy( szQuality, "High" );
break;
case 1:
strcpy( szQuality, "Medium" );
break;
case 2:
strcpy( szQuality, "Standard" );
break;
default:
strcpy( szQuality, "" );
break;
}
}
//-------------------------------------------------------------------------
void DisplayExtendedTVRating(int tvrating, char *szRating, bool append)
{
if (append == false)
{
strcpy( szRating, "");
}
if (tvrating & 0x00020000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "S" ); // Sex
}
if (tvrating & 0x00040000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "V" ); // Violence
}
if (tvrating & 0x00080000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "L" ); // Language
}
if (tvrating & 0x00100000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "D" ); // Drug Use
}
if (tvrating & 0x00200000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "F" ); // Fantasy Violence
}
}
//-------------------------------------------------------------------------
void DisplayTVRating(int tvrating, char *szRating)
{
strcpy( szRating, "");
if (tvrating & 0x00008000)
{
strcpy( szRating, "TV-Y" );
}
if (tvrating & 0x00010000)
{
strcpy( szRating, "TV-Y7" );
}
if (tvrating & 0x00001000)
{
strcpy( szRating, "TV-G" );
}
if (tvrating & 0x00004000)
{
strcpy( szRating, "TV-PG" );
}
if (tvrating & 0x00002000)
{
strcpy( szRating, "TV-MA" );
}
if (tvrating & 0x00000800)
{
strcpy( szRating, "TV-14" );
}
}
//-------------------------------------------------------------------------
void DisplayExtendedMPAARating(int mpaarating, char *szRating, bool append)
{
if (append == false)
{
strcpy( szRating, "");
}
if (mpaarating & 0x00400000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "AC" ); // Adult Content
}
if (mpaarating & 0x00800000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "BN" ); // Brief Nudity
}
if (mpaarating & 0x01000000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "GL" ); // Graphic Language
}
if (mpaarating & 0x02000000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "GV" ); // Graphic Violence
}
if (mpaarating & 0x04000000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "AL" ); // Adult Language
}
if (mpaarating & 0x08000000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "MV" ); // Mild Violence
}
if (mpaarating & 0x10000000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "N" ); // Nudity
}
if (mpaarating & 0x20000000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "RP" ); // Rape
}
if (mpaarating & 0x40000000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "SC " ); // Sexual Content
}
if (mpaarating & 0x80000000)
{
if (strlen(szRating) > 0)
{
strcat( szRating, " ");
}
strcat( szRating, "V" ); // Violence
}
}
//-------------------------------------------------------------------------
void DisplayMPAARating(int mpaarating, char *szRating)
{
strcpy( szRating, "");
if (mpaarating & 0x00000001)
{
strcat( szRating, "AO" ); // unverified
}
if (mpaarating & 0x00000002)
{
strcat( szRating, "G" );
}
if (mpaarating & 0x00000004)
{
strcat( szRating, "NC-17" );
}
if (mpaarating & 0x00000008)
{
strcat( szRating, "NR" );
}
if (mpaarating & 0x00000010)
{
strcat( szRating, "PG" );
}
if (mpaarating & 0x00000020)
{
strcat( szRating, "PG-13" );
}
if (mpaarating & 0x00000040)
{
strcat( szRating, "R" );
}
}
//-------------------------------------------------------------------------
// Data Presentation Functions
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
void ConvertCodepage(char *szString)
{
unsigned int i = 0;
char ch;
if (szString[0] == 0)
{
return;
}
for( i = 0; i < strlen(szString); ++i )
{
ch = szString[i];
// Windows Codepage Translation to DOS/UNIX etc
if (ch == (char)146)
{
szString[i] = '\'';
}
if (ch == (char)147)
{
szString[i] = '\"';
}
if (ch == (char)148)
{
szString[i] = '\"';
}
#ifdef _WIN32
// Windows (Console) specific translations
#endif
#if defined(__unix__) || defined(__APPLE__)
// UNIX specific translations
#endif
}
return;
}
//-------------------------------------------------------------------------
// Misc. Functions
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
int CalculateMinutes( int seconds )
{
int retval = 0;
double result1 = 0.0;
double result2 = 0.0;
if (seconds < 1)
{
return 0;
}
result1 = seconds / 60;
result2 = seconds % 60;
if (result2 > .0) // this will round up if there's any remainder,
// could also make this .5 etc
{
retval = (int)result1 + 1;
}
else
{
retval = (int)result1;
}
return retval;
}
//-------------------------------------------------------------------------
// ENDIAN CONVERSION FUNCTIONS
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
// LONGLONG/INT64 Endian Conversion
//-------------------------------------------------------------------------
//-------------------------------------------------------------------------
#if _MSC_VER < 1700
DWORD64 ntohll(DWORD64 llValue)
{
DWORD64 retval = 0;
// This is really cheesy but it works so that's all that matters
// If someone out there wants to replace this with something cooler,
// please feel free to do so!
char szBuffer[17];
char szInt64[17];
memset(szBuffer,0,sizeof(szBuffer));
memset(szInt64,0,sizeof(szInt64));
MoveMemory(szBuffer,&llValue,sizeof(llValue));
size_t cc = sizeof(llValue) - 1;
size_t i = 0;
for( i = 0; i < sizeof(llValue); ++i )
{
szInt64[i] = szBuffer[cc];
--cc;
}
MoveMemory(&retval,szInt64,sizeof(retval));
return retval;
}
#endif // _MSC_VER < 1700
//-------------------------------------------------------------------------
void ConvertProgramInfoEndian(struct tagProgramInfo * strProgramInfo)
{
strProgramInfo->autorecord = ntohl(strProgramInfo->autorecord);
strProgramInfo->eventtime = ntohl(strProgramInfo->eventtime);
strProgramInfo->flags = ntohl(strProgramInfo->flags);
strProgramInfo->isvalid = ntohl(strProgramInfo->isvalid);
strProgramInfo->minutes = ntohs(strProgramInfo->minutes);
strProgramInfo->recLen = ntohs(strProgramInfo->recLen);
strProgramInfo->structuresize = ntohl(strProgramInfo->structuresize);
strProgramInfo->tuning = ntohl(strProgramInfo->tuning);
strProgramInfo->tmsID = ntohl(strProgramInfo->tmsID);
return;
}
//-------------------------------------------------------------------------
void ConvertMovieInfoEndian(struct tagMovieInfo * strMovieInfo)
{
strMovieInfo->mpaa = ntohs(strMovieInfo->mpaa);
strMovieInfo->runtime = ntohs(strMovieInfo->runtime);
strMovieInfo->stars = ntohs(strMovieInfo->stars);
strMovieInfo->year = ntohs(strMovieInfo->year);
return;
}
//-------------------------------------------------------------------------
void ConvertPartsInfoEndian(struct tagPartsInfo * strPartsInfo)
{
strPartsInfo->maxparts = ntohs(strPartsInfo->maxparts);
strPartsInfo->partnumber = ntohs(strPartsInfo->partnumber);
return;
}
//-------------------------------------------------------------------------
void ConvertReplayShowEndian(struct tagReplayShow * strReplayShow)
{
strReplayShow->checkpointed = ntohl(strReplayShow->checkpointed);
strReplayShow->created = ntohl(strReplayShow->created);
strReplayShow->downloadid = ntohl(strReplayShow->downloadid);
strReplayShow->GOP_count = ntohl(strReplayShow->GOP_count);
strReplayShow->GOP_highest = ntohl(strReplayShow->GOP_highest);
strReplayShow->GOP_last = ntohl(strReplayShow->GOP_last);
strReplayShow->guaranteed = ntohl(strReplayShow->guaranteed);
strReplayShow->guideid = ntohl(strReplayShow->guideid);
strReplayShow->indexsize = ntohll(strReplayShow->indexsize);
strReplayShow->inputsource = ntohl(strReplayShow->inputsource);
strReplayShow->instance = ntohl(strReplayShow->instance);
strReplayShow->intact = ntohl(strReplayShow->intact);
strReplayShow->ivsstatus = ntohl(strReplayShow->ivsstatus);
strReplayShow->mpegsize = ntohll(strReplayShow->mpegsize);
strReplayShow->playbackflags = ntohl(strReplayShow->playbackflags);
strReplayShow->quality = ntohl(strReplayShow->quality);
strReplayShow->recorded = ntohl(strReplayShow->recorded);
strReplayShow->seconds = ntohl(strReplayShow->seconds);
strReplayShow->timessent = ntohl(strReplayShow->timessent);
strReplayShow->upgradeflag = ntohl(strReplayShow->upgradeflag);
strReplayShow->unused = ntohs(strReplayShow->unused);
return;
}
//-------------------------------------------------------------------------
void ConvertReplayGuideEndian(struct tagGuideHeader * strGuideHeader)
{
strGuideHeader->GroupData.categories = ntohl(strGuideHeader->GroupData.categories);
strGuideHeader->GroupData.structuresize = ntohl(strGuideHeader->GroupData.structuresize);
strGuideHeader->GuideSnapshotHeader.snapshotsize = ntohl(strGuideHeader->GuideSnapshotHeader.snapshotsize);
strGuideHeader->GuideSnapshotHeader.channeloffset = ntohl(strGuideHeader->GuideSnapshotHeader.channeloffset);
strGuideHeader->GuideSnapshotHeader.flags = ntohl(strGuideHeader->GuideSnapshotHeader.flags);
strGuideHeader->GuideSnapshotHeader.groupdataoffset = ntohl(strGuideHeader->GuideSnapshotHeader.groupdataoffset);
strGuideHeader->GuideSnapshotHeader.osversion = ntohs(strGuideHeader->GuideSnapshotHeader.osversion);
strGuideHeader->GuideSnapshotHeader.snapshotversion = ntohs(strGuideHeader->GuideSnapshotHeader.snapshotversion);
strGuideHeader->GuideSnapshotHeader.channelcount = ntohl(strGuideHeader->GuideSnapshotHeader.channelcount);
strGuideHeader->GuideSnapshotHeader.channelcountcheck = ntohl(strGuideHeader->GuideSnapshotHeader.channelcountcheck);
strGuideHeader->GuideSnapshotHeader.showoffset = ntohl(strGuideHeader->GuideSnapshotHeader.showoffset);
strGuideHeader->GuideSnapshotHeader.unknown1 = ntohl(strGuideHeader->GuideSnapshotHeader.unknown1);
strGuideHeader->GuideSnapshotHeader.unknown2 = ntohl(strGuideHeader->GuideSnapshotHeader.unknown2);
strGuideHeader->GuideSnapshotHeader.unknown3 = ntohl(strGuideHeader->GuideSnapshotHeader.unknown3);
strGuideHeader->GuideSnapshotHeader.unknown4 = ntohl(strGuideHeader->GuideSnapshotHeader.unknown4);
strGuideHeader->GuideSnapshotHeader.unknown5 = ntohl(strGuideHeader->GuideSnapshotHeader.unknown5);
strGuideHeader->GuideSnapshotHeader.unknown6 = ntohl(strGuideHeader->GuideSnapshotHeader.unknown6);
strGuideHeader->GuideSnapshotHeader.unknown7 = ntohl(strGuideHeader->GuideSnapshotHeader.unknown7);
for( unsigned int cc = 0; cc < strGuideHeader->GroupData.categories; ++cc )
{
strGuideHeader->GroupData.category[cc] = ntohl(strGuideHeader->GroupData.category[cc]);
strGuideHeader->GroupData.categoryoffset[cc] = ntohl(strGuideHeader->GroupData.categoryoffset[cc]);
}
{
strGuideHeader->GuideSnapshotHeader.structuresize = ntohl(strGuideHeader->GuideSnapshotHeader.structuresize);
}
return;
}
//-------------------------------------------------------------------------
void ConvertReplayGuide45To50Endian(struct tagGuideHeader45 * strGuideHeader45, struct tagGuideHeader * strGuideHeader)
{
strGuideHeader->GroupData.categories = ntohl(strGuideHeader45->GroupData.categories);
strGuideHeader->GroupData.structuresize = ntohl(strGuideHeader45->GroupData.structuresize);
strGuideHeader->GuideSnapshotHeader.snapshotsize = 0;
strGuideHeader->GuideSnapshotHeader.channeloffset = ntohl(strGuideHeader45->GuideSnapshotHeader.channeloffset);