-
Notifications
You must be signed in to change notification settings - Fork 2
/
youtube.c
163 lines (122 loc) · 3.03 KB
/
youtube.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
#include "youtube.h"
//Still trying to figure this out
void YoutubeLogin(char *Username, char *Password)
{
STREAM *S;
char *Tempstr=NULL;
Tempstr=MCopyStr(Tempstr,"https://www.google.com/accounts/ServiceLoginAuth?service=youtube&Email=",Username,"&Passwd=",Password,"&signIn=Sign in","&continue=http://www.youtube.com/signin?action_handle_signin=true&next=",NULL);
//S=HTTPGet("https://www.google.com/accounts/ServiceLogin?uilel=3&service=youtube&passive=true");
S=HTTPGet(Tempstr,"","");
Tempstr=STREAMReadLine(Tempstr,S);
while (Tempstr)
{
StripTrailingWhitespace(Tempstr);
fprintf(stderr,"%s\n",Tempstr);
Tempstr=STREAMReadLine(Tempstr,S);
}
DestroyString(Tempstr);
}
void YouTubeFormatGetData(char *Data, char **URL, char **Code)
{
char *Name=NULL, *Value=NULL, *ptr;
ptr=GetNameValuePair(Data,"&","=",&Name,&Value);
while (ptr)
{
if (StrLen(Name))
{
if (strcmp(Name,"sig")==0) *URL=MCatStr(*URL,"&signature=", Value, NULL);
if (strcmp(Name,"url")==0) *URL=HTTPUnQuote(*URL,Value);
if (strcmp(Name,"itag")==0) *Code=CopyStr(*Code,Value);
}
ptr=GetNameValuePair(ptr,"&","=",&Name,&Value);
}
DestroyString(Name);
DestroyString(Value);
}
void DecodeYouTubeFormats(char *Formats, ListNode *Vars)
{
char *Token=NULL, *Tempstr=NULL, *TypeCode=NULL, *URL=NULL, *ptr;
ptr=GetToken(Formats,",",&Token,0);
while (ptr)
{
YouTubeFormatGetData(Token, &URL, &TypeCode);
switch (atoi(TypeCode))
{
case 5:
SetVar(Vars,"item:flv:400x240",URL);
break;
case 6:
SetVar(Vars,"item:flv:480x270",URL);
break;
case 13:
SetVar(Vars,"item:3gp",URL);
break;
case 17:
SetVar(Vars,"item:3gp:176x144",URL);
break;
case 18:
SetVar(Vars,"item:mp4:480x360",URL);
break;
case 22:
SetVar(Vars,"item:mp4:1280x720",URL);
break;
case 34:
SetVar(Vars,"item:flv-h264:640x360",URL);
break;
case 35:
SetVar(Vars,"item:flv-h264:854x480",URL);
break;
case 36:
SetVar(Vars,"item:3gp:400x240",URL);
break;
case 37:
SetVar(Vars,"item:mp4:1920x1080",URL);
break;
case 38:
SetVar(Vars,"item:mp4:4096x3072",URL);
break;
case 43:
SetVar(Vars,"item:webm:640x360",URL);
break;
case 44:
SetVar(Vars,"item:webm:854x480",URL);
break;
case 45:
SetVar(Vars,"item:webm:1280x720",URL);
break;
case 46:
SetVar(Vars,"item:webm:1920x1080",URL);
break;
case 82:
SetVar(Vars,"item:mp4-3D:640x360",URL);
break;
case 83:
SetVar(Vars,"item:mp4-3D:854x240",URL);
break;
case 84:
SetVar(Vars,"item:mp4-3D:1280x720",URL);
break;
case 85:
SetVar(Vars,"item:mp4-3D:1920x520",URL);
break;
case 100:
SetVar(Vars,"item:webm-3D:640x360",URL);
break;
case 101:
SetVar(Vars,"item:webm-3D:854x480",URL);
break;
case 102:
SetVar(Vars,"item:webm-3D:1280x720",URL);
break;
default:
// if (! Flags & FLAG_QUIET)
if (StrLen(ptr)) fprintf(stderr,"Unknown youtube format [%s]\n",Token);
break;
}
ptr=GetToken(ptr,",",&Token,0);
}
DestroyString(TypeCode);
DestroyString(URL);
DestroyString(Token);
DestroyString(Tempstr);
}