0

I stream tweets in my wp8 app, using TweetSharp. I want to detect the content in each tweet. With photos it's simple, using TwitterStatus.Entities.Media its a collection of images. Harder with video, links to videos are in TwitterStatus.Entities.Urls (such as youtube.com or youtu.be, etc) with simple links to another sites. Official android Twitter app detects content type and show an icon forech type(link, video, photo). I tried to get this info just from JSON, but in JSON videolinks also are in urls, not in media. But android app knows how to detect content, so it can be make.

In complete solution I need just a enum field ContentType in MyTwitterMessage with Photo, Video, Link or Nothing

Dima Serdechnyi
  • 707
  • 2
  • 10
  • 19

1 Answers1

0

A couple of ways I could think of is

a) Just use known file extensions and check if the extension which type it is and return (assuming all URLs will provide a file extension).

b) Fire off a download using the URL but only retrieving the headers

 WebClient aClient = new WebClient();
 WebHeaderCollection collection = new WebHeaderCollection();
 collection[HttpRequestHeader.Range] = "bytes=0-0";
 aClient.Headers = collection; 
 aClient.DownloadStringAsync(new Uri("URI GOES HERE"));

Then in the DownloadStringCompleted event parse the headers and retrieve content-type

 var aClient = (Webclient)sender;
 var responseHeaders = client.ResponseHeaders;
 var TypeOfContent = responseHeaders["Content-Type"];

You should then be able to determine the content from there, MIME types can be found here

For b) You might also need to handle redirects, but that's another question.

David Gordon
  • 554
  • 2
  • 8