[Python-modules-commits] [gtts-token] 01/04: import gtts-token_1.1.1.orig.tar.gz

Ethan Ward ethanward-guest at moszumanska.debian.org
Tue Jul 25 16:55:07 UTC 2017


This is an automated email from the git hooks/post-receive script.

ethanward-guest pushed a commit to branch master
in repository gtts-token.

commit f986c5742f5ed3369c8b009f11a22091613170e0
Author: Ethan Ward <ethan.ward at mycroft.ai>
Date:   Tue Jul 25 11:42:05 2017 -0500

    import gtts-token_1.1.1.orig.tar.gz
---
 MANIFEST.in                              |  2 +
 PKG-INFO                                 | 37 +++++++++++++++
 README.md                                | 16 +++++++
 gTTS_token.egg-info/PKG-INFO             | 37 +++++++++++++++
 gTTS_token.egg-info/SOURCES.txt          | 11 +++++
 gTTS_token.egg-info/dependency_links.txt |  1 +
 gTTS_token.egg-info/requires.txt         |  1 +
 gTTS_token.egg-info/top_level.txt        |  1 +
 gtts_token/__init__.py                   |  0
 gtts_token/gtts_token.py                 | 79 ++++++++++++++++++++++++++++++++
 gtts_token/version.py                    |  1 +
 setup.cfg                                |  5 ++
 setup.py                                 | 35 ++++++++++++++
 13 files changed, 226 insertions(+)

diff --git a/MANIFEST.in b/MANIFEST.in
new file mode 100644
index 0000000..98fd97a
--- /dev/null
+++ b/MANIFEST.in
@@ -0,0 +1,2 @@
+include README.md
+include CHANGES.txt
diff --git a/PKG-INFO b/PKG-INFO
new file mode 100644
index 0000000..6a18131
--- /dev/null
+++ b/PKG-INFO
@@ -0,0 +1,37 @@
+Metadata-Version: 1.1
+Name: gTTS-token
+Version: 1.1.1
+Summary: Calculates a token to run the Google Translate text to speech
+Home-page: https://github.com/boudewijn26/gTTS-token
+Author: Boudewijn van Groos
+Author-email: boudewijn at vangroos.nl
+License: MIT
+Description: gTTS-token
+        ====
+        
+        **gTTS-token** (Google Text to Speech token): A python implementation of the token validation of Google Translate
+        
+        [![Build Status](https://travis-ci.org/Boudewijn26/gTTS-token.svg?branch=master)](https://travis-ci.org/Boudewijn26/gTTS-token)
+        
+        Install
+        -------
+        
+            pip install gTTS-token
+        
+        Description
+        -------
+        
+        Google Translate requires a tk param when making a request to its translate API. This project provides an implementation for that algorithm in Python.
+Platform: UNKNOWN
+Classifier: Environment :: Console
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: Unix
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: POSIX :: Linux
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Topic :: Software Development :: Libraries
+Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
diff --git a/README.md b/README.md
new file mode 100644
index 0000000..7c080d6
--- /dev/null
+++ b/README.md
@@ -0,0 +1,16 @@
+gTTS-token
+====
+
+**gTTS-token** (Google Text to Speech token): A python implementation of the token validation of Google Translate
+
+[![Build Status](https://travis-ci.org/Boudewijn26/gTTS-token.svg?branch=master)](https://travis-ci.org/Boudewijn26/gTTS-token)
+
+Install
+-------
+
+    pip install gTTS-token
+
+Description
+-------
+
+Google Translate requires a tk param when making a request to its translate API. This project provides an implementation for that algorithm in Python.
\ No newline at end of file
diff --git a/gTTS_token.egg-info/PKG-INFO b/gTTS_token.egg-info/PKG-INFO
new file mode 100644
index 0000000..6a18131
--- /dev/null
+++ b/gTTS_token.egg-info/PKG-INFO
@@ -0,0 +1,37 @@
+Metadata-Version: 1.1
+Name: gTTS-token
+Version: 1.1.1
+Summary: Calculates a token to run the Google Translate text to speech
+Home-page: https://github.com/boudewijn26/gTTS-token
+Author: Boudewijn van Groos
+Author-email: boudewijn at vangroos.nl
+License: MIT
+Description: gTTS-token
+        ====
+        
+        **gTTS-token** (Google Text to Speech token): A python implementation of the token validation of Google Translate
+        
+        [![Build Status](https://travis-ci.org/Boudewijn26/gTTS-token.svg?branch=master)](https://travis-ci.org/Boudewijn26/gTTS-token)
+        
+        Install
+        -------
+        
+            pip install gTTS-token
+        
+        Description
+        -------
+        
+        Google Translate requires a tk param when making a request to its translate API. This project provides an implementation for that algorithm in Python.
+Platform: UNKNOWN
+Classifier: Environment :: Console
+Classifier: Intended Audience :: Developers
+Classifier: License :: OSI Approved :: MIT License
+Classifier: Operating System :: MacOS :: MacOS X
+Classifier: Operating System :: Unix
+Classifier: Operating System :: POSIX
+Classifier: Operating System :: POSIX :: Linux
+Classifier: Programming Language :: Python :: 2.7
+Classifier: Programming Language :: Python :: 3.3
+Classifier: Programming Language :: Python :: 3.4
+Classifier: Topic :: Software Development :: Libraries
+Classifier: Topic :: Multimedia :: Sound/Audio :: Speech
diff --git a/gTTS_token.egg-info/SOURCES.txt b/gTTS_token.egg-info/SOURCES.txt
new file mode 100644
index 0000000..a2960d2
--- /dev/null
+++ b/gTTS_token.egg-info/SOURCES.txt
@@ -0,0 +1,11 @@
+MANIFEST.in
+README.md
+setup.py
+gTTS_token.egg-info/PKG-INFO
+gTTS_token.egg-info/SOURCES.txt
+gTTS_token.egg-info/dependency_links.txt
+gTTS_token.egg-info/requires.txt
+gTTS_token.egg-info/top_level.txt
+gtts_token/__init__.py
+gtts_token/gtts_token.py
+gtts_token/version.py
\ No newline at end of file
diff --git a/gTTS_token.egg-info/dependency_links.txt b/gTTS_token.egg-info/dependency_links.txt
new file mode 100644
index 0000000..8b13789
--- /dev/null
+++ b/gTTS_token.egg-info/dependency_links.txt
@@ -0,0 +1 @@
+
diff --git a/gTTS_token.egg-info/requires.txt b/gTTS_token.egg-info/requires.txt
new file mode 100644
index 0000000..663bd1f
--- /dev/null
+++ b/gTTS_token.egg-info/requires.txt
@@ -0,0 +1 @@
+requests
\ No newline at end of file
diff --git a/gTTS_token.egg-info/top_level.txt b/gTTS_token.egg-info/top_level.txt
new file mode 100644
index 0000000..0b2800b
--- /dev/null
+++ b/gTTS_token.egg-info/top_level.txt
@@ -0,0 +1 @@
+gtts_token
diff --git a/gtts_token/__init__.py b/gtts_token/__init__.py
new file mode 100644
index 0000000..e69de29
diff --git a/gtts_token/gtts_token.py b/gtts_token/gtts_token.py
new file mode 100644
index 0000000..87be2c0
--- /dev/null
+++ b/gtts_token/gtts_token.py
@@ -0,0 +1,79 @@
+# -*- coding: utf-8 -*-
+import calendar
+import math
+import time
+import requests
+import re
+
+
+class Token:
+    """ Token (Google Translate Token)
+    Generate the current token key and allows generation of tokens (tk) with it
+    Python version of `token-script.js` itself from translate.google.com
+    """
+
+    SALT_1 = "+-a^+6"
+    SALT_2 = "+-3^+b+-f"
+
+    def __init__(self):
+        self.token_key = None
+
+    def calculate_token(self, text, seed=None):
+        """ Calculate the request token (`tk`) of a string
+        :param text: str The text to calculate a token for
+        :param seed: str The seed to use. By default this is the number of hours since epoch
+        """
+
+        if seed is None:
+            seed = self._get_token_key()
+
+        [first_seed, second_seed] = seed.split(".")
+
+        try:
+            d = bytearray(text.encode('UTF-8'))
+        except UnicodeDecodeError:
+            # This will probably only occur when d is actually a str containing UTF-8 chars, which means we don't need
+            # to encode.
+            d = bytearray(text)
+
+        a = int(first_seed)
+        for value in d:
+            a += value
+            a = self._work_token(a, self.SALT_1)
+        a = self._work_token(a, self.SALT_2)
+        a ^= int(second_seed)
+        if 0 > a:
+            a = (a & 2147483647) + 2147483648
+        a %= 1E6
+        a = int(a)
+        return str(a) + "." + str(a ^ int(first_seed))
+
+    def _get_token_key(self):
+        if self.token_key is not None:
+            return self.token_key
+
+        timestamp = calendar.timegm(time.gmtime())
+        hours = int(math.floor(timestamp / 3600))
+
+        response = requests.get("https://translate.google.com/")
+        line = response.text.split('\n')[-1]
+
+        tkk_expr = re.search(".*?(TKK=.*?;)W.*?", line).group(1)
+        a = re.search("a\\\\x3d(-?\d+);", tkk_expr).group(1)
+        b = re.search("b\\\\x3d(-?\d+);", tkk_expr).group(1)
+
+        result = str(hours) + "." + str(int(a) + int(b))
+        self.token_key = result
+        return result
+
+    """ Functions used by the token calculation algorithm """
+    def _rshift(self, val, n):
+        return val >> n if val >= 0 else (val + 0x100000000) >> n
+
+    def _work_token(self, a, seed):
+        for i in range(0, len(seed) - 2, 3):
+            char = seed[i + 2]
+            d = ord(char[0]) - 87 if char >= "a" else int(char)
+            d = self._rshift(a, d) if seed[i + 1] == "+" else a << d
+            a = a + d & 4294967295 if seed[i] == "+" else a ^ d
+        return a
diff --git a/gtts_token/version.py b/gtts_token/version.py
new file mode 100644
index 0000000..8676381
--- /dev/null
+++ b/gtts_token/version.py
@@ -0,0 +1 @@
+__version__ = '1.1.1'
diff --git a/setup.cfg b/setup.cfg
new file mode 100644
index 0000000..ce27595
--- /dev/null
+++ b/setup.cfg
@@ -0,0 +1,5 @@
+[egg_info]
+tag_svn_revision = 0
+tag_build = 
+tag_date = 0
+
diff --git a/setup.py b/setup.py
new file mode 100644
index 0000000..dfff0ba
--- /dev/null
+++ b/setup.py
@@ -0,0 +1,35 @@
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
+
+exec(open('gtts_token/version.py').read())
+
+setup(
+    name='gTTS-token',
+    version=__version__,
+    author='Boudewijn van Groos',
+    author_email='boudewijn at vangroos.nl',
+    url='https://github.com/boudewijn26/gTTS-token',
+    packages=['gtts_token'],
+    license='MIT',
+    description='Calculates a token to run the Google Translate text to speech',
+    long_description=open('README.md').read(),
+    install_requires=[
+        "requests"
+    ],
+    classifiers=[
+          'Environment :: Console',
+          'Intended Audience :: Developers',
+          'License :: OSI Approved :: MIT License',
+          'Operating System :: MacOS :: MacOS X',
+          'Operating System :: Unix',
+          'Operating System :: POSIX',
+          'Operating System :: POSIX :: Linux',
+          'Programming Language :: Python :: 2.7',
+          'Programming Language :: Python :: 3.3',
+          'Programming Language :: Python :: 3.4',
+          'Topic :: Software Development :: Libraries',
+          'Topic :: Multimedia :: Sound/Audio :: Speech'
+    ],
+)

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/python-modules/packages/gtts-token.git



More information about the Python-modules-commits mailing list