--- yougrabber-0.29.4.old/src/download.c +++ yougrabber-0.29.4/src/download.c @@ -21,11 +21,12 @@ * along with this program. If not, see . */ +#include #include "include/common.h" static const char __FILE_TEMP[] = {"VIDEODATA"}; static const char __EXT_TEMP[] = {"part"}; -static const char __EXT_VIDEO[] = {"flv"}; +static const char __EXT_VIDEO[] = {"mp4"}; /* match strings and delimiters */ static const char __FLAGGED_URL_MATCH[] = {"verify_age?"}; @@ -35,13 +36,13 @@ static const char __VIDEO_ID_DELIM_1[] = {"?v="}; static const char __VIDEO_ID_DELIM_2[] = {""}; -static const char __TITLE_MATCH[] = {""}; - -static const char __URL_T_MATCH[] = {"swfArgs"}; -static const char __URL_T_DELIM_1[] = {"t\": \""}; -static const char __URL_T_DELIM_2[] = {"\","}; +static const char __TITLE_MATCH[] = { "" }; +static const char __TITLE_DELIM_1[] = { "<title>" }; +static const char __TITLE_DELIM_2[] = { "" }; + +static const char __URL_T_MATCH[] = { "&t=" }; +static const char __URL_T_DELIM_1[] = { "&t=" }; +static const char __URL_T_DELIM_2[] = { "&" }; static const char __YOUTUBE_URL_VIDEO[] = {"http://www.youtube.com/get_video?video_id="}; @@ -107,7 +108,14 @@ { unsigned short int got_title = 0; unsigned short int got_url = 0; - char buf[256]; + +#define YTBUFSIZE 512000 +#define MAXBUFIDX (YTBUFSIZE-2) + + static char buf [YTBUFSIZE]; + int c; + char *cp; + int ii; /* wait for the login result */ while (yg_config_login_status(d_ptr->c_ptr) == YG_LOGIN_OK_CONNECTING) @@ -152,41 +160,69 @@ fflush(d_ptr->stream); rewind(d_ptr->stream); - while (fgets(buf, sizeof(buf), d_ptr->stream) || (!got_title && !got_url) - || !strstr(buf, __ERROR_MATCH)) - { - if (feof(d_ptr->stream)) - break; + memset (buf, 0, (size_t) sizeof (buf)); - /* video title */ - if (strstr(buf, __TITLE_MATCH)) + for (ii = 0; + (ii <= MAXBUFIDX) && ((c = getc (d_ptr->stream)) != EOF); + ii++) { - char *title = NULL; - - title = yg_strcut(buf, __TITLE_DELIM_1, __TITLE_DELIM_2); + buf [ii] = c; + } - free(d_ptr->video.title); - d_ptr->video.title = yg_utf2locale(title); + /* video title */ + if (strstr (buf, __TITLE_MATCH)) + { + char *title = NULL; + title = yg_strcut (buf, __TITLE_DELIM_1, __TITLE_DELIM_2); + free (d_ptr->video.title); + d_ptr->video.title = yg_utf2locale (title); + free (title); + + for (cp = d_ptr->video.title; *cp; cp++) + { + c = 0xFF & *cp; + + if (((c < 'a') || (c > 'z')) && + ((c < 'A') || (c > 'Z')) && + ((c < '0') || (c > '9')) && + (c != '_') && (c != '-')) + { + *cp = '_'; + } + } + + while ((cp = strstr (d_ptr->video.title, "__")) != NULL) + { + strcpy (cp, cp+1); + } + + cp = d_ptr->video.title; + while (*cp == '_') strcpy (cp, cp+1); + + while (((ii = strlen (cp)-1) >= 0) && + (cp [ii] == '_')) + { + cp [ii] = '\0'; + } - free(title); - got_title = 1; + if (!*cp) strcpy (cp, '_'); + got_title = 1; } /* URL "t" parameter */ - if (strstr(buf, __URL_T_MATCH)) + if (strstr (buf, __URL_T_MATCH)) { - char *t = NULL; - - t = yg_strcut(buf, __URL_T_DELIM_1, __URL_T_DELIM_2); - - free(d_ptr->video.url); - d_ptr->video.url = g_strdup_printf("%s%s&t=%s", __YOUTUBE_URL_VIDEO, - d_ptr->video.id, t); - - free(t); - got_url = 1; + char *t = NULL; + t = yg_strcut (buf, __URL_T_DELIM_1, __URL_T_DELIM_2); + free (d_ptr->video.url); + d_ptr->video.url = g_strdup_printf ("%s%s&t=%s&fmt=18", + __YOUTUBE_URL_VIDEO, + d_ptr->video.id, t); + free (t); + got_url = 1; } - } + + if (strstr (buf, __ERROR_MATCH)) got_title = got_url = 0; /* download phase 3 */ if (got_title && got_url) --- yougrabber-0.29.4.old/src/main.c +++ yougrabber-0.29.4/src/main.c @@ -35,7 +35,7 @@ if (argc < 2) { - yg_print("Usage: yg [URL]..."); + yg_print ("Usage: yougrabber URL ..."); return EXIT_SUCCESS; }