gTTS-token-1.1.3/0000755000175000017500000000000013400014634015444 5ustar boudewijnboudewijn00000000000000gTTS-token-1.1.3/LICENSE0000644000175000017500000000207613351214547016470 0ustar boudewijnboudewijn00000000000000The MIT License (MIT) Copyright (c) 2016 Boudewijn van Groos Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. gTTS-token-1.1.3/MANIFEST.in0000644000175000017500000000006613351256467017225 0ustar boudewijnboudewijn00000000000000include README.md include CHANGES.txt include LICENSE gTTS-token-1.1.3/PKG-INFO0000644000175000017500000000264713400014634016552 0ustar boudewijnboudewijn00000000000000Metadata-Version: 1.1 Name: gTTS-token Version: 1.1.3 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@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 gTTS-token-1.1.3/README.md0000644000175000017500000000073513351214547016742 0ustar boudewijnboudewijn00000000000000gTTS-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.gTTS-token-1.1.3/gTTS_token.egg-info/0000755000175000017500000000000013400014634021157 5ustar boudewijnboudewijn00000000000000gTTS-token-1.1.3/gTTS_token.egg-info/PKG-INFO0000644000175000017500000000264713400014634022265 0ustar boudewijnboudewijn00000000000000Metadata-Version: 1.1 Name: gTTS-token Version: 1.1.3 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@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 gTTS-token-1.1.3/gTTS_token.egg-info/SOURCES.txt0000644000175000017500000000042513400014634023044 0ustar boudewijnboudewijn00000000000000LICENSE 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.pygTTS-token-1.1.3/gTTS_token.egg-info/dependency_links.txt0000644000175000017500000000000113400014634025225 0ustar boudewijnboudewijn00000000000000 gTTS-token-1.1.3/gTTS_token.egg-info/requires.txt0000644000175000017500000000001113400014634023547 0ustar boudewijnboudewijn00000000000000requests gTTS-token-1.1.3/gTTS_token.egg-info/top_level.txt0000644000175000017500000000001313400014634023703 0ustar boudewijnboudewijn00000000000000gtts_token gTTS-token-1.1.3/gtts_token/0000755000175000017500000000000013400014634017625 5ustar boudewijnboudewijn00000000000000gTTS-token-1.1.3/gtts_token/__init__.py0000644000175000017500000000000013351214547021736 0ustar boudewijnboudewijn00000000000000gTTS-token-1.1.3/gtts_token/gtts_token.py0000644000175000017500000000556013400014174022365 0ustar boudewijnboudewijn00000000000000# -*- 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 response = requests.get("https://translate.google.com/") tkk_expr = re.search("(tkk:.*?),", response.text) if not tkk_expr: raise ValueError( "Unable to find token seed! Did https://translate.google.com change?" ) tkk_expr = tkk_expr.group(1) try: # Grab the token directly if already generated by function call result = re.search("\d{6}\.[0-9]+", tkk_expr).group(0) except AttributeError: # Generate the token using algorithm timestamp = calendar.timegm(time.gmtime()) hours = int(math.floor(timestamp / 3600)) 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 gTTS-token-1.1.3/gtts_token/version.py0000644000175000017500000000002613400014174021661 0ustar boudewijnboudewijn00000000000000__version__ = '1.1.3' gTTS-token-1.1.3/setup.cfg0000644000175000017500000000004613400014634017265 0ustar boudewijnboudewijn00000000000000[egg_info] tag_build = tag_date = 0 gTTS-token-1.1.3/setup.py0000644000175000017500000000217613351256467017205 0ustar boudewijnboudewijn00000000000000try: 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@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' ], )