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

Dave Lambley mplayer-dev-eng at dlambley.freeserve.co.uk
Thu Oct 16 01:12:14 CEST 2003


On Wed, 2003-10-15 at 23:03, Diego Biurrun wrote:
> OSD/SUB OPTIONS is the wrong section, put it in DEMUXER/STREAM OPTIONS
> instead.

This patch contains Per Wigren's text instead, in the right place
hopefully.

> Hmm, what about the version that Per Wigren (IIRC) sent?  It also
> implemented -user-agent..  What are the differences, which one is
> better?

Mine :). My patch is Per Wigren's, with the addition of some code to
detect the user agent screening Surfer Network does, and make it try
again claiming to be iTunes.

On Wed, 2003-10-15 at 22:29, Dominik 'Rathann' Mierzejewski wrote:
> IMHO it should retry automatically with predefined UA string only if
> there's no user-specified UA string. And it's still a hack, meaning
> there's no nice way to add more predefined strings to retry with. Just my
> 0.03 eurocents. Don't take me too seriously. :)

IMHO a smaller hack is better than a bigger hack!

Cheers,
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
? t.ps
? 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 22:26:07 -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 22:26:08 -0000
@@ -1038,6 +1038,9 @@
 .B \-user <user name> (see \-passwd option too)
 Specify user name for http authentication.
 .TP
+.B \-user-agent <string>
+Tells MPlayer to give <string> as the user agent when making HTTP requests.
+.TP
 .B \-vid <id>
 Select video channel [MPG: 0\-15 ASF: 0\-255 MPEG-TS: 17\-8190].
 When playing an MPEG-TS stream, MPlayer/Mencoder will use the first program 
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 22:26:09 -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