[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 15:24:56 CEST 2003


On Wed, 2003-10-15 at 10:37, Dominik 'Rathann' Mierzejewski wrote:
> I also propose to have a few predefined UAs to make life easier for people
> who don't understand this concept and don't really need to - they can be
> told to try this and this and if it doesn't help, _then_ worry, because
> most often, one of these will work: RealPlayer (or RealOne),
> MSIE/Mozilla/Opera and the aforementioned iTunes. Does WMP have its own
> UA string, too?

This patch detects the EOF condition SN creates, and make MPlayer retry
with an iTunes UA string automatically.

Do other sites have access control like SN? Perhaps we could include
some spyware in MPlayer to automatically report URLs it can't play.

Cheers,
Dave

-------------- next part --------------
? 5doct.ogg
? cap1
? cap2
? cap3
? ffmpeg
? foo.mpg
? mplayer.core
? patch
? 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 13:12:33 -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: 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 13:12:36 -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 distinquish 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