-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmungeM3U.c
1745 lines (1516 loc) · 44.5 KB
/
mungeM3U.c
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
/**
Copyright © Paul Chambers, 2020.
@ToDo Switch to UTF-8 string handling, rather than relying on ASCII backwards-compatibility
*/
#define _GNU_SOURCE
#include <stdlib.h>
#include <stdio.h>
#include <errno.h>
#include <string.h>
#include <ctype.h>
#include <sys/stat.h>
#include <sys/mman.h>
#include <dlfcn.h>
#include <fcntl.h>
#include <stdbool.h>
#include <argtable3.h>
#include <btree/btree.h>
#include <libhashstrings.h>
/* generated from hash files */
#include "capitalization.h"
#include "city.h"
#include "country.h"
#include "genre.h"
#include "keyword.h"
#include "name.h"
#include "nielsenDMA.h"
#include "resolution.h"
#include "uscallsign.h"
#include "usstate.h"
/* normal local includes */
#include "languages.h"
#include "countryCodes.h"
#include "usstationdata.h"
#define kHashExtAVI 0x0002dbe9
#define kHashExtFLV 0x00031386
#define kHashExtM3U8 0x00881baa
#define kHashExtM4V 0x00033c9e
#define kHashExtMK 0x000012d7
#define kHashExtMKV 0x00033844
#define kHashExtMP4 0x00033ba8
#define kHashExtMP41 0x00883ec1
#define kHashExtMPG 0x00033b7f
#define kHashExtTS 0x0000139b
#define kHashExtWMV 0x00037548
#define kHashPeriod 0x0000002e
/* first pass parsing the line */
/*
* these are common attributes that may occur in the channel and/or group name
* so they are handled using a common structure & parsing. Attributes defined at
* the group level are assumed to be inherited by every channel in the group,
* unless the channel name itself has keywords to override that.
*/
typedef struct {
const char * originalName;
const char * name;
bool disabled;
tResolutionIndex resolution;
bool isVIP;
bool isPlus1;
enum { kLinear = 0, kPPV, kVOD, k24x7, kLive } type;
tCityIndex city;
tCountryIndex country;
tRegionIndex region;
tLanguage language;
tGenreIndex genre;
tAffiliateIndex affiliate;
tUSCallsignIndex usStation;
} tCommon;
const char * lookupTypeAsString[] =
{
[kLinear] = "linear",
[kPPV] = "Pay-Per-View",
[kVOD] = "Video On Demand",
[k24x7] = "24/7",
[kLive] = "Live Event"
};
typedef struct sTMSChannel {
const char * name;
long id;
} tTMSChannel;
typedef struct sStream {
struct sStream * next;
const char * url;
tResolutionIndex resolution;
bool isVIP;
bool isFile;
} tStream;
typedef struct sChannel {
tCommon common;
const char * xui;
const char * id;
const char * logo;
struct sStream * stream;
struct sGroup * group;
} tChannel;
typedef struct sGroup {
tCommon common;
} tGroup;
struct {
const char * executableName;
FILE * outputFile;
int debugLevel;
struct {
struct btree * channel;
struct btree * group;
struct btree * mapping;
} tree;
struct {
tChannel * channel;
tGroup * group;
tStream * stream;
} head;
} global;
void dumpCommon( FILE * output, tCommon * common );
void dumpChannel( FILE * output, tChannel * channel );
void dumpGroup( FILE * output, tGroup * group );
void dumpStreams( FILE * output, tStream * stream );
#undef DEBUG_REJECTION
/**
* @brief Decide if a group should be included in the output M3U
*
* This is the key function to modify to sort your needs.
* It controls the filtering of channels imported from the original
* M3U to produce the trimmed-down list of channels you actually
* want to be in the output M3U.
*
* @param group
* @return true if the group should be included
*/
bool isGroupDisabled( tGroup * group )
{
bool result = false;
tCommon * common = &group->common;
switch ( common->genre )
{
/* Filter out genres I never record */
case kGenreAdult:
case kGenreCivic:
case kGenreReligious:
case kGenreShopping:
case kGenreSports:
result = true;
break;
/* the regional channels can bump up the channel count significantly.
* since most methods of recording IPTV put a cap on the number of
* channels that can be imported, removing redundant channels is worthwhile */
case kGenreLocal:
case kGenreCountry:
switch ( common->country )
{
case kCountryUnitedStates:
/* if we find a US Callsign, filter down to the SF Bay Area stations */
if ( common->usStation != kUSCallsignUnset )
{
// result = ( USStationData[ common->usStation ].stateIdx != kUSStateCalifornia );
}
break;
case kCountryCanada:
if ( common->city != kCityToronto && common->city != kCityVancouver )
{
// result = true;
}
break;
case kCountryUnitedKingdom:
/* nuke the multitude of regional channels in the UK */
if ( common->city != kCityLondon )
{
// result = true;
}
break;
default:
result = true;
break;
}
break;
case kGenreUnset:
default:
break;
}
/* trim down to just UK and Canadian channels */
if ( ! result )
{
switch ( common->country )
{
case kCountryUnset:
case kCountryCanada:
case kCountryUnitedKingdom:
break;
default:
result = true;
break;
}
}
if ( ! result && (common->isPlus1 || common->type != kLinear ))
{
result = true;
}
if ( result )
{
#ifdef DEBUG_REJECTION
fprintf( stderr, "%10s ", lookupGenreAsString[ common->genre ] );
dumpGroup( stderr, group );
#endif
}
return result;
}
/**
* @brief Decide if a channel should be included in the output M3U
*
* This is the key function to modify to sort your needs.
* It controls the filtering of channels imported from the original
* M3U to produce the trimmed-down list of channels you actually
* want to be in the output M3U.
*
* @param channel
* @return true if the channel should be included
*/
bool isChannelDisabled( tChannel * channel )
{
bool result = false;
tCommon * common = &channel->common;
if ( channel->stream == NULL || channel->stream->isFile == true )
{
result = true;
#ifdef DEBUG_REJECTION
fprintf( stderr, " File ");
dumpChannel( stderr, channel );
#endif
}
if ( ! result ) switch ( common->genre )
{
/* Filter out genres I never record */
case kGenreAdult:
case kGenreCivic:
case kGenreReligious:
case kGenreShopping:
case kGenreSports:
result = true;
#ifdef DEBUG_REJECTION
fprintf( stderr, " Genre ");
dumpChannel( stderr, channel );
#endif
break;
/* The regional channels can bump up the channel count significantly. Since
* most methods of recording IPTV put a cap on the number of channels that
* can be imported, removing redundant channels is worthwhile */
case kGenreLocal:
switch ( channel->common.country )
{
case kCountryUnitedStates:
/* if we find a US Callsign, filter down to the SF Bay Area stations */
if ( common->usStation != kUSCallsignUnset )
{
// result = ( USStationData[ common->usStation ].nielsenDMAIdx != kNielsenDMASFBayArea );
}
break;
case kCountryCanada:
if ( common->city != kCityToronto && common->city != kCityVancouver )
{
result = true;
}
break;
case kCountryUnitedKingdom:
/* nuke the multitude of regional channels in the UK */
if ( common->city != kCityLondon )
{
result = true;
}
break;
default:
result = true;
break;
}
#ifdef DEBUG_REJECTION
if ( result == true )
{
fprintf( stderr, " Local ");
dumpChannel( stderr, channel );
}
#endif
break;
case kGenreUnset:
default:
break;
}
/* trim down to just UK and Canadian channels */
if ( ! result )
{
switch ( channel->common.country )
{
case kCountryUnset:
case kCountryCanada:
case kCountryUnitedKingdom:
case kCountryUnitedStates:
break;
default:
result = true;
#ifdef DEBUG_REJECTION
fprintf( stderr, " Country ");
dumpChannel( stderr, channel );
#endif
break;
}
}
if ( ! result )
{
/* only channels that are in the english language */
if ( common->language != kLanguageEnglish )
{
result = true;
#ifdef DEBUG_REJECTION
fprintf( stderr, " Language ");
dumpChannel( stderr, channel );
#endif
}
}
if ( ! result && (common->isPlus1 || common->type != kLinear ))
{
result = true;
#ifdef DEBUG_REJECTION
fprintf( stderr, " Live ");
dumpChannel( stderr, channel );
#endif
}
if ( ! result)
{
if ( channel->stream != NULL && channel->stream->resolution == kResolutionSD )
{
result = true;
#ifdef DEBUG_REJECTION
fprintf( stderr, "Resolution ");
dumpChannel( stderr, channel );
#endif
}
}
return result;
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
static inline int min( int a, int b )
{
if ( a < b )
return a;
else return b;
}
static inline int bound( int value, int lower, int upper )
{
if ( value < lower ) return lower;
if ( value > upper ) return upper;
return value;
}
/* Uglyness because of inconsistent formatting of '+1' channels.
* Some lack a separator between the channel name and the '+1'
* this code detects that case and inserts a space */
/**
* @brief
* @param str
* @return
*/
char * seperatePlus1( char * str )
{
char * s = strrchr( str, '+' );
/* if a '+' was found, and it is followed by a '1', but NOT preceded by a ' '... */
if ( s != NULL && s[ 1 ] == '1' && s[ -1 ] != ' ' )
{
/* enlarge the string to make room for the extra char */
str = realloc( (void *)str, strlen( str ) + 2 );
/* find the end of the string */
while ( *s != '\0' ) { s++; }
/* reverse back up the string, moving existing chars
* up by one until we hit the plus we found earlier */
do {
s[ 1 ] = s[ 0 ];
} while ( *s-- != '+' );
s[1] = ' '; /* make sure there's a separator before the plus */
}
return str;
}
/**
* @brief
* @param p
*/
void trimTrailingEOL( char * p )
{
char * start = p;
/* find the end of the string */
while ( *p != '\0' ) { ++p; }
/* back up before the nul */
--p;
/* reverse over any trailing newlines/carriage returns */
while ( start < p && ( *p == '\n' || *p == '\r' ) ) { --p; }
p[1] = '\0';
}
void trimAppendQuote( char * p )
{
char * start = p;
/* find the end of the string */
while ( *p != '\0' ) { ++p; }
/* back up before the nul */
--p;
/* reverse over any trailing newlines/carriage returns */
while ( start < p && ( *p == '\n' || *p == '\r' ) ) { --p; }
p[1] = '\"';
p[2] = '\0';
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/* in hindsight, I probably should have used C++ instead... */
/**
* @brief
* @return
*/
tStream * newStream( void )
{
return (tStream *) calloc( 1, sizeof( tStream ));
}
/**
* @brief
* @param stream
*/
void freeStream( tStream * stream )
{
free( (void *)stream->url );
free( (void *)stream );
}
/**
* @brief
* @return
*/
tChannel * newChannel(void)
{
return (tChannel *) calloc(1,sizeof( tChannel ));
}
/**
* @brief
* @param channel
* @return
*/
tChannel * freeChannel( tChannel * channel )
{
if (channel != NULL)
{
tStream * stream = channel->stream;
channel->stream = NULL;
while ( stream != NULL )
{
tStream * next = stream->next;
freeStream( stream );
stream = next;
}
free( channel );
}
return NULL;
}
/**
* @brief
* @return
*/
tGroup * newGroup( void )
{
return (tGroup *) calloc( 1, sizeof( tGroup ) );
}
/**
* @brief
* @param group
*/
void freeGroup( tGroup * group )
{
if (group != NULL)
{
free( (void *) group->common.name );
free( (void *) group );
}
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @brief
* @param output
* @param common
*/
void dumpCommon( FILE * output, tCommon * common)
{
if ( common->genre != kGenreUnset )
{
fprintf( output, ", genre: %s", lookupGenreAsString[ common->genre ] );
}
if ( common->usStation != kUSCallsignUnset )
{
fprintf( output, ", callsign: \"%s\"",
USStationData[ common->usStation ].callsign );
fprintf( output, ", state: %s",
lookupUSStateAsString[ USStationData[ common->usStation ].stateIdx ] );
fprintf( output, ", DMA: \"%s\"",
lookupNielsenDMAAsString[ USStationData[ common->usStation ].nielsenDMAIdx ] );
}
if ( common->affiliate != kAffiliateUnset )
{
fprintf( output, ", affiliate: %s", lookupAffiliateAsString[ common->affiliate ] );
}
if ( common->region != kRegionUnset )
{
fprintf( output, ", region: %s", lookupRegionAsString[ common->region ] );
}
if ( common->language != kLanguageUnset )
{
fprintf( output, ", language: %s", lookupLanguageAsString[ common->language ] );
}
if ( common->resolution != kResolutionUnset )
{
fprintf( output, ", resolution: %s", lookupResolutionAsString[ common->resolution ] );
}
if ( common->isVIP )
{
fprintf( output, ", VIP" );
}
if (common->isPlus1)
{
fprintf(output,", +1");
}
}
/**
* @brief
* @param output
* @param stream
*/
void dumpStreams( FILE * output, tStream * stream )
{
while ( stream != NULL )
{
fprintf( output, " stream: rez: %s, isvip: %d, url: %s\n",
lookupResolutionAsString[ stream->resolution ],
stream->isVIP,
stream->url );
stream = stream->next;
}
}
/**
* @brief
* @param output
* @param channel
*/
void dumpChannel( FILE * output, tChannel * channel )
{
fprintf( output, " channel " );
if ( channel->common.name != NULL )
{
fprintf( output, "name: %s", channel->common.name );
}
if ( channel->common.country != kCountryUnset )
{
fprintf( output, ", country: %s", lookupFullCountryAsString[ channel->common.country ] );
if ( channel->common.country == kCountryCanada && channel->common.city != kCityUnset )
{
fprintf( output, ", city: %s", lookupCityAsString[ channel->common.city ] );
}
}
dumpCommon( output, &channel->common );
fprintf( output, ".\n" );
}
/**
* @brief
* @param output
* @param group
*/
void dumpGroup( FILE * output, tGroup * group )
{
fprintf( output, " group " );
if ( group->common.name != NULL )
{
fprintf( output, "name: %s", group->common.name );
}
if ( group->common.country != kCountryUnset )
{
fprintf( output, ", country: %s", lookupFullCountryAsString[group->common.country] );
if ( group->common.country == kCountryCanada && group->common.city != kCityUnset )
{
fprintf( output, ", city: %s", lookupCityAsString[group->common.city] );
}
}
dumpCommon( output, &group->common );
fprintf( output, ".\n" );
}
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */
/**
* @brief
* @param skipTable
* @param hash
* @param setting
* @return
*/
bool assignHash( tRecord skipTable[], tHash hash, tIndex * setting )
{
tIndex index = findHash( skipTable, hash );
if ( index != kIndexUnset && *setting == kIndexUnset )
{
*setting = index;
}
return (index != kIndexUnset);
}
/**
* @brief
* @param hash
* @param common
* @return true - swallow the string
*/
bool processCommonHash( tHash hash, tCommon * common )
{
bool swallow = false;
if ( common->country == kCountryUnset && assignHash( mapCountrySearch, hash, &common->country ) )
{
swallow = true;
if ( common->region == kRegionUnset )
{
common->region = countryToRegion[ common->country ];
}
if ( common->language == kLanguageUnset )
{
common->language = countryToLanguage[ common->country ];
}
} else {
switch ( findHash( mapCountrySearch, hash ) )
{
case kCountryCanada:
if ( common->country == kCountryFrance )
{
common->country = kCountryCanada;
common->language = kLanguageFrench;
}
break;
case kCountryFrance:
if ( common->country == kCountryCanada )
{
common->language = kLanguageFrench;
}
break;
default:
/* otherwise ignore a second country match */
break;
}
}
switch (findHash( mapNameSearch, hash ))
{
case kNameVIP:
common->isVIP = true;
swallow = true;
break;
case kNamePlus1:
common->isPlus1 = true;
break;
case kNamePayPerView:
common->type = kPPV;
break;
case kName24x7:
common->type = k24x7;
break;
case kNameVideoOnDemand:
common->type = kVOD;
break;
case kNameLiveEvent:
common->type = kLive;
break;
case kNameFrenchCanadian:
common->language = kLanguageFrench;
break;
case kNameLatino:
common->language = kLanguageSpanish;
break;
}
if ( assignHash( mapResolutionSearch, hash, &common->resolution ) )
{
swallow = true;
}
if ( common->country == kCountryUnitedStates || common->country == kCountryCanada )
{
assignHash( mapUSCallsignSearch, hash, &common->usStation );
if ( common->usStation != kUSCallsignUnset )
{
common->country = kCountryUnitedStates;
common->genre = kGenreLocal;
common->affiliate = USStationData[ common->usStation ].affiliateIdx;
}
}
if ( common->genre == kGenreUnset && assignHash( mapCitySearch, hash, &common->city ) )
{
common->genre = kGenreLocal;
}
/* if a US Station callsign was already found, then genre has already been set to 'regional' */
/* Allow a second genre to override 'sports', since group names of 'sports and entertainment' are common*/
if ( common->genre == kGenreUnset || common->genre == kGenreSports )
{
assignHash( mapGenreSearch, hash, &common->genre );
}
/* This is a stronger indication of a station's language than the country, e.g. hispanic networks in the U.S. */
if (common->affiliate != kAffiliateUnset)
{
common->language = affiliateToLanguage[ common->affiliate ];
}
return swallow;
}
/**
* @brief
* @param stream
* @param channel
*/
void inheritChannel( tStream * stream, tChannel * channel )
{
/* copy over any unset attributes from channel to stream */
if ( stream != NULL && channel != NULL )
{
/* inherit resolution from channel if stream resolution is not set */
if ( stream->resolution == kResolutionUnset )
{
stream->resolution = channel->common.resolution;
}
/* inherit stream VIP status from channel if not already VIP */
if ( channel->common.isVIP )
{
stream->isVIP = channel->common.isVIP;
}
}
}
/**
* @brief
* @param channel
* @param group
*/
void inheritGroup( tChannel * channel, tGroup * group )
{
if ( channel != NULL && group != NULL )
{
/* copy over any unset attributes from group to channel */
if ( channel->common.country == kCountryUnset
&& group->common.country != kCountryUnset )
{
channel->common.country = group->common.country;
}
if ( channel->common.language == kLanguageUnset
&& group->common.language != kLanguageUnset )
{
channel->common.language = group->common.language;
}
if ( channel->common.genre == kGenreUnset
&& group->common.genre != kGenreUnset )
{
channel->common.genre = group->common.genre;
}
if ( channel->common.affiliate == kAffiliateUnset
&& group->common.affiliate != kAffiliateUnset )
{
channel->common.affiliate = group->common.affiliate;
}
/* inherit resolution from group if channel resolution is not set */
if ( channel->common.resolution == kResolutionUnset )
{
channel->common.resolution = group->common.resolution;
}
if ( channel->common.type == kLinear
&& group->common.type != kLinear )
{
channel->common.type = group->common.type;
}
if ( group->common.isVIP )
{
channel->common.isVIP = true;
}
}
}
/**
* @brief
* @param url
* @param channel
* @return
*/
tStream * processStream( const char * url, tChannel * channel )
{
tStream * stream = newStream();
if ( stream != NULL)
{
stream->url = url;
inheritChannel( stream, channel );
if ( url != NULL)
{
const char * ext;
for ( ext = url; *ext != '\0'; ++ext ) { /* find the end-of-string */ }
for ( int i = 5; ext > url && *ext != '.' && i > 0; --i )
{
/* scan backwards up to 5 characters, looking for a period */
--ext;
}
if ( *ext == '.' )
{
tHash hash = hashString( ext, gNameCharMap );
switch ( hash )
{
case kHashExtAVI:
case kHashExtFLV:
case kHashExtM4V:
case kHashExtMK:
case kHashExtMKV:
case kHashExtMP41:
case kHashExtMP4:
case kHashExtMPG:
case kHashExtWMV:
stream->isFile = true;
break;
case kHashExtTS: /* valid streams may have a .ts extension */
case kHashExtM3U8: /* ...or a .m3u8 extension */
case kHashPeriod: /* some URLs have trailing periods? */
break;
default:
if ( hash != 0 ) {
fprintf( stderr, "%s = 0x%08lx (%s)\n", ext, hash, url );
}
break;
}
}
}
// dumpChannel( stderr, channel );
}
return stream;
}
/**
* @brief
* @param name
* @param common
*/
void processName( const char * name, tCommon * common )
{
tMappedChar mappedC;
const char * p;
char * sp;
char * dp;
int dl;
char temp[256];
/* first extract any attributes embedded in the channel name,
* tags like 'VIP', 'UK', 'HD', etc. See name.hash */
if ( name == NULL || strlen(name) == 0 )
{
common->name = strdup( "(none)" );
return;
}
p = name;
common->originalName = strdup( p );
sp = temp;
dp = sp;
dp[0] = '\0';
dl = sizeof( temp ) - 1;
tHash hash = 0;
bool first = true;
int alpha = 0;
do {
mappedC = remapChar( gNameCharMap, *p++ );
if ( mappedC != kNameSeparator && mappedC != '\0' )
{
hash = hashChar( hash, mappedC );
*dp++ = mappedC;
if ( isalpha( mappedC ) )
{
++alpha;
}
}
else
{
if ( hash != 0 )
{
if ( processCommonHash( hash, common ) )
{
/* swallow the string - back up to the beginning of this hash run */
dp = sp;
}
else
{
tCapitalizationIndex capitalize = findHash( mapCapitalizationSearch, hash );
if ( capitalize != kCapitalizationUnset )
{
const char * p = lookupCapitalizationAsString[ capitalize ];
dp = stpcpy( sp, p );