useragent 0.12.0 → 0.13.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 70923abee7e8ba999ee2cd327e6eda2af9f0d721
4
- data.tar.gz: caeb5dea87e448b5d41d0d3946d1e6bb95e42cf7
3
+ metadata.gz: 51aa24d6a524743862c56ab432b88b4e3cf47de9
4
+ data.tar.gz: de584ebbb72e57c6d7e2754b576bf395551a7eb5
5
5
  SHA512:
6
- metadata.gz: 5acfcce5871ad92a637be4d463ca721c4688db4c873eaa8afb5f2bb8526fb22ceed31274a332fd6908310d537d2a2cfda30c3b23662b5562dd086b2ec8934481
7
- data.tar.gz: c6e856cff6f0b873bcc95bf78925a950500f3509e1c2c3303b1a88f894f1f0cdf7a831e48f622b5334e2a0f236851fd60af53768fa9b67481ec9391c30aeec91
6
+ metadata.gz: deb3a0828a300e60e5a440e15922da7c18f4219b55fb23dbf516ce1dd7e2f695f4f4d2a7cdb061da3ba157e0706133789c9d77cb46d91985267014889ecb6734
7
+ data.tar.gz: 741f86b6dfa3d46ceaf09c5fc5ae4e0d3c1d0f55d385c4730f3bbb8b0467cc1a5e85443e86eb1fb0b567189041adda2c4e9b6a048f9ac9bc95145c8fd09da183
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # UserAgent
2
2
 
3
3
  [![Build Status](https://travis-ci.org/gshutler/useragent.svg?branch=master)](https://travis-ci.org/gshutler/useragent)
4
+ [![Gem Version](https://badge.fury.io/rb/useragent.svg)](http://badge.fury.io/rb/useragent)
4
5
 
5
6
  UserAgent is a Ruby library that parses and compares HTTP User Agents.
6
7
 
@@ -4,6 +4,10 @@ require 'user_agent/browsers/gecko'
4
4
  require 'user_agent/browsers/internet_explorer'
5
5
  require 'user_agent/browsers/opera'
6
6
  require 'user_agent/browsers/webkit'
7
+ require 'user_agent/browsers/windows_media_player'
8
+ require 'user_agent/browsers/itunes'
9
+ require 'user_agent/browsers/apple_core_media'
10
+ require 'user_agent/browsers/libavformat'
7
11
 
8
12
  class UserAgent
9
13
  module Browsers
@@ -14,7 +18,7 @@ class UserAgent
14
18
  }.freeze
15
19
 
16
20
  def self.all
17
- [InternetExplorer, Opera, Chrome, Webkit, Gecko]
21
+ [InternetExplorer, Opera, Chrome, ITunes, Webkit, Gecko, WindowsMediaPlayer, AppleCoreMedia, Libavformat]
18
22
  end
19
23
 
20
24
  def self.extend(array)
@@ -0,0 +1,56 @@
1
+ class UserAgent
2
+ module Browsers
3
+ # CoreMedia is a framework on iOS and is used by various iOS apps to playback media.
4
+ class AppleCoreMedia < Base
5
+ def self.extend?(agent)
6
+ agent.detect { |useragent| useragent.product == 'AppleCoreMedia' }
7
+ end
8
+
9
+ def browser
10
+ "AppleCoreMedia"
11
+ end
12
+
13
+ def application
14
+ self.reject { |agent| agent.comment.nil? || agent.comment.empty? }.first
15
+ end
16
+
17
+ def platform
18
+ if application.nil?
19
+ nil
20
+ elsif application.comment[0] =~ /Windows/
21
+ 'Windows'
22
+ else
23
+ application.comment[0]
24
+ end
25
+ end
26
+
27
+ def security
28
+ Security[application.comment[1]]
29
+ end
30
+
31
+ def os
32
+ if application
33
+ if application.comment[0] =~ /Windows NT/
34
+ OperatingSystems.normalize_os(application.comment[0])
35
+ elsif application.comment[2].nil?
36
+ OperatingSystems.normalize_os(application.comment[1])
37
+ elsif application.comment[1] =~ /Android/
38
+ OperatingSystems.normalize_os(application.comment[1])
39
+ else
40
+ OperatingSystems.normalize_os(application.comment[2])
41
+ end
42
+ else
43
+ nil
44
+ end
45
+ end
46
+
47
+ def localization
48
+ if application.nil?
49
+ nil
50
+ else
51
+ application.comment[3]
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -44,7 +44,7 @@ class UserAgent
44
44
  nil
45
45
  end
46
46
 
47
- def respond_to?(symbol)
47
+ def respond_to?(symbol, include_all = false)
48
48
  detect_product(symbol) ? true : super
49
49
  end
50
50
 
@@ -0,0 +1,77 @@
1
+ class UserAgent
2
+ module Browsers
3
+ # The user agent for iTunes
4
+ #
5
+ # Some user agents:
6
+ # iTunes/10.6.1 (Macintosh; Intel Mac OS X 10.7.3) AppleWebKit/534.53.11
7
+ # iTunes/12.0.1 (Macintosh; OS X 10.10) AppleWebKit/0600.1.25
8
+ # iTunes/11.1.5 (Windows; Microsoft Windows 7 x64 Business Edition Service Pack 1 (Build 7601)) AppleWebKit/537.60.15
9
+ # iTunes/12.0.1 (Windows; Microsoft Windows 8 x64 Home Premium Edition (Build 9200)) AppleWebKit/7600.1017.0.24
10
+ # iTunes/12.0.1 (Macintosh; OS X 10.10.1) AppleWebKit/0600.1.25
11
+ class ITunes < Webkit
12
+ def self.extend?(agent)
13
+ agent.detect { |useragent| useragent.product == "iTunes" }
14
+ end
15
+
16
+ # @return ["iTunes"] Always return iTunes as the browser
17
+ def browser
18
+ "iTunes"
19
+ end
20
+
21
+ # @return [Version] The version of iTunes in use
22
+ def version
23
+ self.iTunes.version
24
+ end
25
+
26
+ # @return [nil] nil - not included in the user agent
27
+ def security
28
+ nil
29
+ end
30
+
31
+ # @return [nil, Version] The WebKit version in use if we have it
32
+ def build
33
+ webkit ? super : nil
34
+ end
35
+
36
+ # Parses the operating system in use.
37
+ #
38
+ # @return [String] The operating system
39
+ def os
40
+ full_os = self.full_os
41
+
42
+ if application && application.comment[0] =~ /Windows/
43
+ if full_os =~ /Windows 8\.1/
44
+ "Windows 8.1"
45
+ elsif full_os =~ /Windows 8/
46
+ "Windows 8"
47
+ elsif full_os =~ /Windows 7/
48
+ "Windows 7"
49
+ elsif full_os =~ /Windows Vista/
50
+ "Windows Vista"
51
+ elsif full_os =~ /Windows XP/
52
+ "Windows XP"
53
+ else
54
+ "Windows"
55
+ end
56
+ else
57
+ super
58
+ end
59
+ end
60
+
61
+ # Parses the operating system in use.
62
+ #
63
+ # @return [String] The operating system
64
+ def full_os
65
+ if application && application.comment && application.comment.length > 1
66
+ full_os = application.comment[1]
67
+
68
+ full_os = "#{full_os})" if full_os =~ /\(Build [0-9][0-9][0-9][0-9]\z/ # The regex chops the ) off :(
69
+
70
+ full_os
71
+ else
72
+ nil
73
+ end
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,36 @@
1
+ class UserAgent
2
+ module Browsers
3
+ # The user agent utilized by ffmpeg or other projects utilizing libavformat
4
+ class Libavformat < Base
5
+ def self.extend?(agent)
6
+ agent.detect do |useragent|
7
+ useragent.product == "Lavf" || (useragent.product == "NSPlayer" && agent.version == "4.1.0.3856")
8
+ end
9
+ end
10
+
11
+ # @return ["libavformat"] To make it easy to pick it out, all of the UAs that Lavf uses have this browser.
12
+ def browser
13
+ "libavformat"
14
+ end
15
+
16
+ # @return [nil, Version] If the product is NSPlayer, we don't have a version
17
+ def version
18
+ if detect_product("NSPlayer")
19
+ nil
20
+ else
21
+ super
22
+ end
23
+ end
24
+
25
+ # @return [nil] Lavf doesn't return us anything here
26
+ def os
27
+ nil
28
+ end
29
+
30
+ # @return [nil] Lavf doesn't return us anything here
31
+ def platform
32
+ nil
33
+ end
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,177 @@
1
+ class UserAgent
2
+ module Browsers
3
+ # The user agent used by Windows Media Player or applications which utilize the
4
+ # Windows Media SDK.
5
+ #
6
+ # @note Both VLC and libavformat impersonate Windows Media Player when they think they
7
+ # are using MMS (Microsoft Media Services/Windows Media Server).
8
+ class WindowsMediaPlayer < Base
9
+ def self.extend?(agent)
10
+ agent.detect do |useragent|
11
+ (useragent.product == "NSPlayer" || useragent.product == "Windows-Media-Player" || useragent.product == "WMFSDK") &&
12
+ agent.version != "4.1.0.3856" && # 4.1.0.3856 is libavformat
13
+ agent.version != "7.10.0.3059" && # used by VLC for mmsh support
14
+ agent.version != "7.0.0.1956" # used by VLC for mmstu support
15
+ end
16
+ end
17
+
18
+ # The Windows Media Format SDK version
19
+ #
20
+ # @return [Version, nil] The WMFSDK version
21
+ def wmfsdk_version
22
+ (respond_to?("WMFSDK") && self.send("WMFSDK").version) || nil
23
+ end
24
+
25
+ # Check if the client supports the WMFSDK version passed in.
26
+ #
27
+ # @param [String] version
28
+ # The WMFSDK version to check for. For example, "9.0", "11.0", "12.0"
29
+ # @return [true, false] Is this media player compatible with the passed WMFSDK version?
30
+ def has_wmfsdk?(version)
31
+ if wmfsdk_version && wmfsdk_version.to_s =~ /\A#{version}/
32
+ return true
33
+ else
34
+ return false
35
+ end
36
+ end
37
+
38
+ # @return ["Windows Media Player"] All of the user agents we parse are Windows Media Player
39
+ def browser
40
+ "Windows Media Player"
41
+ end
42
+
43
+ # @return ["Windows"] All of the user agents we parse are on Windows
44
+ def platform
45
+ "Windows"
46
+ end
47
+
48
+ # @return [true, false] Is this Windows Media Player 6.4 (NSPlayer 4.1) or Media Player 6.0 (NSPlayer 3.2)?
49
+ def classic?
50
+ version.to_a[0] <= 4
51
+ end
52
+
53
+ # Check if our parsed OS is a mobile OS
54
+ #
55
+ # @return [true, false] Is this a mobile Windows Media Player?
56
+ def mobile?
57
+ ["Windows Phone 8", "Windows Phone 8.1"].include?(os)
58
+ end
59
+
60
+ # Parses the Windows Media Player version to figure out the host OS version
61
+ #
62
+ # User agents I have personally found:
63
+ #
64
+ # Windows 95 with Windows Media Player 6.4::
65
+ # NSPlayer/4.1.0.3857
66
+ #
67
+ # Windows 98 SE with Windows Media Player 6.01::
68
+ # NSPlayer/3.2.0.3564
69
+ #
70
+ # Womdpws 98 SE with Windows Media Player 6.4::
71
+ # NSPlayer/4.1.0.3857
72
+ # NSPlayer/4.1.0.3925
73
+ #
74
+ # Windows 98 SE with Windows Media Player 7.1::
75
+ # NSPlayer/7.1.0.3055
76
+ #
77
+ # Windows 98 SE with Windows Media Player 9.0::
78
+ # Windows-Media-Player/9.00.00.2980
79
+ # NSPlayer/9.0.0.2980 WMFSDK/9.0
80
+ #
81
+ # Windows 2000 with Windows Media Player 6.4::
82
+ # NSPlayer/4.1.0.3938
83
+ #
84
+ # Windows 2000 with Windows Media Player 7.1 (downgraded from WMP9)::
85
+ # NSPlayer/9.0.0.3268
86
+ # NSPlayer/9.0.0.3268 WMFSDK/9.0
87
+ # NSPlayer/9.0.0.3270 WMFSDK/9.0
88
+ # NSPlayer/9.0.0.2980
89
+ #
90
+ # Windows 2000 with Windows Media Player 9.0::
91
+ # NSPlayer/9.0.0.3270 WMFSDK/9.0
92
+ # Windows-Media-Player/9.00.00.3367
93
+ #
94
+ # Windows XP with Windows Media Player 6.4::
95
+ # NSPlayer/4.1.0.3936
96
+ #
97
+ # Windows XP with Windows Media Player 9::
98
+ # NSPlayer/9.0.0.4503
99
+ # NSPlayer/9.0.0.4503 WMFSDK/9.0
100
+ # Windows-Media-Player/9.00.00.4503
101
+ #
102
+ # Windows XP with Windows Media Player 10::
103
+ # NSPlayer/10.0.0.3802
104
+ # NSPlayer/10.0.0.3802 WMFSDK/10.0
105
+ # Windows-Media-Player/10.00.00.3802
106
+ #
107
+ # Windows XP with Windows Media Player 11::
108
+ # NSPlayer/11.0.5721.5262
109
+ # NSPlayer/11.0.5721.5262 WMFSDK/11.0
110
+ # Windows-Media-Player/11.0.5721.5262
111
+ #
112
+ # Windows Vista with Windows Media Player 11::
113
+ # NSPlayer/11.00.6002.18392 WMFSDK/11.00.6002.18392
114
+ # NSPlayer/11.0.6002.18005
115
+ # NSPlayer/11.0.6002.18049 WMFSDK/11.0
116
+ # Windows-Media-Player/11.0.6002.18311
117
+ #
118
+ # Windows 8.1 with Windows Media Player 12::
119
+ # NSPlayer/12.00.9600.17031 WMFSDK/12.00.9600.17031
120
+ #
121
+ # Windows 10 with Windows Media Player 12::
122
+ # Windows-Media-Player/12.0.9841.0
123
+ # NSPlayer/12.00.9841.0000 WMFSDK/12.00.9841.0000
124
+ #
125
+ # Windows Phone 8.1 (Podcasts app)::
126
+ # NSPlayer/12.00.9651.0000 WMFSDK/12.00.9651.0000
127
+ def os
128
+ # WMP 6.4
129
+ if classic?
130
+ case version.to_a[3]
131
+ when 3564, 3925 then "Windows 98"
132
+ when 3857 then "Windows 9x"
133
+ when 3936 then "Windows XP"
134
+ when 3938 then "Windows 2000"
135
+ else "Windows"
136
+ end
137
+
138
+ # WMP 7/7.1
139
+ elsif version.to_a[0] == 7
140
+ case version.to_a[3]
141
+ when 3055 then "Windows 98"
142
+ else "Windows"
143
+ end
144
+
145
+ # WMP 8 was also known as "Windows Media Player for Windows XP"
146
+ elsif version.to_a[0] == 8
147
+ "Windows XP"
148
+
149
+ # WMP 9/10
150
+ elsif version.to_a[0] == 9 || version.to_a[0] == 10
151
+ case version.to_a[3]
152
+ when 2980 then "Windows 98/2000"
153
+ when 3268, 3367, 3270 then "Windows 2000"
154
+ when 3802, 4503 then "Windows XP"
155
+ else "Windows"
156
+ end
157
+
158
+ # WMP 11/12
159
+ elsif version.to_a[0] == 11 || version.to_a[0] == 12
160
+ case version.to_a[2]
161
+ when 9841, 9858, 9860,
162
+ 9879 then "Windows 10"
163
+ when 9651 then "Windows Phone 8.1"
164
+ when 9600 then "Windows 8.1"
165
+ when 9200 then "Windows 8"
166
+ when 7600, 7601 then "Windows 7"
167
+ when 6000, 6001, 6002 then "Windows Vista"
168
+ when 5721 then "Windows XP"
169
+ else "Windows"
170
+ end
171
+ else
172
+ "Windows"
173
+ end
174
+ end
175
+ end
176
+ end
177
+ end
@@ -16,10 +16,21 @@ class UserAgent
16
16
  }.freeze
17
17
 
18
18
  def self.normalize_os(os)
19
- Windows[os] || normalize_mac_os_x(os) || os
19
+ Windows[os] || normalize_mac_os_x(os) || normalize_ios(os) || os
20
20
  end
21
21
 
22
22
  private
23
+ def self.normalize_ios(os)
24
+ if os =~ /CPU OS\s*([0-9_\.]+)?\slike Mac OS X/
25
+ if $1.nil?
26
+ "iOS"
27
+ else
28
+ version = $1.gsub('_', '.')
29
+ "iOS #{version}"
30
+ end
31
+ end
32
+ end
33
+
23
34
  def self.normalize_mac_os_x(os)
24
35
  if os =~ /(?:Intel|PPC) Mac OS X\s*([0-9_\.]+)?/
25
36
  if $1.nil?
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: useragent
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.12.0
4
+ version: 0.13.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Joshua Peek
@@ -50,12 +50,16 @@ files:
50
50
  - README.md
51
51
  - lib/user_agent.rb
52
52
  - lib/user_agent/browsers.rb
53
+ - lib/user_agent/browsers/apple_core_media.rb
53
54
  - lib/user_agent/browsers/base.rb
54
55
  - lib/user_agent/browsers/chrome.rb
55
56
  - lib/user_agent/browsers/gecko.rb
56
57
  - lib/user_agent/browsers/internet_explorer.rb
58
+ - lib/user_agent/browsers/itunes.rb
59
+ - lib/user_agent/browsers/libavformat.rb
57
60
  - lib/user_agent/browsers/opera.rb
58
61
  - lib/user_agent/browsers/webkit.rb
62
+ - lib/user_agent/browsers/windows_media_player.rb
59
63
  - lib/user_agent/comparable.rb
60
64
  - lib/user_agent/operating_systems.rb
61
65
  - lib/user_agent/version.rb