Changeset 35609 for titan/plugins/tithek/tithek_global.h
- Timestamp:
- 09/16/15 16:43:26 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
titan/plugins/tithek/tithek_global.h
r35569 r35609 4 4 #include <curl/curl.h> 5 5 6 struct MemoryStruct {7 char *memory;8 size_t size;9 };10 11 static size_t12 WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp)13 {14 size_t realsize = size * nmemb;15 struct MemoryStruct *mem = (struct MemoryStruct *)userp;16 17 mem->memory = realloc(mem->memory, mem->size + realsize + 1);18 if(mem->memory == NULL) {19 /* out of memory! */20 printf("not enough memory (realloc returned NULL)\n");21 return 0;22 }23 24 memcpy(&(mem->memory[mem->size]), contents, realsize);25 mem->size += realsize;26 mem->memory[mem->size] = 0;27 28 return realsize;29 }30 31 // flag = 0 (without header in output)32 // flag = 1 (with header in output)33 char* gethttps(char* url, char* localfile, char* data, char* user, char* pass, int flag)34 {35 debug(99, "url: %s", url);36 37 int debuglevel = getconfigint("debuglevel", NULL);38 39 char* tmpstr = NULL;40 FILE *fp;41 42 CURL *curl_handle;43 CURLcode res;44 45 struct MemoryStruct chunk;46 47 chunk.memory = malloc(1); /* will be grown as needed by the realloc above */48 chunk.size = 0; /* no data at this point */49 50 curl_global_init(CURL_GLOBAL_ALL);51 52 /* init the curl session */53 curl_handle = curl_easy_init();54 if(curl_handle)55 {56 if(localfile != NULL)57 fp = fopen(localfile,"wb");58 59 /* specify URL to get */60 curl_easy_setopt(curl_handle, CURLOPT_URL, url);61 62 if(user != NULL && pass != NULL)63 {64 curl_easy_setopt(curl_handle, CURLOPT_USERNAME, user);65 curl_easy_setopt(curl_handle, CURLOPT_PASSWORD, pass);66 curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);67 }68 if(data == NULL)69 curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1L);70 else71 curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data);72 if(flag == 1)73 curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1L);74 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 5);75 curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 20);76 /* send all data to this function */77 if(localfile == NULL)78 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback);79 else80 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, NULL);81 82 /* we pass our 'chunk' struct to the callback function */83 if(localfile == NULL)84 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk);85 else86 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, fp);87 88 /* some servers don't like requests that are made without a user-agent field, so we provide one */89 curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0");90 91 // This is occassionally required to stop CURL from verifying the peers certificate.92 // CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if93 // CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a94 // common name and also verify that it matches the hostname provided)95 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L);96 97 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L);98 if(debuglevel == 99)99 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1);100 curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "/mnt/network/cookies");101 curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "/mnt/network/cookies");102 curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L);103 curl_easy_setopt(curl_handle, CURLOPT_AUTOREFERER, 1L);104 105 /* get it! */106 res = curl_easy_perform(curl_handle);107 /* check for errors */108 if(res != CURLE_OK)109 {110 err("failed: %s", curl_easy_strerror(res));111 printf("curl error\n");112 }113 else114 {115 /*116 * Now, our chunk.memory points to a memory block that is chunk.size117 * bytes big and contains the remote file.118 *119 * Do something nice with it!120 */121 printf("%lu bytes retrieved\n", (long)chunk.size);122 }123 124 /* cleanup curl stuff */125 curl_easy_cleanup(curl_handle);126 if(localfile != NULL)127 fclose(fp);128 }129 130 tmpstr = ostrcat(chunk.memory, NULL, 0, 0);131 free(chunk.memory);132 /* we're done with libcurl, so clean it up */133 curl_global_cleanup();134 135 if(localfile != NULL)136 free(tmpstr), tmpstr = NULL;137 return tmpstr;138 }139 140 char* string_decode3(char* input)141 {142 if(input == NULL) return input;143 144 input = string_replace_all("Ä", "Ä", input, 1);145 input = string_replace_all("ä", "ä", input, 1);146 input = string_replace_all("É", "É", input, 1);147 input = string_replace_all("é", "é", input, 1);148 input = string_replace_all("Ö", "Ö", input, 1);149 input = string_replace_all("ö", "ö", input, 1);150 input = string_replace_all("Ü", "Ü", input, 1);151 input = string_replace_all("ü", "ü", input, 1);152 input = string_replace_all("ß", "ß", input, 1);153 input = string_replace_all("&", "&", input, 1);154 155 input = string_replace_all("Ä", "Ä", input, 1);156 input = string_replace_all("ä", "ä", input, 1);157 input = string_replace_all("É", "É", input, 1);158 input = string_replace_all("é", "é", input, 1);159 input = string_replace_all("Ö", "Ö", input, 1);160 input = string_replace_all("ö", "ö", input, 1);161 input = string_replace_all("Ü", "Ü", input, 1);162 input = string_replace_all("ü", "ü", input, 1);163 input = string_replace_all("ß", "ß", input, 1);164 input = string_replace_all("&", "&", input, 1);165 166 return input;167 }168 169 char* getfilekey(char* w, char* i, char* s, char* e)170 {171 char* ret = NULL;172 173 if(w == NULL || i == NULL || s == NULL || e == NULL)174 return NULL;175 176 int a = 0, b = 0, c = 0;177 int a1 = 0, b1 = 0;178 179 int lw = strlen(w);180 int li = strlen(i);181 int ls = strlen(s);182 183 if(lw < 5 || li < 5 || ls < 5)184 return NULL;185 186 char ca[lw + li + ls - 14];187 char cb[16];188 189 ca[lw + li + ls - 15] = '\0';190 cb[15] = '\0';191 192 while(1)193 {194 if(a < 5)195 {196 cb[b1] = w[a];197 b1++;198 }199 else if(a < lw)200 {201 ca[a1] = w[a];202 a1++;203 }204 a++;205 206 if(b < 5)207 {208 cb[b1] = i[b];209 b1++;210 }211 else if(b < li)212 {213 ca[a1] = i[b];214 a1++;215 }216 b++;217 218 if(c < 5)219 {220 cb[b1] = s[c];221 b1++;222 }223 else if(c < ls)224 {225 ca[a1] = s[c];226 a1++;227 }228 c++;229 230 if(lw + li + ls == a1 + b1)231 break;232 }233 234 b = 0;235 int d = 0;236 char cc[a1 / 2 + 1];237 char casub[3] = {'\0'};238 cc[a1 / 2] = '\0';239 240 for(a = 0; a < a1; a += 2)241 {242 int c = -1;243 244 if(cb[b] % 2) c = 1;245 246 casub[0] = ca[a];247 casub[1] = ca[a + 1];248 249 cc[d] = strtol(casub, '\0', 36) - c;250 b++; d++;251 if(b >= b1) b = 0;252 }253 254 char* r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL;255 char* pos = ostrstr(cc, ");}('");256 if(pos != NULL)257 {258 r1 = string_resub(");}('", "'", pos, 0);259 pos = ostrstr(pos + 5, ",'");260 if(pos != NULL)261 {262 r2 = string_resub(",'", "'", pos, 0);263 pos = ostrstr(pos + 2, ",'");264 if(pos != NULL)265 {266 r3 = string_resub(",'", "'", pos, 0);267 pos = ostrstr(pos + 2, ",'");268 if(pos != NULL)269 {270 r4 = string_resub(",'", "'", pos, 0);271 ret = getfilekey(r1, r2, r3, r4);272 }273 }274 }275 }276 else277 {278 ret = string_resub("ll=\"", "\"", cc, 0);279 if(ret == NULL)280 ret = string_resub("filekey=\"", "\"", cc, 0);281 }282 283 free(r1); r1 = NULL;284 free(r2); r2 = NULL;285 free(r3); r3 = NULL;286 free(r4); r4 = NULL;287 288 return ret;289 }290 291 6 char* hoster(char* url) 292 7 { 293 8 debug(99, "url: %s", url); 294 9 char* streamurl = NULL, *tmplink = NULL; 295 296 /*297 if re.match(".*?http://www.putlocker.com/(file|embed)/", link, re.S):298 elif re.match(".*?http://www.sockshare.com/(file|embed)/", link, re.S):299 elif re.match(".*?http://www.videoslasher.com/embed/", link, re.S):300 elif re.match('.*?http://faststream.in', link, re.S):301 elif re.match('.*?http:/.*?flashx.tv', link, re.S):302 elif re.match('.*?http://streamcloud.eu', link, re.S):303 elif re.match('.*?http://vidstream.in', link, re.S):304 elif re.match('.*?http://xvidstage.com', link, re.S):305 elif re.match('.*?http://embed.nowvideo.eu', link, re.S):306 elif re.match('.*?.movshare.net', link, re.S):307 elif re.match('.*?(embed.divxstage.eu|divxstage.eu/video)', link, re.S):308 elif re.match('.*?videoweed.es', link, re.S):309 elif re.match('.*?novamov.com', link, re.S):310 elif re.match('.*primeshare', link, re.S):311 elif re.match('.*?videomega.tv', link, re.S):312 elif re.match('.*?bitshare.com', link, re.S):313 elif re.match('.*?http://movreel.com/', link, re.S):314 elif re.match('.*?uploadc.com', link, re.S):315 elif re.match('.*?http://filenuke.com', link, re.S):316 elif re.match('.*?http://www.youtube.com/watch', link, re.S):317 elif re.match('.*?http://www.mightyupload.com/embed', link, re.S):318 elif re.match('.*?180upload', link, re.S):319 elif re.match('.*?ecostream.tv', link, re.S):320 321 tmplink = ostrcat(url, NULL, 0, 0);322 323 if(ostrstr(tmpstr, "/Out/?s=") != NULL)324 {325 tmplink = string_replace("/Out/?s=", "", tmplink, 1);326 debug(99, "remove out string: %s", tmplink);327 }328 329 330 if(ostrcmp(tmphname, "Sockshare") == 0)331 hname = ostrcat("Sockshare.com", NULL, 0, 0);332 else if(ostrcmp(tmphname, "Putlocker") == 0)333 hname = ostrcat("Putlocker.com", NULL, 0, 0);334 else if(ostrcmp(tmphname, "Filenuke") == 0)335 hname = ostrcat("FileNuke.com", NULL, 0, 0);336 else if(ostrcmp(tmphname, "Streamclou") == 0)337 hname = ostrcat("StreamCloud.eu", NULL, 0, 0);338 else if(ostrcmp(tmphname, "Streamcloud") == 0)339 hname = ostrcat("StreamCloud.eu", NULL, 0, 0);340 else if(ostrcmp(tmphname, "VidStream") == 0)341 hname = ostrcat("VidStream.in", NULL, 0, 0);342 else if(ostrcmp(tmphname, "Flashx") == 0)343 hname = ostrcat("FlashX.tv", NULL, 0, 0);344 else if(ostrcmp(tmphname, "PrimeShare") == 0)345 hname = ostrcat("PrimeShare.tv", NULL, 0, 0);346 else if(ostrcmp(tmphname, "Xvidstage") == 0)347 hname = ostrcat("XvidStage.com", NULL, 0, 0);348 else if(ostrcmp(tmphname, "Nowvideo") == 0)349 hname = ostrcat("NowVideo.eu", NULL, 0, 0);350 else if(ostrcmp(tmphname, "Movshare") == 0)351 hname = ostrcat("MovShare.net", NULL, 0, 0);352 else if(ostrcmp(tmphname, "MovReel") == 0)353 hname = ostrcat("MovReel.com", NULL, 0, 0);354 else if(ostrcmp(tmphname, "NovaMov") == 0)355 hname = ostrcat("NovaMov", NULL, 0, 0);356 else if(ostrcmp(tmphname, "DivXStage") == 0)357 hname = ostrcat("DivXStage", NULL, 0, 0);358 else if(ostrcmp(tmphname, "PrimeShare") == 0)359 hname = ostrcat("PrimeShare.tv", NULL, 0, 0);360 else361 {362 hname = ostrcat(tmphname, " (coming soon)", 0, 0);363 type = 66;364 }365 */366 10 367 11 tmplink = ostrcat(url, NULL, 0, 0); … … 412 56 else if(ostrstr(tmplink, "promptfile") != NULL) 413 57 streamurl = promptfile(url); 414 else if(ostrstr(tmplink, "letwatch") != NULL )58 else if(ostrstr(tmplink, "letwatch") != NULL || ostrstr(tmplink, "realvid") != NULL) 415 59 streamurl = letwatch(url); 416 60 else if(ostrstr(tmplink, "vidbull") != NULL) … … 426 70 else if(ostrstr(tmplink, "mightyupload") != NULL) 427 71 streamurl = mightyupload(url); 72 else if(ostrstr(tmplink, "cloudzilla") != NULL) 73 streamurl = cloudzilla(url); 428 74 else 429 75 textbox(_("Message"), _("The hoster is not yet supported !"), _("OK"), getrcconfigint("rcok", NULL), _("EXIT"), getrcconfigint("rcexit", NULL), NULL, 0, NULL, 0, 600, 200, 5, 0); … … 443 89 444 90 return streamurl; 91 } 92 93 struct MemoryStruct { 94 char *memory; 95 size_t size; 96 }; 97 98 static size_t 99 WriteMemoryCallback(void *contents, size_t size, size_t nmemb, void *userp) 100 { 101 size_t realsize = size * nmemb; 102 struct MemoryStruct *mem = (struct MemoryStruct *)userp; 103 104 mem->memory = realloc(mem->memory, mem->size + realsize + 1); 105 if(mem->memory == NULL) { 106 /* out of memory! */ 107 printf("not enough memory (realloc returned NULL)\n"); 108 return 0; 109 } 110 111 memcpy(&(mem->memory[mem->size]), contents, realsize); 112 mem->size += realsize; 113 mem->memory[mem->size] = 0; 114 115 return realsize; 116 } 117 118 // flag = 0 (without header in output) 119 // flag = 1 (with header in output) 120 char* gethttps(char* url, char* localfile, char* data, char* user, char* pass, int flag) 121 { 122 debug(99, "url: %s", url); 123 124 int debuglevel = getconfigint("debuglevel", NULL); 125 126 char* tmpstr = NULL; 127 FILE *fp; 128 129 CURL *curl_handle; 130 CURLcode res; 131 132 struct MemoryStruct chunk; 133 134 chunk.memory = malloc(1); /* will be grown as needed by the realloc above */ 135 chunk.size = 0; /* no data at this point */ 136 137 curl_global_init(CURL_GLOBAL_ALL); 138 139 /* init the curl session */ 140 curl_handle = curl_easy_init(); 141 if(curl_handle) 142 { 143 if(localfile != NULL) 144 fp = fopen(localfile,"wb"); 145 146 /* specify URL to get */ 147 curl_easy_setopt(curl_handle, CURLOPT_URL, url); 148 149 if(user != NULL && pass != NULL) 150 { 151 curl_easy_setopt(curl_handle, CURLOPT_USERNAME, user); 152 curl_easy_setopt(curl_handle, CURLOPT_PASSWORD, pass); 153 curl_easy_setopt(curl_handle, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 154 } 155 if(data == NULL) 156 curl_easy_setopt(curl_handle, CURLOPT_HTTPGET, 1L); 157 else 158 curl_easy_setopt(curl_handle, CURLOPT_POSTFIELDS, data); 159 if(flag == 1) 160 curl_easy_setopt(curl_handle, CURLOPT_HEADER, 1L); 161 curl_easy_setopt(curl_handle, CURLOPT_CONNECTTIMEOUT, 5); 162 curl_easy_setopt(curl_handle, CURLOPT_TIMEOUT, 20); 163 /* send all data to this function */ 164 if(localfile == NULL) 165 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); 166 else 167 curl_easy_setopt(curl_handle, CURLOPT_WRITEFUNCTION, NULL); 168 169 /* we pass our 'chunk' struct to the callback function */ 170 if(localfile == NULL) 171 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, (void *)&chunk); 172 else 173 curl_easy_setopt(curl_handle, CURLOPT_WRITEDATA, fp); 174 175 /* some servers don't like requests that are made without a user-agent field, so we provide one */ 176 curl_easy_setopt(curl_handle, CURLOPT_USERAGENT, "libcurl-agent/1.0"); 177 178 // This is occassionally required to stop CURL from verifying the peers certificate. 179 // CURLOPT_SSL_VERIFYHOST may also need to be TRUE or FALSE if 180 // CURLOPT_SSL_VERIFYPEER is disabled (it defaults to 2 - check the existence of a 181 // common name and also verify that it matches the hostname provided) 182 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYPEER, 0L); 183 184 curl_easy_setopt(curl_handle, CURLOPT_SSL_VERIFYHOST, 0L); 185 if(debuglevel == 99) 186 curl_easy_setopt(curl_handle, CURLOPT_VERBOSE, 1); 187 curl_easy_setopt(curl_handle, CURLOPT_COOKIEFILE, "/mnt/network/cookies"); 188 curl_easy_setopt(curl_handle, CURLOPT_COOKIEJAR, "/mnt/network/cookies"); 189 curl_easy_setopt(curl_handle, CURLOPT_FOLLOWLOCATION, 1L); 190 curl_easy_setopt(curl_handle, CURLOPT_AUTOREFERER, 1L); 191 192 /* get it! */ 193 res = curl_easy_perform(curl_handle); 194 /* check for errors */ 195 if(res != CURLE_OK) 196 { 197 err("failed: %s", curl_easy_strerror(res)); 198 printf("curl error\n"); 199 } 200 else 201 { 202 /* 203 * Now, our chunk.memory points to a memory block that is chunk.size 204 * bytes big and contains the remote file. 205 * 206 * Do something nice with it! 207 */ 208 printf("%lu bytes retrieved\n", (long)chunk.size); 209 } 210 211 /* cleanup curl stuff */ 212 curl_easy_cleanup(curl_handle); 213 if(localfile != NULL) 214 fclose(fp); 215 } 216 217 tmpstr = ostrcat(chunk.memory, NULL, 0, 0); 218 free(chunk.memory); 219 /* we're done with libcurl, so clean it up */ 220 curl_global_cleanup(); 221 222 if(localfile != NULL) 223 free(tmpstr), tmpstr = NULL; 224 return tmpstr; 225 } 226 227 char* string_decode3(char* input) 228 { 229 if(input == NULL) return input; 230 231 input = string_replace_all("Ä", "Ä", input, 1); 232 input = string_replace_all("ä", "ä", input, 1); 233 input = string_replace_all("É", "É", input, 1); 234 input = string_replace_all("é", "é", input, 1); 235 input = string_replace_all("Ö", "Ö", input, 1); 236 input = string_replace_all("ö", "ö", input, 1); 237 input = string_replace_all("Ü", "Ü", input, 1); 238 input = string_replace_all("ü", "ü", input, 1); 239 input = string_replace_all("ß", "ß", input, 1); 240 input = string_replace_all("&", "&", input, 1); 241 242 input = string_replace_all("Ä", "Ä", input, 1); 243 input = string_replace_all("ä", "ä", input, 1); 244 input = string_replace_all("É", "É", input, 1); 245 input = string_replace_all("é", "é", input, 1); 246 input = string_replace_all("Ö", "Ö", input, 1); 247 input = string_replace_all("ö", "ö", input, 1); 248 input = string_replace_all("Ü", "Ü", input, 1); 249 input = string_replace_all("ü", "ü", input, 1); 250 input = string_replace_all("ß", "ß", input, 1); 251 input = string_replace_all("&", "&", input, 1); 252 253 return input; 254 } 255 256 char* getfilekey(char* w, char* i, char* s, char* e) 257 { 258 char* ret = NULL; 259 260 if(w == NULL || i == NULL || s == NULL || e == NULL) 261 return NULL; 262 263 int a = 0, b = 0, c = 0; 264 int a1 = 0, b1 = 0; 265 266 int lw = strlen(w); 267 int li = strlen(i); 268 int ls = strlen(s); 269 270 if(lw < 5 || li < 5 || ls < 5) 271 return NULL; 272 273 char ca[lw + li + ls - 14]; 274 char cb[16]; 275 276 ca[lw + li + ls - 15] = '\0'; 277 cb[15] = '\0'; 278 279 while(1) 280 { 281 if(a < 5) 282 { 283 cb[b1] = w[a]; 284 b1++; 285 } 286 else if(a < lw) 287 { 288 ca[a1] = w[a]; 289 a1++; 290 } 291 a++; 292 293 if(b < 5) 294 { 295 cb[b1] = i[b]; 296 b1++; 297 } 298 else if(b < li) 299 { 300 ca[a1] = i[b]; 301 a1++; 302 } 303 b++; 304 305 if(c < 5) 306 { 307 cb[b1] = s[c]; 308 b1++; 309 } 310 else if(c < ls) 311 { 312 ca[a1] = s[c]; 313 a1++; 314 } 315 c++; 316 317 if(lw + li + ls == a1 + b1) 318 break; 319 } 320 321 b = 0; 322 int d = 0; 323 char cc[a1 / 2 + 1]; 324 char casub[3] = {'\0'}; 325 cc[a1 / 2] = '\0'; 326 327 for(a = 0; a < a1; a += 2) 328 { 329 int c = -1; 330 331 if(cb[b] % 2) c = 1; 332 333 casub[0] = ca[a]; 334 casub[1] = ca[a + 1]; 335 336 cc[d] = strtol(casub, '\0', 36) - c; 337 b++; d++; 338 if(b >= b1) b = 0; 339 } 340 341 char* r1 = NULL, *r2 = NULL, *r3 = NULL, *r4 = NULL; 342 char* pos = ostrstr(cc, ");}('"); 343 if(pos != NULL) 344 { 345 r1 = string_resub(");}('", "'", pos, 0); 346 pos = ostrstr(pos + 5, ",'"); 347 if(pos != NULL) 348 { 349 r2 = string_resub(",'", "'", pos, 0); 350 pos = ostrstr(pos + 2, ",'"); 351 if(pos != NULL) 352 { 353 r3 = string_resub(",'", "'", pos, 0); 354 pos = ostrstr(pos + 2, ",'"); 355 if(pos != NULL) 356 { 357 r4 = string_resub(",'", "'", pos, 0); 358 ret = getfilekey(r1, r2, r3, r4); 359 } 360 } 361 } 362 } 363 else 364 { 365 ret = string_resub("ll=\"", "\"", cc, 0); 366 if(ret == NULL) 367 ret = string_resub("filekey=\"", "\"", cc, 0); 368 } 369 370 free(r1); r1 = NULL; 371 free(r2); r2 = NULL; 372 free(r3); r3 = NULL; 373 free(r4); r4 = NULL; 374 375 return ret; 445 376 } 446 377
Note: See TracChangeset
for help on using the changeset viewer.