mercredi 24 décembre 2014

Infer "Device Class" (Mobile, Touch, Desktop, etc) from User Agent String

Are there any tools which will infer "device class" information from User Agent strings?


This tool should have something like the following behavior:


For iPads:



getDeviceClass('Mozilla/5.0 ;iPad; CPU OS 8_1_1 like Mac OS X; AppleWebKit/600.1.4 ;KHTML, like Gecko; Version/8.0 Mobile/12B435 Safari/600.1.4')


Returns:



{ "deviceClass":"tablet",
"interface":"touch" }


Note that the behavior I'm describing is subtly different from 'normal' user agent parsing tools like BrowserScope's user agent parser). Which parse device specifics, e.g.,



{'device': {'family': 'iPhone'},
'os': {... 'family': u'iOS', },
'user_agent': {... 'family': u'Mobile Safari', }


The device class would be inferred from some combination of information about the device, os and user_agent.




Hopefully this is written in Python or JavaScript




More examples of desired behavior


For iPhones...



getDeviceType('Mozilla/5.0 ;iPhone; CPU iPhone OS 7_1_1 like Mac OS X; AppleWebKit/537.51.2 ;KHTML, like Gecko; Version/7.0 Mobile/11D201 Safari/9537.53')


Returns...



{ "deviceType":"phone",
"interface":"touch" }


Windows PC...



getDeviceType('Mozilla/5.0 ;Macintosh; Intel Mac OS X 10_10_1; AppleWebKit/537.36 ;KHTML, like Gecko; Chrome/39.0.2171.95 Safari/537.36')


Returns...



{ "deviceType":"pc",
"interface":"other" }




Aucun commentaire:

Enregistrer un commentaire