updates fetched from Aciidisco
[plugin.video.netflix.git] / resources / lib / utils.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3 # Module: utils
4 # Created on: 13.01.2017
5
6 import platform
7
8 # Takes everything, does nothing, classic no operation function
9 def noop (**kwargs):
10     return True
11
12 # log decorator
13 def log(f, name=None):
14     if name is None:
15         name = f.func_name
16     def wrapped(*args, **kwargs):
17         that = args[0]
18         class_name = that.__class__.__name__
19         arguments = ''
20         for key, value in kwargs.iteritems():
21             if key != 'account' and key != 'credentials':
22                 arguments += ":%s = %s:" % (key, value)
23         if arguments != '':
24             that.log('"' + class_name + '::' + name + '" called with arguments ' + arguments)
25         else:
26             that.log('"' + class_name + '::' + name + '" called')
27         result = f(*args, **kwargs)
28         that.log('"' + class_name + '::' + name + '" returned: ' + str(result))
29         return result
30     wrapped.__doc__ = f.__doc__
31     return wrapped
32
33 def get_user_agent_for_current_platform():
34     """Determines the user agent string for the current platform (to retrieve a valid ESN)
35
36     Returns
37     -------
38     :obj:`str`
39         User Agent for platform
40     """
41     system = platform.system()
42     if system == 'Darwin':
43         return 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_10_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
44     if system == 'Windows':
45         return 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
46     if platform.machine().startswith('arm'):
47         return 'Mozilla/5.0 (X11; CrOS armv7l 7647.78.0) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'
48     return 'Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/59.0.3071.115 Safari/537.36'