-
Notifications
You must be signed in to change notification settings - Fork 5
/
servicetypes.c
executable file
·1549 lines (1243 loc) · 41.2 KB
/
servicetypes.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
#include "servicetypes.h"
#include "containerfiles.h"
#include "selectformat.h"
#include "download.h"
#include "youtube.h"
#include "settings.h"
/*
This file and it's header (servicetypes.h) holds all the functions and data
related to individual services/sites. When adding a site you need to add to
the arrays 'DownloadTypes', 'DownloadNames' and 'TestLinks' and to the
enumerated type in servicetypes.h tht matches to 'DownloadTypes'.
Then site specific
*/
//Site type names used at the command line etc
char *DownloadTypes[]={"none","generic","youtube","youtu.be","metacafe","dailymotion","break","vimeo","ted","reuters","liveleak","photobucket","washingtonpost","cbsnews","france24","euronews","metatube","guardian","redorbit","uctv.tv","dotsub","astronomy.com","discovery","bloomberg","nationalgeographic","smh","ebaumsworld","imdb","charlierose","stanfordoc","screencast.com","royalsociety.tv","bitchute",NULL};
//Longer names used in display
char *DownloadNames[]={"none",
"Generic: Search in page for http://*.flv, http://*.mp3, http//*.mp4 etc, etc, etc",
"YouTube: http://www.youtube.com",
"youtu.be: http://www.youtu.be",
"Metacafe: http://www.metacafe.com",
"Daily Motion: http://www.dailymotion.com",
"www.break.com",
"www.vimeo.com",
"www.ted.com",
"Reuters: http://www.reuters.com/",
"Liveleak: http://www.liveleak.com",
"Photobucket: http://www.photobucket.com",
"Washington Post: www.washingtonpost.com",
"CBS News: www.cbsnews.com",
"France24: www.france24.com",
"Euronews: www.euronews.net",
"www.metatube.com",
"www.guardian.co.uk",
"www.redorbit.com",
"University of California Television: http://www.uctv.tv/",
"dotsub.com",
"astronomy.com",
"dsc.discovery.com",
"www.bloomberg.com (not bloomberg.tv)",
"National Geographic (http://video.nationalgeographic.com)",
"Sidney Morning Herald",
"Ebaums World",
"www.imdb.com",
"Charlie Rose",
"Stanford Open Classroom",
"UDemy",
"http://royalsociety.org/",
"BitChute",
NULL};
//"http://vimeo.com/33204284",
//links used by the -test-sites feature to test if a download site still
//works with movgrab
char *TestLinks[]={"", "",
"https://www.youtube.com/watch?v=GrK9EaQRp2I",
"http://youtu.be/mvEPnhmtXY0",
"http://metacafe.com/watch/11419763/super-blood-moon-eclipse-2015/",
"http://www.dailymotion.com/video/x5790e_hubblecast-16-galaxies-gone-wild_tech",
"http://www.break.com/video/break-compilations-2591623/cats-vs-the-world-iii-breaking-videos-3075295",
"broken",
"http://www.ted.com/talks/janine_benyus_shares_nature_s_designs.html",
"http://www.reuters.com/video/2016/05/02/foam-swords-drawn-in-mass-play-fight-in?videoId=368328211",
"http://www.liveleak.com/view?i=e28_1462299205",
"http://gs147.photobucket.com/groups/r299/QM25Y4IJEP/?action=view¤t=BlackSwan1.mp4",
"http://www.washingtonpost.com/video/politics/tom-prices-tense-senate-finance-hearing/2017/01/24/f0c35346-e282-11e6-a419-eefe8eff0835_video.html",
"http://www.cbsnews.com/video/watch/?id=7357739n",
"http://www.france24.com/en/20160430-down-earth-fast-fashion-pollution-environment-ethical-consumption",
"https://www.euronews.com/2019/06/27/astronaut-luca-parmitano-chronicles-his-mission-for-euronews",
"https://www.metatube.com/en/videos/266906/Ex-Machina-Movie-TRAILER-2-2015/",
"http://www.guardian.co.uk/world/video/2011/may/13/fukushima-radiation-dairy-farmers-video",
"http://www.redorbit.com/video/using-f1-technology-to-transform-healthcare-012016/",
"http://www.uctv.tv/search-details.aspx?showID=20888",
"http://dotsub.com/view/5d90ef11-d5e5-42fb-8263-a4c128fb64df",
"http://www.astronomy.com/News-Observing/Liz%20and%20Bills%20Cosmic%20Adventures/2011/02/Episode%202.aspx",
"http://dsc.discovery.com/videos/how-the-universe-works-birth-of-a-black-hole.html",
"http://www.bloomberg.com/video/72477250/",
"http://video.nationalgeographic.com/video/environment/environment-natural-disasters/earthquakes/earthquake-101/",
"http://www.smh.com.au/technology/sci-tech/newly-discovered-planets-include-superearth-20110913-1k7tl.html",
"https://www.ebaumsworld.com/videos/spacex-released-a-blooper-reel-of-all-their-failed-flights-and-landings/85465411/",
"http://www.imdb.com/video/imdb/vi3832131865",
"https://charlierose.com/videos/27996",
"http://openclassroom.stanford.edu/MainFolder/VideoPage.php?course=PracticalUnix&video=wget&speed=100",
"http://www.brainstuffshow.com/videos/how-gps-coordinates-work-video.htm",
//"http://royalsociety.tv/rsPlayer.aspx?presentationid=474",
"broken",
"https://www.bitchute.com/video/v_UdkNgeuRY/",
NULL};
//Guess service type from servername in URL
int IdentifyServiceType(const char *URL)
{
int Type=TYPE_NONE;
char *Proto=NULL, *Server=NULL, *Tempstr=NULL;
if (! URL) return(TYPE_NONE);
Type=GetContainerFileType(URL);
if (Type != TYPE_NONE) return(Type);
ParseURL(URL,&Proto,&Server,&Tempstr,NULL,NULL,NULL,NULL);
if (! StrValid(Server))
{
Destroy(Proto);
Destroy(Server);
Destroy(Tempstr);
return(TYPE_NONE);
}
if (
(strstr(Server,"youtube"))
) Type=TYPE_YOUTUBE;
else if (
(strcmp(Server,"youtu.be")==0)
) Type=TYPE_YOUTUBE_SHORT;
else if (strcmp(Server,"www.metacafe.com")==0)
{
Type=TYPE_METACAFE;
}
else if (strcmp(Server,"www.break.com")==0)
{
Type=TYPE_BREAK_COM;
}
else if (strcmp(Server,"www.dailymotion.com")==0)
{
Type=TYPE_DAILYMOTION;
}
else if (strcmp(Server,"www.ted.com")==0)
{
Type=TYPE_TED;
}
else if (strstr(Server,"photobucket.com"))
{
Type=TYPE_PHOTOBUCKET;
}
else if (strstr(Server,"liveleak"))
{
Type=TYPE_LIVELEAK;
}
else if (strstr(Server,"smh.com.au"))
{
Type=TYPE_SMH;
}
else if (strstr(Server,"vimeo.com"))
{
Type=TYPE_VIMEO;
}
else if (strstr(Server,"reuters"))
{
Type=TYPE_REUTERS;
}
else if (strstr(Server,"ucsd.tv"))
{
Type=TYPE_UCTV;
}
else if (strstr(Server,"uctv.tv"))
{
Type=TYPE_UCTV;
}
else if (strstr(Server,"washingtonpost"))
{
Type=TYPE_WASHINGTONPOST;
}
else if (strstr(Server,"cbsnews"))
{
Type=TYPE_CBSNEWS;
}
else if (strstr(Server,"france24"))
{
Type=TYPE_FRANCE24;
}
else if (strstr(Server,"euronews"))
{
Type=TYPE_EURONEWS;
}
else if (strstr(Server,"metatube"))
{
Type=TYPE_METATUBE;
}
else if (strstr(Server,"guardian"))
{
Type=TYPE_GUARDIAN;
}
else if (strstr(Server,"redorbit"))
{
Type=TYPE_REDORBIT;
}
else if (strcmp(Server,"royalsociety.tv")==0)
{
Type=TYPE_ROYALSOCIETY_STAGE2;
}
else if (strcmp(Server,"royalsociety.org")==0)
{
Type=TYPE_ROYALSOCIETY;
}
else if (strcmp(Server,"dotsub.com")==0)
{
Type=TYPE_DOTSUB;
}
else if (strstr(Server,"astronomy.com"))
{
Type=TYPE_ASTRONOMYCOM;
}
else if (strstr(Server,"discovery.com") || strstr(Server,"sciencechannel.com"))
{
Type=TYPE_DISCOVERY;
}
else if (strstr(Server,"nationalgeographic.com"))
{
Type=TYPE_NATGEO;
}
else if (strstr(Server,"bloomberg.com"))
{
Type=TYPE_BLOOMBERG;
}
else if (strstr(Server,".imdb.com"))
{
Type=TYPE_IMDB;
}
else if (strstr(Server,".ebaumsworld.com"))
{
Type=TYPE_EBAUMSWORLD;
}
else if (strstr(Server,"charlierose.com"))
{
Type=TYPE_CHARLIEROSE;
}
else if (strcmp(Server,"openclassroom.stanford.edu")==0)
{
Type=TYPE_STANFORD_OPENCLASS;
}
else if (strstr(Server,".google."))
{
Type=TYPE_GOOGLE_URL;
}
else if (strstr(Server,"screencast.com"))
{
Type=TYPE_SCREENCAST_COM;
}
else if (strstr(Server,"bitchute.com"))
{
Type=TYPE_BITCHUTE;
}
Destroy(Server);
Destroy(Proto);
Destroy(Tempstr);
return(Type);
}
//This function is called before we even pull the first page from a site
//it is a good place to do any site-specific stuff like rewriting the
//site URL to a form that's better for movgrab
char *SiteSpecificPreprocessing(char *RetBuff, const char *Path, const char *Proto, const char *Server, int Port, const char *Doc, int *Type, char **Title, int *Flags)
{
char *Tempstr=NULL;
char *NextPath=NULL;
char *Token=NULL;
const char *ptr;
NextPath=CopyStr(RetBuff,Path);
switch (*Type)
{
case TYPE_YOUTUBE_SHORT:
//something like https://youtu.be/OdrEId7YI1k
ptr=Doc;
while (*ptr=='/') ptr++;
NextPath=MCopyStr(NextPath,Proto,"://www.youtube.com/get_video_info?&video_id=",ptr,"&el=detailpage&ps=default&eurl=&gl=US&hl=enB",NULL);
*Type=TYPE_YOUTUBE;
break;
case TYPE_YOUTUBE:
//hmm.. have we been given the http://www.youtube.com/v/ or https://www.youtube.com/embed/ format?
if (strncmp(Doc,"/v/",3)==0) Token=CopyStr(Token,Doc+3);
else if (strncmp(Doc,"/embed/",7)==0) Token=CopyStr(Token,Doc+7);
else if (strncmp(Doc,"/watch?v=",9)==0) Token=CopyStr(Token,Doc+9);
else
{
*Type=TYPE_YOUTUBE_PLAYLIST;
NextPath=MCopyStr(NextPath,Proto,"://",Server,"/",Doc,NULL);
}
if (*Type == TYPE_YOUTUBE)
{
//strip any http arguments
StrTruncChar(Token,'?');
NextPath=MCopyStr(NextPath,Proto,"://www.youtube.com/get_video_info?&video_id=",Token,"&el=detailpage&ps=default&eurl=&gl=US&hl=enB",NULL);
}
//Do we have authentication info?
//if (StrValid(Username) && StrValid(Password)) YoutubeLogin(Username,Password);
break;
case TYPE_METACAFE:
ptr=GetToken(Doc,"watch/",&Token,0);
ptr=GetToken(ptr,"/",&Token,0);
if (strchr(Token,'-'))
{
//Movie is embedded from elsewhere
if (strncmp(Token,"yt",2)==0)
{
ptr=strrchr(Token,'-');
if (ptr)
{
ptr++;
// *Type=TYPE_NONE;
// Tempstr=MCopyStr(Tempstr,"http://www.youtube.com/watch?v=",ptr,NULL);
// GrabMovie(Tempstr);
*Type=TYPE_YOUTUBE;
NextPath=MCopyStr(NextPath,"http://www.youtube.com/watch?v=",ptr,NULL);
}
}
else if (! (*Flags & FLAG_QUIET)) fprintf(stderr,"Movie is not genuinely stored on metacafe, it is embedded from elsewhere, but it's not youtube, so I don't know how to download it. Sorry.\n");
}
else
{
STREAM *S;
if (*Flags & FLAG_PORN)
{
//Initial 'turn off family filter'
Tempstr=FormatStr(Tempstr,"%s://%s:%d/f/index.php?inputType=filter&controllerGroup=user&filters=0&submit=Continue+-+I%27m+over+18",Proto,Server,Port);
S=STREAMOpen(Tempstr,"w");
STREAMClose(S);
//But we have to do it twice, probably something to do with cookies
NextPath=FormatStr(NextPath,"http://%s:%d/f/index.php?inputType=filter&controllerGroup=user&filters=0&Continue=Continue+-+I%27m+over+18&prevURL=%s",Server,Port,Path);
}
else NextPath=CopyStr(NextPath,Path);
}
break;
case TYPE_DAILYMOTION:
if (*Flags & FLAG_PORN)
{
Tempstr=HTTPQuote(Tempstr,Doc);
NextPath=FormatStr(NextPath,"http://%s:%d/family_filter?urlback=/%s&enable=false",Server,Port,Tempstr);
}
else NextPath=CopyStr(NextPath,Path);
break;
case TYPE_VIMEO:
NextPath=MCopyStr(NextPath,"http://player.vimeo.com/video/",Doc,NULL);
break;
case TYPE_GOOGLE_URL:
ptr=strchr(Path, '?');
if (ptr)
{
ptr++;
ptr=GetToken(ptr,"&",&Token,0);
while (ptr)
{
if (strncmp(Token, "url=", 4)==0) NextPath=HTTPUnQuote(NextPath,Token+4);
if (strncmp(Token, "q=", 2)==0) NextPath=HTTPUnQuote(NextPath,Token+2);
ptr=GetToken(ptr,"&",&Token,0);
}
*Type=IdentifyServiceType(NextPath);
}
break;
case TYPE_CHARLIEROSE:
NextPath=MCopyStr(NextPath,"https://charlierose.com/video/player/",GetBasename(Path),NULL);
break;
default:
NextPath=CopyStr(NextPath,Path);
break;
}
Destroy(Tempstr);
Destroy(Token);
return(NextPath);
}
//For websites with multiple videos on a page (not multiple formats of the
//same video, but actual different videos) decide which one to get
void HandleMultipleMedia(int Type, const char *Server, int Flags, ListNode *Vars, int MediaCount)
{
char *Tempstr=NULL;
const char *ptr;
int i, startpos, endpos;
startpos=0;
endpos=MediaCount;
if (MediaCount==1) endpos=1;
else if (! StrValid(Settings.ItemSelectArg))
{
if (! (Flags & FLAG_QUIET))
{
fprintf(stderr,"\nMultiple downloads exist on this page.\n");
fprintf(stderr,"Please select by using the command-line argument -n <num>\n");
fprintf(stderr," e.g. -n all\n");
fprintf(stderr," -n 0-4\n");
fprintf(stderr," -n 3-\n\n");
for (i=0; i < MediaCount; i++)
{
Tempstr=FormatStr(Tempstr,"ID:%d",i);
ptr=GetVar(Vars,Tempstr);
if (ptr) ptr=strrchr(ptr,'.');
if (! ptr) ptr="?";
Tempstr=FormatStr(Tempstr,"Title:%d",i);
fprintf(stderr," % 4d: %4s %s\n",i,ptr,GetVar(Vars,Tempstr));
}
fprintf(stderr,"\n");
}
endpos=startpos;
}
else if (strcmp(Settings.ItemSelectArg,"all")==0)
{
//do nothing
}
else if (strchr(Settings.ItemSelectArg,'-'))
{
ptr=GetToken(Settings.ItemSelectArg,"-",&Tempstr,0);
if (StrValid(Tempstr)) startpos=atoi(Tempstr);
else startpos=0;
if (StrValid(ptr)) endpos=atoi(ptr);
else endpos=MediaCount;
}
else
{
startpos=atoi(Settings.ItemSelectArg);
endpos=startpos+1;
}
for (i=startpos; i < endpos; i++)
{
Tempstr=FormatStr(Tempstr,"ID:%d",i);
ptr=GetVar(Vars,Tempstr);
SetVar(Vars,"ID",ptr);
GrabMovie(ptr, TYPE_YOUTUBE);
}
Destroy(Tempstr);
}
//Called after the first page has been downloaded from the site
//Decides what to do next (Download another page, download the actual
//media item, give up, etc.
int GetNextURL(int Type, const char *Server, int Flags, ListNode *Vars)
{
char *Tempstr=NULL, *Title=NULL, *Fmt=NULL;
const char *ptr;
int RetVal=FALSE;
STREAM *Con;
Title=CopyStr(Title,GetVar(Vars,"Title"));
Fmt=CopyStr(Fmt,GetVar(Vars,"DownloadFormat"));
switch (Type)
{
case TYPE_M3U8_STREAM:
Tempstr=CopyStr(Tempstr,GetVar(Vars,"ID"));
Con=ConnectAndRetryUntilDownload(Tempstr, 0, 0);
if (Con)
{
M3UStreamDownload(Con, Tempstr, Title);
STREAMClose(Con);
}
break;
case TYPE_REFERENCE:
case TYPE_GOOGLE_URL:
Tempstr=CopyStr(Tempstr,GetVar(Vars,"ID"));
RetVal=GrabMovie(Tempstr,TYPE_NONE);
break;
case TYPE_YOUTUBE:
Tempstr=CopyStr(Tempstr,GetVar(Vars,"ID"));
RetVal=DownloadItem(Tempstr, Title, Fmt, Flags);
break;
case TYPE_YOUTUBE_PLAYLIST:
Tempstr=CopyStr(Tempstr,GetVar(Vars,"ID"));
RetVal=DownloadPage(Tempstr,TYPE_YOUTUBE, Title, Flags);
break;
case TYPE_METACAFE:
//#define METACAFE_OVER_18 "allowAdultContent=1&submit=Continue+-+I%27m+over+18"
//Tempstr=SubstituteVarsInString(Tempstr,"$(ID)&$(METACAFE_OVER_18)",Vars,0);
RetVal=DownloadItem(GetVar(Vars,"ID"), Title, Fmt, Flags);
break;
case TYPE_BREAK_COM:
Tempstr=SubstituteVarsInString(Tempstr,"http://www.break.com/$(ID)",Vars,0);
RetVal=DownloadPage(Tempstr,TYPE_BREAK_STAGE2,Title,Flags);
break;
case TYPE_VIMEO:
RetVal=DownloadPage(GetVar(Vars,"ID"),TYPE_VIMEO_STAGE2,Title,Flags);
break;
case TYPE_VIMEO_STAGE2:
Tempstr=SubstituteVarsInString(Tempstr,"$(BASE)/$(ID)",Vars,0);
RetVal=DownloadItem(Tempstr, Title, Fmt, Flags);
break;
case TYPE_ROYALSOCIETY:
ptr=GetVar(Vars,"ID");
if (ptr && (strncmp(ptr,"http:",5)==0)) RetVal=DownloadItem(ptr,Title, Fmt, Flags);
else
{
Tempstr=SubstituteVarsInString(Tempstr,"http://royalsociety.tv/rsPlayer.aspx?presentationid=$(ID)",Vars,0);
RetVal=DownloadPage(Tempstr,TYPE_ROYALSOCIETY_STAGE2, Title,Flags);
}
break;
case TYPE_ROYALSOCIETY_STAGE2:
Tempstr=SubstituteVarsInString(Tempstr,"$(ID)",Vars,0);
//RetVal=DownloadM3U(Tempstr, Title, Flags);
break;
case TYPE_ASTRONOMYCOM:
Tempstr=SubstituteVarsInString(Tempstr,"$(ID)",Vars,0);
RetVal=DownloadPage(Tempstr,TYPE_ASTRONOMYCOM_STAGE2, Title,Flags);
break;
case TYPE_BLOOMBERG:
Tempstr=SubstituteVarsInString(Tempstr,"http://videos.bloomberg.com/$(ID).flv",Vars,0);
RetVal=DownloadItem(Tempstr, Title, Fmt, Flags);
break;
case TYPE_IMDB:
Tempstr=SubstituteVarsInString(Tempstr,"http://www.imdb.com/video/imdb/vi$(ID)/imdb/single",Vars,0);
RetVal=DownloadPage(Tempstr,TYPE_IMDB_STAGE2, Title,Flags);
break;
case TYPE_REUTERS:
Tempstr=CopyStr(Tempstr, GetVar(Vars,"ID"));
RetVal=DownloadPage(Tempstr,TYPE_REUTERS_STAGE2, Title,Flags);
break;
case TYPE_STANFORD_OPENCLASS:
Tempstr=SubstituteVarsInString(Tempstr,"http://openclassroom.stanford.edu/MainFolder/courses/$(course)/videos/$(ID).xml",Vars,0);
Title=SubstituteVarsInString(Title,"$(course)-$(ID)",Vars,0);
RetVal=DownloadPage(Tempstr,TYPE_STANFORD_STAGE2, Title,Flags);
break;
case TYPE_BITCHUTE:
case TYPE_DOTSUB:
case TYPE_GENERIC:
case TYPE_TED:
case TYPE_NATGEO:
case TYPE_UCTV:
case TYPE_LIVELEAK:
case TYPE_EURONEWS:
case TYPE_SMH:
case TYPE_REDORBIT:
case TYPE_PHOTOBUCKET:
case TYPE_WASHINGTONPOST:
case TYPE_CBSNEWS:
case TYPE_FRANCE24:
case TYPE_METATUBE:
case TYPE_GUARDIAN:
case TYPE_DISCOVERY:
case TYPE_REDORBIT_STAGE2:
case TYPE_ASTRONOMYCOM_STAGE2:
case TYPE_BREAK_STAGE2:
case TYPE_IMDB_STAGE2:
case TYPE_STANFORD_STAGE2:
case TYPE_REUTERS_STAGE2:
case TYPE_EBAUMSWORLD:
case TYPE_DAILYMOTION:
case TYPE_SCREENCAST_COM:
case TYPE_CHARLIEROSE:
case TYPE_CONTAINERFILE_PLS:
case TYPE_CONTAINERFILE_ASX:
case TYPE_CONTAINERFILE_M3U8:
Tempstr=CopyStr(Tempstr, GetVar(Vars,"ID"));
if (strncmp(Tempstr, "https://www.youtube.com/",24)==0) RetVal=GrabMovie(Tempstr, TYPE_YOUTUBE);
else
{
if ((strncmp(Tempstr,"icy:",4)!=0) && (strncmp(Tempstr,"http:",5)!=0) && (strncmp(Tempstr,"https:",6)!=0)) Tempstr=MCopyStr(Tempstr,"http:",GetVar(Vars,"ID"),NULL);
RetVal=DownloadItem(Tempstr, Title, Fmt, Flags);
}
break;
}
Destroy(Tempstr);
Destroy(Title);
Destroy(Fmt);
return(RetVal);
}
void ExtractDailyMotion(const char *Line, const char *Start, const char *End, ListNode *Vars)
{
const char *ptr, *tptr, *eptr;;
char *Item=NULL, *Name=NULL, *Res=NULL;
ptr=Line;
while (ptr)
{
ptr=GenericExtractFromLine(ptr, "item", Start, End, Vars,EXTRACT_DEQUOTE | EXTRACT_NOSPACES);
Item=CopyStr(Item,GetVar(Vars,"item"));
tptr=strstr(Item, "H264-");
if (tptr)
{
tptr+=5;
GetToken(tptr,"/",&Res,0);
Name=MCopyStr(Name,"item:mp4:",Res,NULL);
SetVar(Vars, Name, Item);
}
}
Destroy(Item);
Destroy(Name);
Destroy(Res);
}
/*******************************************************************************************************
// This is the main function that 'screen scrapes' a webpage looking for
// information that it can use to get a video
*******************************************************************************************************/
int ExtractItemInfo(STREAM *S, int Type, const char *URL, const char *Title, int Flags)
{
char *Tempstr=NULL, *Token=NULL, *VarName=NULL, *Server=NULL;
char *Document=NULL;
ListNode *Vars=NULL;
const char *ptr, *remaining, *ptr2;
int MediaCount=0, i, Port;
int RetVal=FALSE, State=0;
ParseURL(URL,NULL,&Server,&Token,NULL,NULL,NULL,NULL);
Port=atoi(Token);
Vars=ListCreate();
SetVar(Vars,"Server",Server);
Tempstr=FormatStr(Tempstr,"%d",Port);
SetVar(Vars,"Port",Tempstr);
if (Flags & (FLAG_DEBUG2 | FLAG_DEBUG3)) fprintf(stderr,"\n------- DOWNLOADING DOCUMENT ------\n");
Document=STREAMReadDocument(Document, S);
remaining=Document;
while (remaining)
{
remaining=GetToken(remaining,"\n",&Tempstr,0);
StripTrailingWhitespace(Tempstr);
StripLeadingWhitespace(Tempstr);
if (Flags & (FLAG_DEBUG2 | FLAG_DEBUG3)) fprintf(stderr,"%s\n",Tempstr);
switch (Type)
{
case TYPE_CONTAINERFILE_PLS:
ptr=GetToken(Tempstr,"=",&Token,0);
if (strncmp(Token,"File",4)==0)
{
GenericExtractFromLine(Tempstr, "item:mp3","=", "", Vars, EXTRACT_DESLASHQUOTE|EXTRACT_GUESSTYPE);
}
break;
case TYPE_CONTAINERFILE_ASX:
#define ASX_ITEM_START "<ref href=\""
if (strstr(Tempstr,ASX_ITEM_START))
{
GenericExtractFromLine(Tempstr, "item:mp3", ASX_ITEM_START, "\"", Vars, EXTRACT_DESLASHQUOTE|EXTRACT_GUESSTYPE);
}
break;
case TYPE_CONTAINERFILE_M3U8:
if (strncmp(Tempstr,"#EXT-X-MEDIA-SEQUENCE",21)==0)
{
//uh oh, this is an apple iphone download rather than a manifest of streams. Call downloader function
M3UStreamDownload(S, URL, Title);
}
else if (strncmp(Tempstr,"#EXT-X-STREAM-INF:",18)==0)
{
/* example of apple iphone stream MANIFEST
#EXT-X-STREAM-INF:PROGRAM-ID=1, BANDWIDTH=898000, RESOLUTION=640x360, CODECS="avc1.42001e,mp4a.40.2"
http://ipad-streaming.cbsnews.com/media/mpx/2016/04/17/667983939550/0417_60Min_Alfonsi_HackingYourPhoneKolbe_508208_800/0417_60Min_Alfonsi_HackingYourPhoneKolbe_508208_800.m3u8
*/
M3UStreamVarName(Tempstr+18, &VarName);
remaining=GetToken(remaining,"\n",&Tempstr,0);
StripTrailingWhitespace(Tempstr);
if (strncasecmp(Tempstr,"http:",5)==0) SetVar(Vars, VarName, Tempstr);
else if (strncasecmp(Tempstr,"https:",6)==0) SetVar(Vars, VarName, Tempstr);
else
{
Token=BuildURL(Token, URL, Tempstr);
SetVar(Vars, VarName, Token);
}
}
else if (*Tempstr !=0) VarsAddDownloadItem("item:mp3", Tempstr, Vars, EXTRACT_GUESSTYPE);
break;
case TYPE_YOUTUBE:
//#define YOUTUBE_PTR "new SWFObject(\"/player2.swf?"
//#define YOUTUBE_PTR "var swfArgs = {"
#define YOUTUBE_DIV "url_encoded_fmt_stream_map="
#define YOUTUBE_TITLE_START "&title="
#define YOUTUBE_END "&"
if (strstr(Tempstr,YOUTUBE_TITLE_START))
{
GenericExtractFromLine(Tempstr, "Title",YOUTUBE_TITLE_START, YOUTUBE_END, Vars, EXTRACT_DEQUOTE);
}
if (strstr(Tempstr,YOUTUBE_DIV))
{
if (! StrValid(GetVar(Vars,"item:flv")))
{
GenericExtractFromLine(Tempstr, "yt:url_fmt",YOUTUBE_DIV, YOUTUBE_END, Vars,EXTRACT_DEQUOTE);
Token=CopyStr(Token,GetVar(Vars,"yt:url_fmt"));
DecodeYouTubeFormats(Token,Vars);
}
}
break;
case TYPE_YOUTUBE_PLAYLIST:
#define YOUTUBE_PLAYLIST_ITEM "/watch?v="
#define YOUTUBE_PLAYLIST_ITEM_END "\""
if (strstr(Tempstr,YOUTUBE_PLAYLIST_ITEM))
{
GenericExtractFromLine(Tempstr, "tmp",YOUTUBE_PLAYLIST_ITEM,YOUTUBE_PLAYLIST_ITEM_END,Vars,EXTRACT_DEHTMLQUOTE | EXTRACT_NOSPACES);
Tempstr=FormatStr(Tempstr,"http://%s:%d/watch?v=%s",Server,Port,GetVar(Vars,"tmp"));
VarName=FormatStr(VarName,"ID:%d",MediaCount);
SetVar(Vars,VarName,Tempstr);
MediaCount++;
}
break;
case TYPE_METACAFE:
#define METACAFE_ITEM "\"sources\":[{\"src\":\""
#define METACAFE_END "\""
GenericTitleExtract(Tempstr, Vars);
if (strstr(Tempstr,METACAFE_ITEM))
{
GenericExtractFromLine(Tempstr, "ID",METACAFE_ITEM, METACAFE_END, Vars, EXTRACT_DESLASHQUOTE | EXTRACT_GUESSTYPE);
}
break;
case TYPE_BREAK_COM:
#define BREAK_ITEM_START "name=\"Break.com Video Player\" src=\""
#define BREAK_END "\""
GenericTitleExtract(Tempstr, Vars);
if (strstr(Tempstr,BREAK_ITEM_START)) GenericExtractFromLine(Tempstr, "ID",BREAK_ITEM_START,BREAK_END,Vars,EXTRACT_DEQUOTE | EXTRACT_NOSPACES);
break;
case TYPE_BREAK_STAGE2:
#define BREAK_STAGE2_REF "<param name=\"movie\" value=\""
#define BREAK_STAGE2_URI "\"uri\": \""
#define BREAK_STAGE2_END "\""
#define BREAK_STAGE2_HEIGHT "\"height\": "
#define BREAK_STAGE2_WIDTH "\"width\": "
if (strstr(Tempstr,"<param name="))
{
Token=UnQuoteStr(Token,Tempstr);
GenericExtractFromLine(Token, "item:reference",BREAK_STAGE2_REF,BREAK_STAGE2_END,Vars, EXTRACT_DEQUOTE | EXTRACT_NOSPACES);
}
if (strstr(Tempstr,BREAK_STAGE2_URI))
{
//set previous item
if (State > 0)
{
VarName=FormatStr(VarName,"width:%d",State);
Token=MCopyStr(Token, "item:mp4:",GetVar(Vars,VarName),"x",NULL);
VarName=FormatStr(VarName,"height:%d",State);
Token=CatStr(Token, GetVar(Vars,VarName));
VarName=FormatStr(VarName,"ID:%d",State);
SetVar(Vars,Token,GetVar(Vars,VarName));
}
VarName=FormatStr(VarName,"ID:%d",++State);
GenericExtractFromLine(Tempstr, VarName,BREAK_STAGE2_URI,BREAK_STAGE2_END,Vars,EXTRACT_DEQUOTE | EXTRACT_NOSPACES);
}
if (strstr(Tempstr,BREAK_STAGE2_WIDTH))
{
VarName=FormatStr(VarName,"width:%d",State);
GenericExtractFromLine(Tempstr, VarName,BREAK_STAGE2_WIDTH,",",Vars,EXTRACT_DEQUOTE | EXTRACT_NOSPACES);
}
if (strstr(Tempstr,BREAK_STAGE2_HEIGHT))
{
VarName=FormatStr(VarName,"height:%d",State);
GenericExtractFromLine(Tempstr, VarName,BREAK_STAGE2_HEIGHT,",",Vars,EXTRACT_DEQUOTE | EXTRACT_NOSPACES);
}
break;
case TYPE_VIMEO:
//"smil":{"url":"http:\/\/player.vimeo.com\/config\/46727983.smil"
#define VIMEO1_ITEM "smil\":{\"url\":\""
#define VIMEO1_ITEM_END "\""
ptr=strstr(Tempstr,VIMEO1_ITEM);
if (ptr)
{
GenericExtractFromLine(Tempstr, "ID",VIMEO1_ITEM,VIMEO1_ITEM_END,Vars,EXTRACT_DESLASHQUOTE | EXTRACT_NOSPACES);
}
break;
case TYPE_VIMEO_STAGE2:
#define VIMEO2_BASE "<meta name=\"httpBase\" content=\""
#define VIMEO2_BASE_END "\""
#define VIMEO2_ITEM "<video src=\""
#define VIMEO2_ITEM_END "\""
ptr=strstr(Tempstr,VIMEO2_BASE);
if (ptr)
{
GenericExtractFromLine(Tempstr, "BASE",VIMEO2_BASE,VIMEO2_BASE_END,Vars,EXTRACT_NOSPACES);
}
ptr=strstr(Tempstr,VIMEO2_ITEM);
if (ptr)
{
GenericExtractFromLine(Tempstr, "ID",VIMEO2_ITEM,VIMEO2_ITEM_END,Vars,EXTRACT_NOSPACES);
}
break;
case TYPE_VIMEO_STAGE3:
#define VIMEO3_ITEM "smil:{\"url\":\""
#define VIMEO3_ITEM_END "\""
ptr=strstr(Tempstr,VIMEO3_ITEM);
if (ptr)
{
GenericExtractFromLine(Tempstr, "ID",VIMEO3_ITEM,VIMEO3_ITEM_END,Vars,EXTRACT_NOSPACES);
}
/*
ptr=strstr(Tempstr,VIMEO2_ITEM);
if (ptr)
{
GenericExtractFromLine(Tempstr, "ID",VIMEO2_ITEM,VIMEO2_ITEM_END,Vars,EXTRACT_NOSPACES);
}
*/
break;
case TYPE_DAILYMOTION:
#define DAILYMOTION_ITEM "/mp4\",\"url\":\""
#define DAILYMOTION_ITEM_END "\"}"
GenericTitleExtract(Tempstr, Vars);
if (strstr(Tempstr,DAILYMOTION_ITEM))
{
Token=UnQuoteStr(Token,Tempstr);
ExtractDailyMotion(Token, DAILYMOTION_ITEM, DAILYMOTION_ITEM_END, Vars);
}
break;
case TYPE_TED:
#define TED_ITEM_START "\"file\":\""
#define TED_ITEM_END "\""
if (strstr(Tempstr,TED_ITEM_START))
{
ptr=Tempstr;
while (ptr)
{
ptr=GenericExtractFromLine(ptr, "file",TED_ITEM_START,TED_ITEM_END,Vars,EXTRACT_DEQUOTE | EXTRACT_NOSPACES);
ptr2=GetVar(Vars,"file");
if (strncmp(ptr2,"http",4)==0) SetVar(Vars,"item:mp4",ptr2);
}
}
break;
case TYPE_REUTERS:
#define REUTERS_ITEM_START "\"embedUrl\": \""
#define REUTERS_ITEM_END "\""
#define REUTERS_TITLE "\"headline\": \""
ptr=strstr(Tempstr,REUTERS_ITEM_START);
if (ptr)
{
GenericExtractFromLine(Tempstr, "item:flv",REUTERS_ITEM_START,REUTERS_ITEM_END,Vars,EXTRACT_NOSPACES);
}
ptr=strstr(Tempstr,REUTERS_TITLE);
if (ptr)
{
GenericExtractFromLine(Tempstr, "Title", REUTERS_TITLE, REUTERS_ITEM_END, Vars, 0);
}
break;
case TYPE_REUTERS_STAGE2:
#define REUTERS_STAGE2_ITEM_START "'mid': '"
#define REUTERS_STAGE2_ITEM_END "'"
ptr=strstr(Tempstr,REUTERS_STAGE2_ITEM_START);
if (ptr)
{
GenericExtractFromLine(Tempstr, "item:flv",REUTERS_STAGE2_ITEM_START,REUTERS_STAGE2_ITEM_END,Vars,EXTRACT_NOSPACES);
}
break;
#define PHOTOBUCKET_START "\"fullsizeUrl\":\""
#define PHOTOBUCKET_END "\""
case TYPE_PHOTOBUCKET:
ptr=strstr(Tempstr,PHOTOBUCKET_START);
if (ptr)
{
GenericExtractFromLine(Tempstr, "item:mp4",PHOTOBUCKET_START,PHOTOBUCKET_END,Vars, EXTRACT_DESLASHQUOTE | EXTRACT_GUESSTYPE);
}
break;
#define SMH_ITEM_START "file\": \""
#define SMH_ITEM_END "\""
#define SMH_TRIGGER "\"playlist\": ["
case TYPE_SMH: