diff --git a/config/user-agents.json b/config/user-agents.json new file mode 100644 index 00000000..38d37046 --- /dev/null +++ b/config/user-agents.json @@ -0,0 +1,14 @@ +{ +"safari": { + "os": ["Macintosh; Intel Mac OS X 10_15_7", "Macintosh; Intel Mac OS X 10_15_6", + "Macintosh; Intel Mac OS X 11_3", ""], + "versions": ["14.1.1", "14.1", "14.0.3"] + }, + +"firefox": { + "os": ["Macintosh; Intel Mac OS X 10.15'", "Macintosh; Intel Mac OS X 10.14", + "Windows NT 10.0; Win64; x64", "X11; Ubuntu; Linux x86_64", + "X11; Linux x86_64", "Windows NT 10.0", "Macintosh; Intel Mac OS X 11.3"], + "versions": ["88.0 ", "89.0", "90.0", "78.0"] + } +} \ No newline at end of file diff --git a/src/invidious/helpers/random-user-agents.cr b/src/invidious/helpers/random-user-agents.cr index f16689fb..305c4f68 100644 --- a/src/invidious/helpers/random-user-agents.cr +++ b/src/invidious/helpers/random-user-agents.cr @@ -1,26 +1,9 @@ -# Using different browsers would allow us to disguise our traffic even more. -# However, due to the widely different version and operating system values as well as -# their frequency on different OSes we're going to need a separate dataset -# for everything. - -AGENT_COMPONENTS = { - "safari" => { - "os" => ["Macintosh; Intel Mac OS X 10_15_7", "Macintosh; Intel Mac OS X 10_15_6"], - "versions" => ["14.1.1", "14.1", "14.0.3"], - }, - - "firefox" => { - "os" => ["Macintosh; Intel Mac OS X 10.15'", "Macintosh; Intel Mac OS X 10.14", - "Windows NT 10.0; Win64; x64", "X11; Ubuntu; Linux x86_64", - "X11; Linux x86_64"], - "versions" => ["88.0 ", "89.0"], - }, -} +AGENT_COMPONENTS = JSON.parse(File.read("config/user-agents.json")).as_h private def generate_user_agent agent_component = AGENT_COMPONENTS.keys.sample(1)[0] - os = AGENT_COMPONENTS[agent_component]["os"].sample(1)[0] - version = AGENT_COMPONENTS[agent_component]["versions"].sample(1)[0] + os = AGENT_COMPONENTS[agent_component]["os"].as_a.sample(1)[0] + version = AGENT_COMPONENTS[agent_component]["versions"].as_a.sample(1)[0] base = "Mozilla/5.0 " case agent_component