python-user-agents icon indicating copy to clipboard operation
python-user-agents copied to clipboard

Improvements for User Agent recognition

Open alexgarciab opened this issue 7 years ago • 1 comments

Here are some improvements I would recommend to apply. Please, also deploy the changes to the Django package.

These type of User Agents are not being recognized as "tablet":

Mozilla/5.0 (iPad; CPU OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E304 [FBAN/FBIOS;FBAV/89.0.0.52.71;FBBV/55613772;FBDV/iPad5,4;FBMD/iPad;FBSN/iOS;FBSV/10.3.1;FBSS/2;FBCR/movistar;FBID/tablet;FBLC/es_ES;FBOP/5;FBRV/0]

These type of User Agents are not being recognized as "PC":

Mozilla/5.0 (X11; CrOS x86_64 9202.66.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.148 Safari/537.36

These types of User Agents are not being recognized as "mobile":

Mozilla/5.0 (iPod touch; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Mobile/14D27 [FBAN/FBIOS;FBAV/89.0.0.52.71;FBBV/55613772;FBDV/iPod7,1;FBMD/iPod touch;FBSN/iOS;FBSV/10.2.1;FBSS/2;FBCR/;FBID/phone;FBLC/es_LA;FBOP/5;FBRV/56133369]

Mozilla/5.0 (Mobile; ALCATELOneTouch4019A; rv:28.0) Gecko/28.0 Firefox/28.0

It should be great to add the "is_smart_tv" feature for these type of User Agents:

Mozilla/5.0 (SMART-TV; Linux; Tizen 2.4.0) AppleWebkit/538.1 (KHTML, like Gecko) SamsungBrowser/1.1 TV Safari/538.1

alexgarciab avatar Apr 30 '17 15:04 alexgarciab

>>> ua = 'Mozilla/5.0 (iPad; CPU OS 10_3_1 like Mac OS X) AppleWebKit/603.1.30 (KHTML, like Gecko) Mobile/14E304 [FBAN/FBIOS;FBAV/89.0.0.52.71;FBBV/55613772;FBDV/iPad5,4;FBMD/iPad;FBSN/iOS;FBSV/10.3.1;FBSS/2;FBCR/movistar;FBID/tablet;FBLC/es_ES;FBOP/5;FBRV/0]'
>>> user_agent = parse(ua)
>>> user_agent.is_tablet
True
>>> ua = 'Mozilla/5.0 (X11; CrOS x86_64 9202.66.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.148 Safari/537.36'
>>> user_agent = parse(ua)
>>> user_agent.is_pc
True
>>> ua = 'Mozilla/5.0 (iPod touch; CPU iPhone OS 10_2_1 like Mac OS X) AppleWebKit/602.4.6 (KHTML, like Gecko) Mobile/14D27 [FBAN/FBIOS;FBAV/89.0.0.52.71;FBBV/55613772;FBDV/iPod7,1;FBMD/iPod touch;FBSN/iOS;FBSV/10.2.1;FBSS/2;FBCR/;FBID/phone;FBLC/es_LA;FBOP/5;FBRV/56133369]'
>>> user_agent = parse(ua)
>>> user_agent.is_mobile
True
>>> ua = 'Mozilla/5.0 (Mobile; ALCATELOneTouch4019A; rv:28.0) Gecko/28.0 Firefox/28.0'
>>> user_agent = parse(ua)
>>> user_agent.is_mobile
True

for is_smart_v you can use

>>> ua = 'Mozilla/5.0 (SMART-TV; Linux; Tizen 2.4.0) AppleWebkit/538.1 (KHTML, like Gecko) SamsungBrowser/1.1 TV Safari/538.1'
>>> user_agent = parse(ua)
>>> user_agent.device.model
'SMART-TV'

for your case, there is no clear standard for smart tv, so it is not easy to implement a is_smart_tv for now

jnozsc avatar Feb 08 '20 04:02 jnozsc