If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Joey Addon: find media (video, audio) files by examining HTTP requests

RESOLVED FIXED

Status

Mozilla Labs
Joey
--
enhancement
RESOLVED FIXED
11 years ago
11 years ago

People

(Reporter: Paweł Knapik, Assigned: dougt)

Tracking

Details

Attachments

(1 attachment, 1 obsolete attachment)

(Reporter)

Description

11 years ago
User-Agent:       Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20061201 Firefox/2.0.0.3 (Ubuntu-feisty)
Build Identifier: Joey Addon : sniffing media files

Joey uses site-specific "hacks" to detect media content files' URIs.
My suggestion is to add a kind of sniffer that examines every request on a page and determines if it is media file by http headers or file extension.

Here's a piece of code that worked well with youtube, last.fm and a few other sites:

var g_joey_mediaContentTypes = ['flv','mov','wmv','avi','mpeg','mp3','wav'];

var httpscanner = {
  observe: function(subject,topic,data){
  	var response=subject.QueryInterface(Components.interfaces.nsIHttpChannel);
    var contentType=response.getResponseHeader('Content-Type');  	
 	
 	function testContentType(types){
 		var isMediaFile = false;
 		for(var i=types.length;i>=0;i--){
			if(contentType.indexOf(types[i])>-1 || mediaLocation.indexOf('.'+types[i])>-1) isMediaFile = true;
		}
		return isMediaFile;
	}
 	
   	if(contentType.indexOf('video')>-1 || contentType.indexOf('audio')>-1 || contentType.indexOf('octet')>-1){
   		var mediaLocation=subject.QueryInterface(Components.interfaces.nsIChannel).URI;
   			mediaLocation=mediaLocation.prePath+mediaLocation.path;
   			
   		if(testContentType(g_joey_mediaContentTypes)){
   			joeyDumpToConsole("media content found: "+ mediaLocation);
   			g_joey_media_url = mediaLocation;
   		}
   	}
  }
}

var observerService =
     Components.classes["@mozilla.org/observer-service;1"]
       .getService(Components.interfaces.nsIObserverService);
observerService.addObserver(httpscanner,"http-on-examine-response",false);

Reproducible: Always
(Reporter)

Updated

11 years ago
Summary: find media (video, audio) files by examining HTTP requests → Joey Addon: find media (video, audio) files by examining HTTP requests
(Assignee)

Comment 1

11 years ago
this is great stuff.

can you get a patch together for the joey addon?
(Reporter)

Comment 2

11 years ago
Created attachment 265955 [details] [diff] [review]
http sniffer code - media file detection
(Assignee)

Comment 3

11 years ago
hi pawel, i applied this patch, and thing just didn't wokr -- going to youtube didn't add a menu item in the joey button at the bottom of the browser.  should it?
(Reporter)

Comment 4

11 years ago
Created attachment 266202 [details] [diff] [review]
http sniffer - media detection

hey Doug, there's an updated patch - now the "Joey! media on page" button shows up when media file is found.
Attachment #265955 - Attachment is obsolete: true
(Assignee)

Comment 5

11 years ago
this is great.  I think we are going to have to figure out sites that lie about their content type (for example, myspace videos seam to be broken).

Thanks pawel.

r4133

Status: NEW → RESOLVED
Last Resolved: 11 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.