Changeset 25041 for titan/plugins/tmdb/tmdb.h
- Timestamp:
- 11/29/13 21:30:29 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
titan/plugins/tmdb/tmdb.h
r20120 r25041 186 186 187 187 struct tmdb* tnode = NULL; 188 char* tmpstr = NULL, *tmpstr1 = NULL, * logdir = NULL, *logfile = NULL, *tmpsearch = NULL, *savefile = NULL, *timen = NULL, *log = NULL, *posterurl = NULL, *title = NULL, *tmpjpg = NULL, *tmpmpg = NULL, *tmpmeta = NULL;188 char* tmpstr = NULL, *tmpstr1 = NULL, *tmpstr2 = NULL, *tmpstr3 = NULL, *logdir = NULL, *logfile = NULL, *tmpsearch = NULL, *savefile = NULL, *timen = NULL, *log = NULL, *posterurl = NULL, *title = NULL, *tmpjpg = NULL, *tmpmpg = NULL, *tmpmeta = NULL; 189 189 190 190 title = ostrcat(title, input, 1, 0); 191 191 192 192 int count = 0; 193 int mvicount = 0; 193 int mvicount = 0; 194 /* 194 195 tmpsearch = ostrcat("2.1/", NULL, 0, 0); 195 196 if(flag == 0) … … 205 206 tmpsearch = ostrcat(tmpsearch, title, 1, 0); 206 207 tmpsearch = stringreplacechar(tmpsearch, ' ', '+'); 208 */ 209 210 if(flag == 1) 211 { 212 tmpsearch = ostrcat("3/movie/", NULL, 0, 0); 213 tmpsearch = ostrcat(tmpsearch, title, 1, 0); 214 } 215 else 216 tmpsearch = ostrcat("3/movie/tt0083944", NULL, 0, 0); 217 218 tmpsearch = ostrcat(tmpsearch, "?api_key=351217450d7c7865ca39c74a7e3a0a4b&language=de", 1, 0); 207 219 208 220 debug(133, "search: http://api.themoviedb.org/%s", tmpsearch); 209 221 tmpstr = gethttp("api.themoviedb.org", tmpsearch, 80, NULL, NULL, 5000, NULL, 0); 222 // writesys("/var/usr/local/share/titan/plugins/tmdb/tmpstr", tmpstr, 1); 210 223 211 224 debug(133, "tmpsearch: %s", tmpsearch); 212 //debug(133, "tmpstr: %s", tmpstr);225 debug(133, "tmpstr: %s", tmpstr); 213 226 214 227 free(tmpsearch); tmpsearch = NULL; … … 232 245 filedebug(logfile, "#############\nTitle: %s\n#############", title); 233 246 234 if(tmpstr != NULL) 235 { 236 if(ostrstr(tmpstr, "<movies>Nothing found.</movies>") != NULL) 237 { 238 debug(133, "<movies>Nothing found.</movies>"); 247 free(tmpsearch); tmpsearch = NULL; 248 char* ret = NULL; 249 250 if(tmpstr != NULL && ostrstr(tmpstr, "Invalid id - The pre-requisite id is invalid or not found") == NULL) 251 { 252 ret = getxmlentry(tmpstr, "\"Response\":"); 253 if(ostrcmp(ret, "False") == 0) 254 { 255 free(ret); ret = NULL; 239 256 free(tmpstr); tmpstr = NULL; 240 257 return NULL; 241 258 } 242 243 tmpstr1 = ostrstr(tmpstr, "<movie>"); 244 245 while(tmpstr1 != NULL) 246 { 247 tnode = addtmdb(first, 1, tnode); 248 if(tnode == NULL) 259 free(ret); ret = NULL; 260 261 tnode = addtmdb(first, 1, tnode); 262 if(tnode == NULL) 263 { 264 err("no mem"); 265 free(tmpstr); tmpstr = NULL; 266 return *first; 267 } 268 count++; 269 270 tmpstr1 = ostrcat(tmpstr, NULL, 0, 0); 271 int count = 0; 272 int incount = 0; 273 int i = 0; 274 struct splitstr* ret1 = NULL; 275 ret1 = strsplit(tmpstr1, ",", &count); 276 if(ret1 != NULL) 277 { 278 int max = count; 279 for(i = 0; i < max; i++) 249 280 { 250 err("no mem"); 251 free(tmpstr); tmpstr = NULL; 252 return *first; 253 } 254 count++; 255 256 if(ostrstr(tmpstr1, "<name>") != NULL) 257 tnode->title = string_resub("<name>", "</name>", tmpstr1, 0); 258 259 if(ostrstr(tmpstr1, "<language>") != NULL) 260 tnode->language = string_resub("<language>", "</language>", tmpstr1, 0); 261 262 if(ostrstr(tmpstr1, "<type>") != NULL) 263 tnode->type = string_resub("<type>", "</type>", tmpstr1, 0); 264 265 if(ostrstr(tmpstr1, "<original_name>") != NULL) 266 tnode->orgname = string_resub("<original_name>", "</original_name>", tmpstr1, 0); 267 268 if(ostrstr(tmpstr1, "<score>") != NULL) 269 tnode->score = string_resub("<score>", "</score>", tmpstr1, 0); 270 271 if(ostrstr(tmpstr1, "<rated>") != NULL) 272 tnode->rated = string_resub("<rated>", "</rated>", tmpstr1, 0); 273 274 if(ostrstr(tmpstr1, "<released>") != NULL) 275 tnode->released = string_resub("<released>", "</released>", tmpstr1, 0); 276 277 if(ostrstr(tmpstr1, "<categories>") != NULL) 281 if(ostrstr(ret1[i].part, "\"backdrop_path\"") != NULL) 282 { 283 tmpstr2 = string_resub("\"backdrop_path\":\"", "\"", ret1[i].part, 0); 284 tmpstr3 = ostrcat("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w1280", tmpstr2, 0, 0); 285 tnode->backdrop = ostrcat(tnode->backdrop, tmpstr3, 1, 0); 286 tnode->backdrop = ostrcat(tnode->backdrop, "\n", 1, 0); 287 288 mvicount++; 289 } 290 } 291 } 292 free(tmpstr2), tmpstr2 = NULL; 293 free(tmpstr3), tmpstr3 = NULL; 294 free(ret1), ret1 = NULL; 295 296 tmpstr1 = getxmlentry(tmpstr, "\"genres\":"); 297 tmpstr2 = string_resub("[", "]", tmpstr1, 0); 298 count = 0; 299 incount = 0; 300 i = 0; 301 struct splitstr* ret2 = NULL; 302 ret2 = strsplit(tmpstr2, ",", &count); 303 if(ret1 != NULL) 304 { 305 int max = count; 306 for(i = 0; i < max; i++) 307 { 308 if(ostrstr(ret1[i].part, "\"name\"") != NULL) 309 { 310 tmpstr3 = string_resub("\"name\":\"", "\"", ret2[i].part, 0); 311 if(tnode->genre != NULL) 312 tnode->genre = ostrcat(tnode->genre, ",", 1, 0); 313 tnode->genre = ostrcat(tnode->genre, tmpstr3, 1, 0); 314 } 315 } 316 } 317 free(tmpstr2), tmpstr2 = NULL; 318 free(tmpstr3), tmpstr3 = NULL; 319 free(ret2), ret2 = NULL; 320 321 tnode->title = getxmlentry(tmpstr, "\"title\":"); 322 323 tmpstr2 = getxmlentry(tmpstr, "\"spoken_languages\":"); 324 tnode->language = string_resub("\"name\":\"", "\"", tmpstr2, 0); 325 free(tmpstr2), tmpstr2 = NULL; 326 327 tnode->type = string_resub("\"adult\":", ",", tmpstr, 0); 328 tnode->orgname = getxmlentry(tmpstr, "\"original_title\":"); 329 tnode->score = string_resub("\"popularity\":", ",", tmpstr, 0); 330 tnode->rating = string_resub("\"vote_average\":", ",", tmpstr, 0); 331 tnode->votes = string_resub("\"vote_count\":", "}", tmpstr, 0); 332 tnode->released = getxmlentry(tmpstr, "\"release_date\":"); 333 tnode->runtime = string_resub("\"runtime\":", ",", tmpstr, 0); 334 tnode->plot = getxmlentry(tmpstr, "\"overview\":"); 335 tnode->year = getxmlentry(tmpstr, "\"Year\":"); 336 337 tmpstr2 = getxmlentry(tmpstr, "\"poster_path\":"); 338 tnode->thumb = ostrcat("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w300", tmpstr2, 0, 0); 339 free(tmpstr2), tmpstr2 = NULL; 340 341 tmpstr2 = getxmlentry(tmpstr, "\"poster_path\":"); 342 tnode->cover = ostrcat("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w300", tmpstr2, 0, 0); 343 free(tmpstr2), tmpstr2 = NULL; 344 345 tmpstr2 = getxmlentry(tmpstr, "\"poster_path\":"); 346 tnode->postermid = ostrcat("http://d3gtl9l2a4fn1j.cloudfront.net/t/p/w500", tmpstr2, 0, 0); 347 free(tmpstr2), tmpstr2 = NULL; 348 349 tnode->year = getxmlentry(tmpstr, "\"release_date\":"); 350 tnode->imdbid = getxmlentry(tmpstr, "\"imdb_id\":"); 351 tnode->id = string_resub(",\"id\":", ",", tmpstr, 0); 352 353 if(getconfigint("mediadbdebug", NULL) == 1 && tnode->backdrop == NULL) 354 { 355 log = ostrcat(logdir, "/tmdb_", 0, 0); 356 if(tnode->imdbid != NULL) 357 log = ostrcat(log, tnode->imdbid, 1, 0); 358 else 359 log = ostrcat(log, timen, 1, 0); 360 361 log = ostrcat(log, "_html", 1, 0); 362 writesys(log, tmpstr1, 1); 363 free(log), log = NULL; 364 365 log = ostrcat(logdir, "/tmdb_", 0, 0); 366 if(tnode->imdbid != NULL) 367 log = ostrcat(log, tnode->imdbid, 1, 0); 368 else 369 log = ostrcat(log, timen, 1, 0); 370 371 log = ostrcat(log, "_link", 1, 0); 372 writesys(log, tnode->backdrop, 1); 373 free(log), log = NULL; 374 } 375 376 if((flag1 == 0 && count == 1) || flag1 == 1 || flag1 == 2) 377 { 378 savefile = savetmdbpic(tnode->imdbid, tnode->thumb, TMPTMDBPIC1, "_thumb.jpg", flag1); 379 free(tnode->thumb); 380 tnode->thumb = savefile; 381 382 savefile = savetmdbpic(tnode->imdbid, tnode->cover, TMPTMDBPIC2, "_cover.jpg", flag1); 383 free(tnode->cover); 384 tnode->cover = savefile; 385 386 savefile = savetmdbpic(tnode->imdbid, tnode->postermid, TMPTMDBPIC3, "_postermid.jpg", flag1); 387 posterurl = ostrcat(posterurl, tnode->postermid, 1, 0); 388 free(tnode->postermid); 389 tnode->postermid = savefile; 390 391 if(mvicount == 0) 278 392 { 279 char* tmpcat = string_resub("<categories>", "</categories>", tmpstr1, 0); 280 char* ptmpcat = ostrstr(tmpcat, "<category "); 281 while(ptmpcat != NULL) 393 savefile = savetmdbpic(tnode->imdbid, tnode->backdrop, TMPTMDBPIC4, "_backdrop1.jpg", flag1); 394 free(tnode->backdrop); 395 tnode->backdrop = savefile; 396 } 397 } 398 399 if((flag1 == 1 || flag1 == 2) && tnode->backdrop != NULL && tnode->imdbid != NULL) 400 { 401 debug(133, "load backdrop flag1: %d", flag1); 402 char* tmppath = NULL; 403 mvicount = 0; 404 char* tmpstr2 = NULL; 405 tmpstr2 = ostrcat(tnode->backdrop, NULL, 0, 0); 406 struct splitstr* ret1 = NULL; 407 int rcount = 0; 408 int i = 0; 409 ret1 = strsplit(tmpstr2, "\n", &rcount); 410 411 for(i = 0; i < rcount; i++) 412 { 413 mvicount++; 414 debug(133, "load %s\n",(&ret1[i])->part); 415 416 if(!ostrncmp("http://", (&ret1[i])->part, 7)) 282 417 { 283 tnode->genre = ostrcat(tnode->genre, string_resub("<category type=\"genre\" name=\"", "\" url=", ptmpcat, 0), 1, 1); 284 ptmpcat += 5; 285 ptmpcat = ostrstr(ptmpcat, "<category "); 286 287 if(ptmpcat != NULL) 288 tnode->genre = ostrcat(tnode->genre, ", ", 1, 0); 289 } 290 free(tmpcat); tmpcat = NULL; 291 } 292 293 if(ostrstr(tmpstr1, "<runtime>") != NULL) 294 tnode->runtime = string_resub("<runtime>", "</runtime>", tmpstr1, 0); 295 296 if(ostrstr(tmpstr1, "<overview>") != NULL) 297 tnode->plot = string_resub("<overview>", "</overview>", tmpstr1, 0); 298 299 if(ostrstr(tmpstr1, "size=\"thumb\"") != NULL) 300 tnode->thumb = oregex(".*<image type=\"poster\" url=\".*(http://.*)\" size=\"thumb\".*", tmpstr1); 301 302 if(ostrstr(tmpstr1, "size=\"cover\"") != NULL) 303 tnode->cover = oregex(".*<image type=\"poster\" url=\".*(http://.*)\" size=\"cover\".*", tmpstr1); 304 305 if(ostrstr(tmpstr1, "<images>") != NULL) 306 { 307 char* tmpcat = string_resub("<images>", "</images>", tmpstr1, 0); 308 if(tmpcat != NULL) 309 tnode->postermid = oregex(".*<image type=\"poster\" url=\".*(http://.*)\" size=\"mid\".*", tmpcat); 310 free(tmpcat); tmpcat = NULL; 311 } 312 313 if(tnode->postermid == NULL && ostrstr(tmpstr1, "size=\"mid\"") != NULL) 314 tnode->postermid = oregex(".*<image type=\"poster\" url=\".*(http://.*)\" size=\"mid\".*", tmpstr1); 315 316 if(ostrstr(tmpstr1, "<images>") != NULL) 317 { 318 char* tmpcat = string_resub("<images>", "</images>", tmpstr1, 0); 319 char* ptmpcat = ostrstr(tmpcat, "<image "); 320 321 while(ptmpcat != NULL) 322 { 323 tnode->backdrop = ostrcat(tnode->backdrop, string_resub("<image type=\"backdrop\" url=\"", "\" size=", ptmpcat, 0), 1, 1); 324 ptmpcat += 5; 325 ptmpcat = ostrstr(ptmpcat, "<image "); 326 327 if(ptmpcat != NULL) 418 tmppath = ostrcat("_backdrop", oitoa(mvicount), 0, 1); 419 tmppath = ostrcat(tmppath, ".jpg", 1, 0); 420 421 savefile = savetmdbpic(tnode->imdbid, (&ret1[i])->part, TMPTMDBPIC4, tmppath, flag1); 422 if(file_exist(savefile)) 328 423 { 329 mvicount++; 330 tnode->backdrop = ostrcat(tnode->backdrop, "\n", 1, 0); 331 } 332 } 333 free(tmpcat); tmpcat = NULL; 334 } 335 336 if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"original\"") != NULL) 337 tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/original/.*)\" size=\"original\" width=\"1920\" height=\"1080\".*", tmpstr1); 338 339 if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"original\"") != NULL) 340 tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/original/.*)\" size=\"original\" width=\"1280\" height=\"720\".*", tmpstr1); 341 342 if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"w1280\"") != NULL) 343 tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/w1280/.*)\" size=\"w1280\" width=\"1280\" height=\"720\".*", tmpstr1); 344 345 if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"w780\"") != NULL) 346 tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/w780/.*)\" size=\"poster\" width=\"780\" height=\"439\".*", tmpstr1); 347 348 if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"original\"") != NULL) 349 tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/original/.*)\" size=\"original\".*", tmpstr1); 350 351 if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"w1280\"") != NULL) 352 tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/w1280/.*)\" size=\"w1280\".*", tmpstr1); 353 354 if(tnode->backdrop == NULL && ostrstr(tmpstr1, "size=\"poster\"") != NULL) 355 tnode->backdrop = oregex(".*<image type=\"backdrop\" url=\".*(http://.*/poster/.*)\" size=\"poster\".*", tmpstr1); 356 357 if(ostrstr(tmpstr1, "<imdb_id>") != NULL) 358 tnode->imdbid = string_resub("<imdb_id>", "</imdb_id>", tmpstr1, 0); 359 360 if(getconfigint("mediadbdebug", NULL) == 1 && tnode->backdrop == NULL) 361 { 362 log = ostrcat(logdir, "/tmdb_", 0, 0); 363 if(tnode->imdbid != NULL) 364 log = ostrcat(log, tnode->imdbid, 1, 0); 365 else 366 log = ostrcat(log, timen, 1, 0); 367 368 log = ostrcat(log, "_html", 1, 0); 369 writesys(log, tmpstr1, 1); 370 free(log), log = NULL; 371 372 log = ostrcat(logdir, "/tmdb_", 0, 0); 373 if(tnode->imdbid != NULL) 374 log = ostrcat(log, tnode->imdbid, 1, 0); 375 else 376 log = ostrcat(log, timen, 1, 0); 377 378 log = ostrcat(log, "_link", 1, 0); 379 writesys(log, tnode->backdrop, 1); 380 free(log), log = NULL; 381 } 382 383 if(ostrstr(tmpstr1, "<rating>") != NULL) 384 tnode->rating = string_resub("<rating>", "</rating>", tmpstr1, 0); 385 386 if(ostrstr(tmpstr1, "<votes>") != NULL) 387 tnode->votes = string_resub("<votes>", "</votes>", tmpstr1, 0); 388 389 if(ostrstr(tmpstr1, "<id>") != NULL) 390 tnode->id = string_resub("<id>", "</id>", tmpstr1, 0); 391 392 if((flag1 == 0 && count == 1) || flag1 == 1 || flag1 == 2) 393 { 394 savefile = savetmdbpic(tnode->imdbid, tnode->thumb, TMPTMDBPIC1, "_thumb.jpg", flag1); 395 free(tnode->thumb); 396 tnode->thumb = savefile; 397 398 savefile = savetmdbpic(tnode->imdbid, tnode->cover, TMPTMDBPIC2, "_cover.jpg", flag1); 399 free(tnode->cover); 400 tnode->cover = savefile; 401 402 savefile = savetmdbpic(tnode->imdbid, tnode->postermid, TMPTMDBPIC3, "_postermid.jpg", flag1); 403 posterurl = ostrcat(posterurl, tnode->postermid, 1, 0); 404 free(tnode->postermid); 405 tnode->postermid = savefile; 406 407 if(mvicount == 0) 408 { 409 savefile = savetmdbpic(tnode->imdbid, tnode->backdrop, TMPTMDBPIC4, "_backdrop1.jpg", flag1); 410 free(tnode->backdrop); 411 tnode->backdrop = savefile; 412 } 413 } 424 free(tnode->backdrop); 425 tnode->backdrop = savefile; 426 427 free(tnode->mvi); 428 tnode->mvi = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0); 429 tnode->mvi = ostrcat(tnode->mvi, tnode->imdbid, 1, 0); 430 tnode->mvi = ostrcat(tnode->mvi, "_backdrop", 1, 0); 431 tnode->mvi = ostrcat(tnode->mvi, oitoa(mvicount), 1, 1); 432 tnode->mvi = ostrcat(tnode->mvi, ".mvi", 1, 0); 433 434 if((!file_exist(tnode->mvi)) || (flag1 == 2)) 435 { 436 off64_t filesize = getfilesize(tnode->backdrop); 437 debug(133, "filesize %lld", filesize); 414 438 415 if((flag1 == 1 || flag1 == 2) && tnode->backdrop != NULL && tnode->imdbid != NULL) 416 { 417 debug(133, "load backdrop flag1: %d", flag1); 418 char* tmppath = NULL; 419 mvicount = 0; 420 char* tmpstr2 = NULL; 421 tmpstr2 = ostrcat(tnode->backdrop, NULL, 0, 0); 422 struct splitstr* ret1 = NULL; 423 int rcount = 0; 424 int i = 0; 425 ret1 = strsplit(tmpstr2, "\n", &rcount); 426 for(i = 0; i < rcount; i++) 427 { 428 if(ostrstr((&ret1[i])->part, "/original/") != NULL) 429 { 430 mvicount++; 431 debug(133, "load %s\n",(&ret1[i])->part); 432 433 if(!ostrncmp("http://", (&ret1[i])->part, 7)) 434 { 435 tmppath = ostrcat("_backdrop", oitoa(mvicount), 0, 1); 436 tmppath = ostrcat(tmppath, ".jpg", 1, 0); 437 438 savefile = savetmdbpic(tnode->imdbid, (&ret1[i])->part, TMPTMDBPIC4, tmppath, flag1); 439 if(file_exist(savefile)) 439 if(filesize < 1500000) 440 440 { 441 free(tnode->backdrop); 442 tnode->backdrop = savefile; 443 444 free(tnode->mvi); 445 tnode->mvi = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0); 446 tnode->mvi = ostrcat(tnode->mvi, tnode->imdbid, 1, 0); 447 tnode->mvi = ostrcat(tnode->mvi, "_backdrop", 1, 0); 448 tnode->mvi = ostrcat(tnode->mvi, oitoa(mvicount), 1, 1); 449 tnode->mvi = ostrcat(tnode->mvi, ".mvi", 1, 0); 450 451 if((!file_exist(tnode->mvi)) || (flag1 == 2)) 452 { 453 454 off64_t filesize = getfilesize(tnode->backdrop); 455 debug(133, "filesize %lld", filesize); 456 457 if(filesize < 1500000) 458 { 459 char* cmd = NULL; 460 cmd = ostrcat(cmd, "ffmpeg -i ", 1, 0); 461 cmd = ostrcat(cmd, tnode->backdrop, 1, 0); 462 cmd = ostrcat(cmd, " > ", 1, 0); 463 cmd = ostrcat(cmd, tmpmeta, 1, 0); 464 cmd = ostrcat(cmd, " 2>&1", 1, 0); 465 466 debug(133, "cmd %s", cmd); 467 system(cmd); 468 free(cmd); cmd = NULL; 469 470 cmd = ostrcat(cmd, "cat ", 1, 0); 471 cmd = ostrcat(cmd, tmpmeta, 1, 0); 472 cmd = ostrcat(cmd, " | grep Stream | awk '{print $6}' | cut -d'x' -f1", 1, 0); 473 char* size = string_newline(command(cmd)); 474 free(cmd), cmd = NULL; 475 debug(133, "size %s", size); 476 if(size != NULL) 477 { 478 debug(133, "size %d", atoi(size)); 479 int picsize = atoi(size); 480 unlink(tmpmeta); 481 482 if(picsize < 2000) 483 { 484 debug(133, "size ok %d", picsize); 485 cmd = ostrcat(cmd, "jpegtran -outfile ", 1, 0); 486 cmd = ostrcat(cmd, tmpjpg, 1, 0); 487 cmd = ostrcat(cmd, " -copy none ", 1, 0); 488 cmd = ostrcat(cmd, tnode->backdrop, 1, 0); 489 490 debug(133, "cmd %s", cmd); 491 system(cmd); 492 free(cmd); cmd = NULL; 493 if(file_exist(tmpjpg)) 494 { 495 free(cmd), cmd = NULL; 496 cmd = ostrcat(cmd, "ffmpeg -y -f image2 -i ", 1, 0); 497 cmd = ostrcat(cmd, tmpjpg, 1, 0); 498 cmd = ostrcat(cmd, " ", 1, 0); 499 cmd = ostrcat(cmd, tmpmpg, 1, 0); 500 501 if(getconfigint("mediadbdebug", NULL) == 1) 502 { 503 filedebug(logfile, "#############\nbackdrop: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part); 504 cmd = ostrcat(cmd, " >> ", 1, 0); 505 cmd = ostrcat(cmd, logfile, 1, 0); 506 cmd = ostrcat(cmd, " 2>&1", 1, 0); 507 } 508 else 509 { 510 cmd = ostrcat(cmd, " > /dev/null 2>&1", 1, 0); 511 } 512 debug(133, "cmd %s", cmd); 513 system(cmd); 514 free(cmd); cmd = NULL; 515 516 if(file_exist(tmpmpg)) 517 { 518 cmd = ostrcat(cmd, "mv -f ", 1, 0); 519 cmd = ostrcat(cmd, tmpmpg, 1, 0); 520 cmd = ostrcat(cmd, " ", 1, 0); 521 cmd = ostrcat(cmd, tnode->mvi, 1, 0); 522 debug(133, "cmd %s", cmd); 523 system(cmd); 524 free(cmd); cmd = NULL; 525 526 if(getconfigint("mediadbdebug", NULL) == 1) 527 writesysint("/proc/sys/vm/drop_caches", 3, 0); 528 529 if(mvicount == getconfigint("mediadbbackdrop", NULL)) 530 break; 531 } 532 else 533 mvicount--; 534 } 535 } 536 else 537 { 538 debug(133, "ERROR Backdrop size to big skipped %d", picsize); 539 540 if(getconfigint("mediadbdebug", NULL) == 1) 541 filedebug(logfile, "#############\nERROR Backdrop size to big skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part); 542 mvicount--; 543 } 544 } 545 else 546 { 547 debug(133, "ERROR Backdrop size is NULL skipped %s", size); 548 549 if(getconfigint("mediadbdebug", NULL) == 1) 550 filedebug(logfile, "#############\nERROR Backdrop size is NULL skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part); 551 552 mvicount--; 553 } 554 free(size), size = NULL; 555 unlink(tmpmeta); 556 unlink(tmpjpg); 557 unlink(tmpmpg); 558 } 559 else 560 { 561 debug(133, "ERROR Backdrop filesize to BIG skipped %lld", filesize); 562 563 if(getconfigint("mediadbdebug", NULL) == 1) 564 filedebug(logfile, "#############\nERROR Backdrop filesize to BIG skipped: %s filesize(%lld) (%s)\n#############", tnode->backdrop, filesize, (&ret1[i])->part); 565 } 566 } 567 568 free(tmppath), tmppath = NULL; 569 } 570 else 571 mvicount--; 572 } 573 else 574 { 575 log = ostrcat(logdir, "/tmdb_", 0, 0); 576 if(tnode->imdbid != NULL) 577 log = ostrcat(log, tnode->imdbid, 1, 0); 578 else 579 log = ostrcat(log, timen, 1, 0); 580 581 log = ostrcat(log, "_html", 1, 0); 582 583 char* cmd = NULL; 584 cmd = command("free"); 585 log = ostrcat(log, "_error_link", 1, 0); 586 cmd = ostrcat(cmd, "\nlink: ", 1, 0); 587 cmd = ostrcat(cmd, (&ret1[i])->part, 1, 0); 588 writesys(log, cmd, 1); 589 free(cmd), cmd = NULL; 590 free(log), log = NULL; 591 mvicount--; 592 } 593 594 if(file_exist(tnode->mvi)) 595 unlink(tnode->backdrop); 596 } 597 } 598 free(ret1), ret1 = NULL; 599 free(tmpstr2), tmpstr2 = NULL; 600 } 601 else if((flag1 == 1 || flag1 == 2) && tnode->postermid != NULL && tnode->imdbid != NULL) 602 { 603 debug(133, "load postermid flag1: %d", flag1); 604 605 free(tnode->mvi); 606 tnode->mvi = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0); 607 tnode->mvi = ostrcat(tnode->mvi, tnode->imdbid, 1, 0); 608 tnode->mvi = ostrcat(tnode->mvi, "_backdrop1.mvi", 1, 0); 609 610 if((!file_exist(tnode->mvi)) || (flag1 == 2)) 611 { 612 613 off64_t filesize = getfilesize(tnode->backdrop); 614 debug(133, "filesize %lld", filesize); 615 616 if(filesize < 1500000) 617 { 618 char* cmd = NULL; 619 cmd = ostrcat(cmd, "ffmpeg -i ", 1, 0); 620 cmd = ostrcat(cmd, tnode->postermid, 1, 0); 621 cmd = ostrcat(cmd, " > ", 1, 0); 622 cmd = ostrcat(cmd, tmpmeta, 1, 0); 623 cmd = ostrcat(cmd, " 2>&1", 1, 0); 624 625 debug(133, "cmd %s", cmd); 626 system(cmd); 627 free(cmd); cmd = NULL; 628 629 cmd = ostrcat(cmd, "cat ", 1, 0); 630 cmd = ostrcat(cmd, tmpmeta, 1, 0); 631 cmd = ostrcat(cmd, " | grep Stream | awk '{print $6}' | cut -d'x' -f1", 1, 0); 632 char* size = string_newline(command(cmd)); 633 free(cmd), cmd = NULL; 634 debug(133, "size %s", size); 635 if(size != NULL) 636 { 637 debug(133, "size %d", atoi(size)); 638 int picsize = atoi(size); 639 640 if(picsize < 2000) 641 { 642 debug(133, "size ok %d", picsize); 643 cmd = ostrcat(cmd, "jpegtran -outfile ", 1, 0); 644 cmd = ostrcat(cmd, tmpjpg, 1, 0); 645 cmd = ostrcat(cmd, " -copy none ", 1, 0); 646 cmd = ostrcat(cmd, tnode->postermid, 1, 0); 441 char* cmd = NULL; 442 cmd = ostrcat(cmd, "ffmpeg -i ", 1, 0); 443 cmd = ostrcat(cmd, tnode->backdrop, 1, 0); 444 cmd = ostrcat(cmd, " > ", 1, 0); 445 cmd = ostrcat(cmd, tmpmeta, 1, 0); 446 cmd = ostrcat(cmd, " 2>&1", 1, 0); 647 447 648 448 debug(133, "cmd %s", cmd); 649 449 system(cmd); 650 450 free(cmd); cmd = NULL; 451 452 cmd = ostrcat(cmd, "cat ", 1, 0); 453 cmd = ostrcat(cmd, tmpmeta, 1, 0); 454 cmd = ostrcat(cmd, " | grep Stream | awk '{print $6}' | cut -d'x' -f1", 1, 0); 455 char* size = string_newline(command(cmd)); 456 free(cmd), cmd = NULL; 457 debug(133, "size %s", size); 458 if(size != NULL) 459 { 460 debug(133, "size %d", atoi(size)); 461 int picsize = atoi(size); 462 unlink(tmpmeta); 463 464 if(picsize < 2000) 465 { 466 debug(133, "size ok %d", picsize); 467 cmd = ostrcat(cmd, "jpegtran -outfile ", 1, 0); 468 cmd = ostrcat(cmd, tmpjpg, 1, 0); 469 cmd = ostrcat(cmd, " -copy none ", 1, 0); 470 cmd = ostrcat(cmd, tnode->backdrop, 1, 0); 471 472 debug(133, "cmd %s", cmd); 473 system(cmd); 474 free(cmd); cmd = NULL; 475 if(file_exist(tmpjpg)) 476 { 477 free(cmd), cmd = NULL; 478 cmd = ostrcat(cmd, "ffmpeg -y -f image2 -i ", 1, 0); 479 cmd = ostrcat(cmd, tmpjpg, 1, 0); 480 cmd = ostrcat(cmd, " ", 1, 0); 481 cmd = ostrcat(cmd, tmpmpg, 1, 0); 482 483 if(getconfigint("mediadbdebug", NULL) == 1) 484 { 485 filedebug(logfile, "#############\nbackdrop: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part); 486 cmd = ostrcat(cmd, " >> ", 1, 0); 487 cmd = ostrcat(cmd, logfile, 1, 0); 488 cmd = ostrcat(cmd, " 2>&1", 1, 0); 489 } 490 else 491 { 492 cmd = ostrcat(cmd, " > /dev/null 2>&1", 1, 0); 493 } 494 debug(133, "cmd %s", cmd); 495 system(cmd); 496 free(cmd); cmd = NULL; 497 498 if(file_exist(tmpmpg)) 499 { 500 cmd = ostrcat(cmd, "mv -f ", 1, 0); 501 cmd = ostrcat(cmd, tmpmpg, 1, 0); 502 cmd = ostrcat(cmd, " ", 1, 0); 503 cmd = ostrcat(cmd, tnode->mvi, 1, 0); 504 debug(133, "cmd %s", cmd); 505 system(cmd); 506 free(cmd); cmd = NULL; 651 507 652 if(file_exist(tmpjpg)) 653 { 654 free(cmd), cmd = NULL; 655 cmd = ostrcat(cmd, "ffmpeg -y -f image2 -i ", 1, 0); 656 cmd = ostrcat(cmd, tmpjpg, 1, 0); 657 cmd = ostrcat(cmd, " ", 1, 0); 658 cmd = ostrcat(cmd, tmpmpg, 1, 0); 659 660 if(getconfigint("mediadbdebug", NULL) == 1) 661 { 662 filedebug(logfile, "#############\npostermid: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl); 663 cmd = ostrcat(cmd, " >> ", 1, 0); 664 cmd = ostrcat(cmd, logfile, 1, 0); 665 cmd = ostrcat(cmd, " 2>&1", 1, 0); 508 if(getconfigint("mediadbdebug", NULL) == 1) 509 writesysint("/proc/sys/vm/drop_caches", 3, 0); 510 511 if(mvicount == getconfigint("mediadbbackdrop", NULL)) 512 break; 513 } 514 else 515 mvicount--; 516 } 666 517 } 667 518 else 668 519 { 669 cmd = ostrcat(cmd, " > /dev/null 2>&1", 1, 0); 520 debug(133, "ERROR Backdrop size to big skipped %d", picsize); 521 522 if(getconfigint("mediadbdebug", NULL) == 1) 523 filedebug(logfile, "#############\nERROR Backdrop size to big skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part); 524 mvicount--; 670 525 } 671 526 } 527 else 528 { 529 debug(133, "ERROR Backdrop size is NULL skipped %s", size); 530 531 if(getconfigint("mediadbdebug", NULL) == 1) 532 filedebug(logfile, "#############\nERROR Backdrop size is NULL skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->backdrop, size, filesize, (&ret1[i])->part); 533 534 mvicount--; 535 } 536 free(size), size = NULL; 537 unlink(tmpmeta); 538 unlink(tmpjpg); 539 unlink(tmpmpg); 540 } 541 else 542 { 543 debug(133, "ERROR Backdrop filesize to BIG skipped %lld", filesize); 544 545 if(getconfigint("mediadbdebug", NULL) == 1) 546 filedebug(logfile, "#############\nERROR Backdrop filesize to BIG skipped: %s filesize(%lld) (%s)\n#############", tnode->backdrop, filesize, (&ret1[i])->part); 547 } 548 } 549 550 free(tmppath), tmppath = NULL; 551 } 552 else 553 mvicount--; 554 } 555 else 556 { 557 log = ostrcat(logdir, "/tmdb_", 0, 0); 558 if(tnode->imdbid != NULL) 559 log = ostrcat(log, tnode->imdbid, 1, 0); 560 else 561 log = ostrcat(log, timen, 1, 0); 562 563 log = ostrcat(log, "_html", 1, 0); 564 565 char* cmd = NULL; 566 cmd = command("free"); 567 log = ostrcat(log, "_error_link", 1, 0); 568 cmd = ostrcat(cmd, "\nlink: ", 1, 0); 569 cmd = ostrcat(cmd, (&ret1[i])->part, 1, 0); 570 writesys(log, cmd, 1); 571 free(cmd), cmd = NULL; 572 free(log), log = NULL; 573 mvicount--; 574 } 575 576 if(file_exist(tnode->mvi)) 577 unlink(tnode->backdrop); 578 } 579 free(ret1), ret1 = NULL; 580 free(tmpstr2), tmpstr2 = NULL; 581 } 582 else if((flag1 == 1 || flag1 == 2) && tnode->postermid != NULL && tnode->imdbid != NULL) 583 { 584 debug(133, "load postermid flag1: %d", flag1); 585 586 free(tnode->mvi); 587 tnode->mvi = ostrcat(getconfig("mediadbpath", NULL), "/", 0, 0); 588 tnode->mvi = ostrcat(tnode->mvi, tnode->imdbid, 1, 0); 589 tnode->mvi = ostrcat(tnode->mvi, "_backdrop1.mvi", 1, 0); 590 591 if((!file_exist(tnode->mvi)) || (flag1 == 2)) 592 { 593 594 off64_t filesize = getfilesize(tnode->backdrop); 595 debug(133, "filesize %lld", filesize); 596 597 if(filesize < 1500000) 598 { 599 char* cmd = NULL; 600 cmd = ostrcat(cmd, "ffmpeg -i ", 1, 0); 601 cmd = ostrcat(cmd, tnode->postermid, 1, 0); 602 cmd = ostrcat(cmd, " > ", 1, 0); 603 cmd = ostrcat(cmd, tmpmeta, 1, 0); 604 cmd = ostrcat(cmd, " 2>&1", 1, 0); 605 606 debug(133, "cmd %s", cmd); 607 system(cmd); 608 free(cmd); cmd = NULL; 609 610 cmd = ostrcat(cmd, "cat ", 1, 0); 611 cmd = ostrcat(cmd, tmpmeta, 1, 0); 612 cmd = ostrcat(cmd, " | grep Stream | awk '{print $6}' | cut -d'x' -f1", 1, 0); 613 char* size = string_newline(command(cmd)); 614 free(cmd), cmd = NULL; 615 debug(133, "size %s", size); 616 if(size != NULL) 617 { 618 debug(133, "size %d", atoi(size)); 619 int picsize = atoi(size); 620 621 if(picsize < 2000) 622 { 623 debug(133, "size ok %d", picsize); 624 cmd = ostrcat(cmd, "jpegtran -outfile ", 1, 0); 625 cmd = ostrcat(cmd, tmpjpg, 1, 0); 626 cmd = ostrcat(cmd, " -copy none ", 1, 0); 627 cmd = ostrcat(cmd, tnode->postermid, 1, 0); 628 629 debug(133, "cmd %s", cmd); 630 system(cmd); 631 free(cmd); cmd = NULL; 632 633 if(file_exist(tmpjpg)) 634 { 635 free(cmd), cmd = NULL; 636 cmd = ostrcat(cmd, "ffmpeg -y -f image2 -i ", 1, 0); 637 cmd = ostrcat(cmd, tmpjpg, 1, 0); 638 cmd = ostrcat(cmd, " ", 1, 0); 639 cmd = ostrcat(cmd, tmpmpg, 1, 0); 640 641 if(getconfigint("mediadbdebug", NULL) == 1) 642 { 643 filedebug(logfile, "#############\npostermid: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl); 644 cmd = ostrcat(cmd, " >> ", 1, 0); 645 cmd = ostrcat(cmd, logfile, 1, 0); 646 cmd = ostrcat(cmd, " 2>&1", 1, 0); 647 } 648 else 649 { 650 cmd = ostrcat(cmd, " > /dev/null 2>&1", 1, 0); 651 } 652 653 debug(133, "cmd %s", cmd); 654 system(cmd); 655 free(cmd); cmd = NULL; 656 if(file_exist(tmpmpg)) 657 { 658 cmd = ostrcat(cmd, "mv -f ", 1, 0); 659 cmd = ostrcat(cmd, tmpmpg, 1, 0); 660 cmd = ostrcat(cmd, " ", 1, 0); 661 cmd = ostrcat(cmd, tnode->mvi, 1, 0); 672 662 debug(133, "cmd %s", cmd); 673 663 system(cmd); 674 664 free(cmd); cmd = NULL; 675 if(file_exist(tmpmpg)) 676 { 677 cmd = ostrcat(cmd, "mv -f ", 1, 0); 678 cmd = ostrcat(cmd, tmpmpg, 1, 0); 679 cmd = ostrcat(cmd, " ", 1, 0); 680 cmd = ostrcat(cmd, tnode->mvi, 1, 0); 681 debug(133, "cmd %s", cmd); 682 system(cmd); 683 free(cmd); cmd = NULL; 684 685 writesysint("/proc/sys/vm/drop_caches", 3, 0); 686 } 665 666 writesysint("/proc/sys/vm/drop_caches", 3, 0); 687 667 } 688 free(cmd), cmd = NULL;689 668 } 690 else 691 { 692 debug(133, "ERROR Postermid size to big skipped %d", picsize); 693 694 if(getconfigint("mediadbdebug", NULL) == 1) 695 filedebug(logfile, "#############\nERROR Postermid size to big skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl); 696 } 669 free(cmd), cmd = NULL; 697 670 } 698 671 else 699 672 { 700 debug(133, "ERROR Postermid size is NULL skipped %s",size);673 debug(133, "ERROR Postermid size to big skipped %d", picsize); 701 674 702 675 if(getconfigint("mediadbdebug", NULL) == 1) 703 filedebug(logfile, "#############\nERROR Postermid size is NULL skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl);676 filedebug(logfile, "#############\nERROR Postermid size to big skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl); 704 677 } 705 free(size), size = NULL;706 unlink(tmpmeta);707 unlink(tmpjpg);708 unlink(tmpmpg);709 678 } 710 679 else 711 680 { 712 debug(133, "ERROR Postermid filesize to BIG skipped %lld", filesize);681 debug(133, "ERROR Postermid size is NULL skipped %s", size); 713 682 714 683 if(getconfigint("mediadbdebug", NULL) == 1) 715 filedebug(logfile, "#############\nERROR Postermid filesize to BIG skipped: %s filesize(%lld) (%s)\n#############", tnode->postermid, filesize, posterurl);684 filedebug(logfile, "#############\nERROR Postermid size is NULL skipped: %s size=(%s) filesize(%lld) (%s)\n#############", tnode->postermid, size, filesize, posterurl); 716 685 } 686 free(size), size = NULL; 687 unlink(tmpmeta); 688 unlink(tmpjpg); 689 unlink(tmpmpg); 717 690 } 718 } 719 720 debug(133, "mvi=%s (mvicount=%d)", tnode->mvi,flag1); 721 debug(133, "backdrop=%s (mvicount=%d)", tnode->backdrop,flag1); 722 723 if(file_exist(tnode->mvi)) 724 unlink(tnode->backdrop); 725 726 if(mvicount > 0) 727 { 728 free(tnode->mvi); 729 tnode->mvi = ostrcat(oitoa(mvicount), NULL, 1, 0); 730 } 731 else 732 { 733 free(tnode->mvi); 734 tnode->mvi = ostrcat("1", NULL, 0, 0); 735 } 736 debug(133, "change mvi=%s (mvicount=%d)", tnode->mvi,flag1); 737 738 tmpstr1 += 5; 739 tmpstr1 = ostrstr(tmpstr1, "<movie>"); 740 741 free(posterurl), posterurl = NULL; 742 free(logdir), logdir = NULL; 743 free(logfile), logfile = NULL; 744 745 debug(133, "----------------------tmdb start----------------------"); 746 debug(133, "title: %s", tnode->title); 747 debug(133, "language: %s", tnode->language); 748 debug(133, "type: %s", tnode->type); 749 debug(133, "orgname: %s", tnode->orgname); 750 debug(133, "score: %s", tnode->score); 751 debug(133, "rating: %s", tnode->rating); 752 debug(133, "released: %s", tnode->released); 753 debug(133, "genre: %s", tnode->genre); 754 debug(133, "runtime: %s", tnode->runtime); 755 debug(133, "plot: %s", tnode->plot); 756 debug(133, "thumb: %s", tnode->thumb); 757 debug(133, "cover: %s", tnode->cover); 758 debug(133, "postermid: %s", tnode->postermid); 759 debug(133, "backdrop: %s", tnode->backdrop); 760 debug(133, "mvi: %s", tnode->mvi); 761 debug(133, "rating: %s", tnode->rating); 762 debug(133, "votes: %s", tnode->votes); 763 debug(133, "id: %s", tnode->id); 764 debug(133, "imdbid: %s", tnode->imdbid); 765 debug(133, "----------------------tmdb end----------------------"); 766 } 767 } 768 769 free(tmpstr); tmpstr = NULL; 691 else 692 { 693 debug(133, "ERROR Postermid filesize to BIG skipped %lld", filesize); 694 695 if(getconfigint("mediadbdebug", NULL) == 1) 696 filedebug(logfile, "#############\nERROR Postermid filesize to BIG skipped: %s filesize(%lld) (%s)\n#############", tnode->postermid, filesize, posterurl); 697 } 698 } 699 } 700 701 702 debug(133, "mvi=%s (mvicount=%d)", tnode->mvi,flag1); 703 debug(133, "backdrop=%s (mvicount=%d)", tnode->backdrop,flag1); 704 705 if(file_exist(tnode->mvi)) 706 unlink(tnode->backdrop); 707 708 if(mvicount > 0) 709 { 710 free(tnode->mvi); 711 tnode->mvi = ostrcat(oitoa(mvicount), NULL, 1, 0); 712 } 713 else 714 { 715 free(tnode->mvi); 716 tnode->mvi = ostrcat("1", NULL, 0, 0); 717 } 718 debug(133, "change mvi=%s (mvicount=%d)", tnode->mvi,flag1); 719 720 free(tmpstr); tmpstr = NULL; 721 722 debug(133, "----------------------tmdb start----------------------"); 723 debug(133, "title: %s", tnode->title); 724 debug(133, "language: %s", tnode->language); 725 debug(133, "type: %s", tnode->type); 726 debug(133, "orgname: %s", tnode->orgname); 727 debug(133, "score: %s", tnode->score); 728 debug(133, "rating: %s", tnode->rating); 729 debug(133, "released: %s", tnode->released); 730 debug(133, "genre: %s", tnode->genre); 731 debug(133, "runtime: %s", tnode->runtime); 732 debug(133, "plot: %s", tnode->plot); 733 debug(133, "thumb: %s", tnode->thumb); 734 debug(133, "cover: %s", tnode->cover); 735 debug(133, "postermid: %s", tnode->postermid); 736 debug(133, "backdrop: %s", tnode->backdrop); 737 debug(133, "mvi: %s", tnode->mvi); 738 debug(133, "rating: %s", tnode->rating); 739 debug(133, "votes: %s", tnode->votes); 740 debug(133, "id: %s", tnode->id); 741 debug(133, "imdbid: %s", tnode->imdbid); 742 debug(133, "----------------------tmdb end----------------------"); 743 } 744 770 745 return *first; 771 746 }
Note: See TracChangeset
for help on using the changeset viewer.