[MPlayer-dev-eng] [wigren at home.se: [PATCH] Selectable User-Agent for HTTP transfers]

Dave Lambley mplayer-dev-eng at dlambley.freeserve.co.uk
Wed Oct 15 19:34:10 CEST 2003


On Wed, 2003-10-15 at 17:54, Diego Biurrun wrote:
> Dave Lambley writes:
>  > This patch detects the EOF condition SN creates, and make MPlayer retry
>  > with an iTunes UA string automatically.
> 
> Please also include a patch for the man page if you add an option to
> MPlayer.
> 
>  > +	/* XXX we don't distinquish between read fail and EOF. */
> 
> nit: s/distinQuish/distinGuish/

Okay, try this.

Dave

-------------- next part --------------
? 5doct.ogg
? auto-ua.diff
? cap1
? cap2
? cap3
? ffmpeg
? foo.mpg
? mplayer.core
? pipe.wav
? race_bb.ram
? slammer2.wmv
? smil.patch
? smildemohurl.ram
? smilparser.cpp
? smilparser.h
? ua.diff
? ~configure
Index: cfg-common.h
===================================================================
RCS file: /cvsroot/mplayer/main/cfg-common.h,v
retrieving revision 1.113
diff -u -r1.113 cfg-common.h
--- cfg-common.h	14 Oct 2003 10:15:35 -0000	1.113
+++ cfg-common.h	15 Oct 2003 17:33:26 -0000
@@ -44,6 +44,7 @@
 	
 	{"prefer-ipv4", &network_prefer_ipv4, CONF_TYPE_FLAG, 0, 0, 1, NULL},	
 	{"ipv4-only-proxy", &network_ipv4_only_proxy, CONF_TYPE_FLAG, 0, 0, 1, NULL},	
+	{"user-agent", &network_useragent, CONF_TYPE_STRING, 0, 0, 0, NULL},
 
 #ifdef HAVE_AF_INET6
 	{"prefer-ipv6", &network_prefer_ipv4, CONF_TYPE_FLAG, 0, 1, 0, NULL},
@@ -270,6 +271,7 @@
 extern char *network_username;
 extern char *network_password;
 extern int   network_bandwidth;
+extern char *network_useragent;
 
 extern int network_prefer_ipv4;
 extern int network_ipv4_only_proxy;
Index: DOCS/en/mplayer.1
===================================================================
RCS file: /cvsroot/mplayer/main/DOCS/en/mplayer.1,v
retrieving revision 1.451
diff -u -r1.451 mplayer.1
--- DOCS/en/mplayer.1	14 Oct 2003 13:55:25 -0000	1.451
+++ DOCS/en/mplayer.1	15 Oct 2003 17:33:30 -0000
@@ -1348,6 +1348,9 @@
 .B \-unicode
 Tells MPlayer to handle the subtitle file as UNICODE.
 .TP
+.B \-user-agent <string>
+Tells MPlayer to give <string> as the user agent when making HTTP requests.
+.TP
 .B \-utf8 \ \ 
 Tells MPlayer to handle the subtitle file as UTF8.
 .TP
Index: libmpdemux/network.c
===================================================================
RCS file: /cvsroot/mplayer/main/libmpdemux/network.c,v
retrieving revision 1.85
diff -u -r1.85 network.c
--- libmpdemux/network.c	15 Aug 2003 19:13:23 -0000	1.85
+++ libmpdemux/network.c	15 Oct 2003 17:33:33 -0000
@@ -47,10 +47,12 @@
 int asf_streaming_start( stream_t *stream, int *demuxer_type );
 int rtsp_streaming_start( stream_t *stream );
 
-/* Variables for the command line option -user, -passwd & -bandwidth */
+/* Variables for the command line options -user, -passwd, -bandwidth 
+   and -user-agent */
 char *network_username=NULL;
 char *network_password=NULL;
 int   network_bandwidth=0;
+char *network_useragent="MPlayer/"VERSION;
 
 /* IPv6 options */
 int   network_prefer_ipv4 = 0;
@@ -443,7 +445,8 @@
 	}
 	snprintf(str, 80, "Host: %s", server_url->hostname );
 	http_set_field( http_hdr, str);
-	http_set_field( http_hdr, "User-Agent: MPlayer/"VERSION);
+	snprintf(str, 80, "User-Agent: %s", network_useragent );
+	http_set_field( http_hdr, str);
 	http_set_field( http_hdr, "Connection: closed");
 	http_add_basic_authentication( http_hdr, url->username, url->password );
 	if( http_build_request( http_hdr )==NULL ) {
@@ -570,7 +573,7 @@
 	char *extension;
 	char *content_type;
 	char *next_url;
-
+	int tried_ua_hack = 0;
 	URL_t *url = streaming_ctrl->url;
 	*file_format = DEMUXER_TYPE_UNKNOWN;
 
@@ -690,9 +693,19 @@
 
 			http_hdr = http_read_response( fd );
 			if( http_hdr==NULL ) {
-				closesocket( fd );
-				http_free( http_hdr );
-				return -1;
+				/* XXX we don't distinguish between read fail and EOF. */
+				if (!tried_ua_hack) {
+					closesocket( fd );
+					redirect = 1;
+					network_useragent = "iTunes/4.0 (Macintosh; N; PPC)";
+					tried_ua_hack = 1;
+					mp_msg(MSGT_NETWORK, MSGL_INFO, "Trying UA string: %s\n", network_useragent);
+					continue;
+				} else {
+					closesocket( fd );
+					http_free( http_hdr );
+					return -1;
+				}
 			}
 
 			*fd_out=fd;


More information about the MPlayer-dev-eng mailing list