コード例 #1
0
static int smil_inputURL(interfaceMenu_t *pMenu, char *value, void* pArg)
{
	CURLcode ret;
	CURL *hnd;
	char data[DATA_BUFF_SIZE];
	char *content_type;
	int code, length;
	char proxy[32];
	char login[512];
	char *login_ptr;
	data[0] = 0;
	errbuff[0] = 0;

	if( value == NULL)
		return 1;

	strcpy( smil_lasturl, value );

	if (strncasecmp(value, URL_HTTP_MEDIA,  sizeof(URL_HTTP_MEDIA)-1) != 0 &&
		strncasecmp(value, URL_HTTPS_MEDIA, sizeof(URL_HTTPS_MEDIA)-1) != 0)
	{
		interface_showMessageBox(_T("ERR_INCORRECT_PROTO"), thumbnail_error, 0);
		return -1;
	}

	hnd = curl_easy_init();

	curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(hnd, CURLOPT_WRITEDATA, data);
	curl_easy_setopt(hnd, CURLOPT_URL, value);
	curl_easy_setopt(hnd, CURLOPT_ERRORBUFFER, errbuff);
	curl_easy_setopt(hnd, CURLOPT_CONNECTTIMEOUT, 5);
	curl_easy_setopt(hnd, CURLOPT_TIMEOUT, 15);
	getParam(BROWSER_CONFIG_FILE, "HTTPProxyServer", "", proxy);
	if( proxy[0] != 0 )
	{
		curl_easy_setopt(hnd, CURLOPT_PROXY, proxy);
		getParam(BROWSER_CONFIG_FILE, "HTTPProxyLogin", "", login);
		if( login[0] != 0 )
		{
			login_ptr = &login[strlen(login)+1];
			getParam(BROWSER_CONFIG_FILE, "HTTPProxyPasswd", "", login_ptr);
			if( *login_ptr != 0 )
			{
				login_ptr[-1] = ':';
			}
			curl_easy_setopt(hnd, CURLOPT_PROXYUSERPWD, login);
		}
	}

	ret = curl_easy_perform(hnd);

	if (ret == 0)
	{
		curl_easy_getinfo(hnd, CURLINFO_RESPONSE_CODE, &code);
		if (code != 200)
		{
			ret = code > 0 ? code : -1;
			interface_showMessageBox(_T("ERR_SERVICE_UNAVAILABLE"), thumbnail_error, 0);
		} else
		{
			length = strlen(data);
			if( CURLE_OK != curl_easy_getinfo(hnd, CURLINFO_CONTENT_TYPE, &content_type) )
			{
				content_type = NULL;
			}
			dprintf("%s: Content-Type: %s\n", __FUNCTION__, content_type);
			//dprintf("%s: streams data %d:\n%s\n\n", __FUNCTION__, length, data);
		}
	}
	else
		eprintf("SMIL: Failed(%d) to get '%s' with message:\n%s\n", ret, value, errbuff);

	if ( ret == 0 )
	{
		if((ret = smil_parseRTMPStreams((const char*)data, smil_rtmpurl, sizeof(smil_rtmpurl))) == 0 )
		{
			dprintf("%s: Playing '%s'\n", __FUNCTION__, smil_rtmpurl);
			media_playURL( screenMain, smil_rtmpurl, NULL, NULL );
		}
		else
		{
			eprintf("SMIL: Failed to parse SMIL at '%s'\n", value);
			interface_showMessageBox(_T("ERR_SERVICE_UNAVAILABLE"), thumbnail_error, 0);
		}
	} else
	{
		eprintf("SMIL: Failed to get SMIL playlist from '%s'\n", value);
		interface_showMessageBox(_T("ERR_SERVICE_UNAVAILABLE"), thumbnail_error, 0);
	}

	curl_easy_cleanup(hnd);

	return ret;
}
コード例 #2
0
static int youtube_streamChange(interfaceMenu_t *pMenu, void *pArg)
{
	CURLcode ret;
	CURL *hnd;
	char proxy[32];
	char login[512];
	char *str;
	static char url[MAX_URL];
	static char url_tmp[MAX_URL];
	static char curl_data[YOUTUBE_INFO_BUFFER_SIZE];
	static char err_buff[CURL_ERROR_SIZE];
	static curlBufferInfo_t buffer;
	char *fmt_url_map;
	//int supported_formats[] = { 18, 17, 34, 5, 0 };
	int supported_formats[] = { 34, 18, 0 };
	/* 37/1920x1080/9/0/115
	   22/1280x720/9/0/115
	   35/854x480/9/0/115
	   34/640x360/9/0/115
	   5/320x240/7/0/0 */
	char *fmt_url;
	int i;
	int len_str;
	int len_url = 0;
	int videoIndex = (int)pArg;

	if( videoIndex == CHANNEL_CUSTOM )
	{
		str = strstr( appControlInfo.mediaInfo.lastFile, "watch?v=" );
		if( str == NULL )
		{
			eprintf("%s: can't file YouTube ID in %s\n", __FUNCTION__, appControlInfo.mediaInfo.lastFile);
			interface_showMessageBox(_T("ERR_PLAY_FILE"), thumbnail_error, 3000);
			return -1;
		}
		str += 8;
		str[sizeof(youtubeInfo.current_id)-1] = 0;
		if( strlen(str) != YOUTUBE_ID_LENGTH-1 )
		{
			eprintf("%s: invalid YouTube ID %s\n", __FUNCTION__, str);
			interface_showMessageBox(_T("ERR_PLAY_FILE"), thumbnail_error, 3000);
			return -1;
		}
		memcpy( youtubeInfo.current_id, str, sizeof(youtubeInfo.current_id) );
	} else if( videoIndex < 0 || videoIndex >= youtubeInfo.count )
	{
		eprintf("%s: there is no stream %d\n", __FUNCTION__, videoIndex);
		interface_showMessageBox(_T("ERR_PLAY_FILE"), thumbnail_error, 3000);
		return -1;
	} else
	{
		memcpy( youtubeInfo.current_id, youtubeInfo.videos[videoIndex].video_id, sizeof(youtubeInfo.current_id) );
	}

	buffer.data = curl_data;
	buffer.size = sizeof(curl_data);
	buffer.pos  = 0;

	curl_data[0] = 0;
	sprintf(url,"http://www.youtube.com/get_video_info?video_id=%s%s",youtubeInfo.current_id, "&eurl=&el=detailpage&ps=default&gl=US&hl=en");
	hnd = curl_easy_init();

	curl_easy_setopt(hnd, CURLOPT_WRITEFUNCTION, write_data);
	curl_easy_setopt(hnd, CURLOPT_WRITEDATA, &buffer);
	curl_easy_setopt(hnd, CURLOPT_URL, url);
	curl_easy_setopt(hnd, CURLOPT_ERRORBUFFER, err_buff);
	curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 2);
	curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYPEER, 0);
	curl_easy_setopt(hnd, CURLOPT_SSL_VERIFYHOST, 1);
	curl_easy_setopt(hnd, CURLOPT_CONNECTTIMEOUT, 15);
	curl_easy_setopt(hnd, CURLOPT_TIMEOUT, 15);
	getParam(BROWSER_CONFIG_FILE, "HTTPProxyServer", "", proxy);
	if( proxy[0] != 0 )
	{
		curl_easy_setopt(hnd, CURLOPT_PROXY, proxy);
		getParam(BROWSER_CONFIG_FILE, "HTTPProxyLogin", "", login);
		if( login[0] != 0 )
		{
			str = &login[strlen(login)+1];
			getParam(BROWSER_CONFIG_FILE, "HTTPProxyPasswd", "", str);
			if( *str != 0 )
			{
				str[-1] = ':';
			}
			curl_easy_setopt(hnd, CURLOPT_PROXYUSERPWD, login);
		}
	}

	ret = curl_easy_perform(hnd);

	eprintf("%s: video info for %s acquired (length %d)\n", __FUNCTION__, youtubeInfo.current_id, buffer.pos);
	eprintf("%s:  YouTube URL %s\n", __FUNCTION__, url);

	curl_easy_cleanup(hnd);

	if (ret != 0)
	{
		eprintf("Youtube: Failed to get video info from '%s': %s\n", url, err_buff);
		interface_showMessageBox(_T("ERR_PLAY_FILE"), thumbnail_error, 3000);
		return 1;
	}
/*
	fmt_url_map = strstr(curl_data, "fmt_list=");
	if( fmt_url_map )
	{
		fmt_url_map += sizeof("fmt_list=")-1;
		for( str = fmt_url_map; *str && *str != '&'; str++ );
		if( *str != '&' )
			str = NULL;
		else
			*str = 0;

		if( utf8_urltomb(fmt_url_map, strlen(fmt_url_map)+1, url, sizeof(url)-1 ) > 0 )
		{
			eprintf("%s: fmt_list='%s'\n", __FUNCTION__, url);
		}
	}
*/
	//fmt_url_map = strstr(curl_data, "fmt_url_map=");
    fmt_url_map = strstr(curl_data, "url_encoded_fmt_stream_map=");
	if( fmt_url_map )
	{
		//fmt_url_map += sizeof("fmt_url_map=")-1;
		fmt_url_map += sizeof("url_encoded_fmt_stream_map=")-1;
		for( str = fmt_url_map; *str && *str != '&'; str++ );
		if( *str != '&' )
			str = NULL;
		else
			*str = 0;

		for( i = 0; supported_formats[i] != 0; i++ )
		{
			//sprintf(proxy, "%d%%7C", supported_formats[i]);
			sprintf(proxy, "itag%%3D%d", supported_formats[i]); // find format tag field
			if( (fmt_url = strstr( fmt_url_map, proxy )) != NULL )
			{
				fmt_url += strlen(proxy) + 9;// skip "%2Curl%3D"
				str = strstr( fmt_url, "%26quality" ); // find end url
				if( str )
					*str = 0;
				eprintf("%s:  URL %s\n", __FUNCTION__, fmt_url);
				if( utf8_urltomb(fmt_url, strlen(fmt_url)+1, url_tmp, sizeof(url_tmp)-1 ) < 0 )
				{
					eprintf("%s: Failed to decode '%s'\n", __FUNCTION__, fmt_url);
				} else
				{
					if( utf8_urltomb(url_tmp, strlen(url_tmp)+1, url, sizeof(url)-1 ) < 0 )
					{
						eprintf("%s: Failed to decode '%s'\n", __FUNCTION__, url_tmp);
					} else {
						eprintf("%s: selected format %d\n", __FUNCTION__, supported_formats[i]);
						break;
					}
				}
			}
		}
		if( supported_formats[i] == 0 )
		{
			interface_showMessageBox(_T("ERR_STREAM_NOT_SUPPORTED"), thumbnail_warning, 0);
			return 1;
		}
	}

	eprintf("Youtube: Playing '%s'\n", url);

	char *descr     = NULL;
	char *thumbnail = NULL;
	if( videoIndex != CHANNEL_CUSTOM )
	{
		youtubeInfo.index = videoIndex;
		if( interface_getMenuEntryInfo( (interfaceMenu_t*)&YoutubeMenu, videoIndex+1, login, sizeof(login) ) == 0 )
			descr = login;
		thumbnail = youtubeInfo.videos[videoIndex].thumbnail[0] ? youtubeInfo.videos[videoIndex].thumbnail : NULL;
		appControlInfo.playbackInfo.channel = videoIndex+1;
		appControlInfo.playbackInfo.playlistMode = playlistModeYoutube;
	} else
	{
		youtubeInfo.index = 0;
		descr     = appControlInfo.playbackInfo.description;
		thumbnail = appControlInfo.playbackInfo.thumbnail;
	}
	appControlInfo.playbackInfo.streamSource = streamSourceYoutube;
	media_playURL(screenMain, url, descr, thumbnail != NULL ? thumbnail : resource_thumbnails[thumbnail_youtube] );

	return 0;
}