コード例 #1
0
ファイル: rtsp.c プロジェクト: ElecardSTB/elecard-apps
static void rtsp_urlHandler(void *pArg, const char *location, const char *desc, xmlConfigHandle_t track)
{
	int            *pIndex = (int*)pArg;
	streams_struct *pstream;
	char           *ptr;

	if( location[0] )
	{
		pstream = add_stream(ppstream_head, (char *)location, *pIndex);

		helperSafeStrCpy(&pstream->name, desc);

		if( track && pstream )
		{
			ptr = (char*)xmlConfigGetText(track, "descr");
			if( ptr && *ptr )
			{
				//dprintf("%s: Adding '%s' description to %03d stream\n", __FUNCTION__, ptr, *pIndex);
				helperSafeStrCpy( &pstream->description, ptr );
			}

			ptr = (char*)xmlConfigGetText(track, "thumb");
			if( ptr && *ptr )
			{
				//dprintf("%s: Adding '%s' thumb to %03d stream\n", __FUNCTION__, ptr, *pIndex);
				helperSafeStrCpy( &pstream->thumb, ptr );
			}

			ptr = (char*)xmlConfigGetText(track, "poster");
			if( ptr && *ptr )
			{
				//dprintf("%s: Adding '%s' poster to %03d stream\n", __FUNCTION__, ptr, *pIndex);
				helperSafeStrCpy( &pstream->poster, ptr );
			}
		}

		(*pIndex)++;
	}
}
コード例 #2
0
int youtube_getVideoList(const char *url, youtubeEntryHandler pCallback, int page)
{
	CURLcode ret;
	CURL *hnd;
	char proxy[32];
	char login[512];
	char *str;
	xmlConfigHandle_t list;
	xmlConfigHandle_t item;
	TiXmlNode *entry;
	TiXmlNode *child;
	TiXmlElement *elem;
	const char *video_name, *video_type, *video_url, *thumbnail;
	static char curl_data[YOUTUBE_LIST_BUFFER_SIZE];
	static char err_buff[CURL_ERROR_SIZE];
	static curlBufferInfo_t buffer;
	buffer.data = curl_data;
	buffer.size = sizeof(curl_data);
	buffer.pos  = 0;

	if( url == 0 || pCallback == 0 )
		return -2;

	curl_data[0] = 0;

	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);
		}
	}

	if (page == 1)
	{
		interface_showLoading();
		interface_displayMenu(1);
	}

	ret = curl_easy_perform(hnd);

	dprintf("%s: page %d of '%s' acquired (length %d)\n", __FUNCTION__, page, youtubeInfo.search[0] ? youtubeInfo.search : "standard feeds", buffer.pos);

	curl_easy_cleanup(hnd);

	if (ret != 0)
	{
		eprintf("Youtube: Failed to get video list from '%s': %s\n", url, err_buff);
		if (page == 1) interface_hideLoading();
		return -1;
	}
	list = xmlConfigParse( curl_data );
	if (list == NULL
		|| (item = xmlConfigGetElement(list, "feed", 0)) == NULL)
	{
		if (list)
		{
			eprintf("Youtube: parse error %s\n", ((TiXmlDocument*)list)->ErrorDesc());
			xmlConfigClose(list);
		}
		if (page == 1)interface_hideLoading();
		eprintf("Youtube: Failed to parse video list %d\n", page);
		return -1;
	}
	for ( entry = ((TiXmlNode *)item)->FirstChild(); entry != 0; entry = entry->NextSibling() )
	{
		if (entry->Type() == TiXmlNode::TINYXML_ELEMENT && strcasecmp(entry->Value(), "entry") == 0)
		{
			item = xmlConfigGetElement(entry, "media:group", 0);
			if( item != NULL )
			{
				video_name = (char *)xmlConfigGetText(item, "media:title");
				video_url = NULL;
				thumbnail = NULL;
				for ( child = ((TiXmlNode *)item)->FirstChild();
					child != 0 && (video_url == NULL || thumbnail == NULL);
					child = child->NextSibling() )
				{
					if (child->Type() == TiXmlNode::TINYXML_ELEMENT )
					{
						if(strcasecmp(child->Value(), "media:content") == 0)
						{
							elem = (TiXmlElement *)child;
							video_type = elem->Attribute("type");
							if( strcmp( video_type, "application/x-shockwave-flash" ) == 0)
							{
								video_url = elem->Attribute("url");
							}
						} else if(thumbnail== 0 && strcasecmp(child->Value(), "media:thumbnail") == 0)
						{
							elem = (TiXmlElement *)child;
							thumbnail = elem->Attribute("url");
						}
					}
				}
				if( video_url != NULL )
				{
					//dprintf("%s: Adding Youtube video '%s' url='%s' thumb='%s'\n", __FUNCTION__,video_name,video_url,thumbnail);
					pCallback(video_url,video_name,thumbnail);
				}
			}
		}
	}
	xmlConfigClose(list);
	if (page == 1) interface_hideLoading();
	return ret;
}