Skip to content
This repository has been archived by the owner on Jul 21, 2020. It is now read-only.

Packaging #9

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,6 @@

# ignore downloaded apps
*.apk

# ignore egg build leftovers
build/
Empty file added googleplayapi/__init__.py
Empty file.
7 changes: 2 additions & 5 deletions apishell.py → googleplayapi/apishell.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
#!/usr/bin/python

# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None

BANNER = """
Google Play Unofficial API Interactive Shell
Successfully logged in using your Google account. The variable 'api' holds the API object.
Expand All @@ -15,8 +12,8 @@
from pprint import pprint
from google.protobuf import text_format

from config import *
from googleplay import GooglePlayAPI
from googleplayapi.config import *
from googleplayapi.googleplay import GooglePlayAPI

api = GooglePlayAPI(ANDROID_ID)
api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
Expand Down
7 changes: 2 additions & 5 deletions categories.py → googleplayapi/categories.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/python

# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None

import sys
import urlparse
from pprint import pprint
from google.protobuf import text_format

from config import *
from googleplay import GooglePlayAPI
from googleplayapi.config import *
from googleplayapi.googleplay import GooglePlayAPI

api = GooglePlayAPI(ANDROID_ID)
api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
Expand Down
File renamed without changes.
17 changes: 9 additions & 8 deletions download.py → googleplayapi/download.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/python

# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None

import sys
from pprint import pprint

from config import *
from googleplay import GooglePlayAPI
from helpers import sizeof_fmt
from googleplayapi.config import *
from googleplayapi.googleplay import GooglePlayAPI
from googleplayapi.helpers import sizeof_fmt

if (len(sys.argv) < 2):
print "Usage: %s packagename [filename]"
Expand All @@ -24,8 +21,12 @@
filename = packagename + ".apk"

# Connect
api = GooglePlayAPI(ANDROID_ID)
api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
api = GooglePlayAPI(androidId=ANDROID_ID, email=GOOGLE_LOGIN, password=GOOGLE_PASSWORD, authSubToken=AUTH_TOKEN)

# login if necessary
if not AUTH_TOKEN:
# api.login(GOOGLE_LOGIN, GOOGLE_PASSWORD, AUTH_TOKEN)
api.login()

# Get the version code and the offer type from the app details
m = api.details(packagename)
Expand Down
File renamed without changes.
45 changes: 36 additions & 9 deletions googleplay.py → googleplayapi/googleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
from google.protobuf import text_format
from google.protobuf.message import Message, DecodeError

import googleplay_pb2
import config
import googleplayapi.googleplay_pb2 as googleplay_pb2
import googleplayapi.config as config

class LoginError(Exception):
def __init__(self, value):
Expand Down Expand Up @@ -46,12 +46,33 @@ class GooglePlayAPI(object):
authSubToken = None
context = None

def __init__(self, androidId=None, debug=False): # you must use a device-associated androidId value
def __init__(self, androidId=None, authSubToken=None, email=None, password=None, debug=False):
"""Google Play API

authSubToken - pass in this value instead of calling login() multiple times

email - Google Play username

password - Google Play Password

androidId - device id associated with the same Google Play account

debug - increase verbosity and clutter up the screen
"""
self.preFetch = {}

self.debug = debug

# store immediately to avoid more params to login() later
self.email = email
self.password = password
self.authSubToken = authSubToken

# try to grab androidId from config as a last resort
if androidId == None:
import googleplayapi.config as config
androidId = config.ANDROID_ID
self.androidId = androidId
self.debug = debug

def toDict(self, protoObj):
"""Converts the (protobuf) result from an API call into a dict, for
Expand Down Expand Up @@ -92,14 +113,20 @@ def _try_register_preFetch(self, protoObj):
def setAuthSubToken(self, authSubToken):
self.authSubToken = authSubToken

# put your auth token in config.py to avoid multiple login requests
if self.debug:
print "authSubToken: " + authSubToken

def login(self, email=None, password=None, authSubToken=None):
"""Login to your Google Account. You must provide either:
"""Login to your Google account. You must provide either:
- an email and password
- a valid Google authSubToken"""
if email == None:
email = self.email
if password == None:
password = self.password
# Don't load authSubToken from self because maybe we're logging in
# again.

if (authSubToken is not None):
self.setAuthSubToken(authSubToken)
else:
Expand All @@ -114,9 +141,9 @@ def login(self, email=None, password=None, authSubToken=None):
"androidId": self.androidId,
"app": "com.android.vending",
#"client_sig": self.client_sig,
"device_country": "fr",
"operatorCountry": "fr",
"lang": "fr",
"device_country": "us",
"operatorCountry": "us",
"lang": "en",
"sdk_version": "16"}
headers = {
"Accept-Encoding": "",
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion helpers.py → googleplayapi/helpers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
from config import SEPARATOR
from googleplayapi.config import SEPARATOR

def sizeof_fmt(num):
for x in ['bytes','KB','MB','GB','TB']:
Expand Down
9 changes: 3 additions & 6 deletions list.py → googleplayapi/list.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/python

# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None

import sys
from pprint import pprint

from config import *
from googleplay import GooglePlayAPI
from helpers import sizeof_fmt, print_header_line, print_result_line
from googleplayapi.config import *
from googleplayapi.googleplay import GooglePlayAPI
from googleplayapi.helpers import sizeof_fmt, print_header_line, print_result_line

if (len(sys.argv) < 2):
print "Usage: %s category [subcategory] [nb_results] [offset]" % sys.argv[0]
Expand Down
7 changes: 2 additions & 5 deletions permissions.py → googleplayapi/permissions.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
#!/usr/bin/python

# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None

import sys
import urlparse
from pprint import pprint
from google.protobuf import text_format

from config import *
from googleplay import GooglePlayAPI
from googleplayapi.config import *
from googleplayapi.googleplay import GooglePlayAPI

if (len(sys.argv) < 2):
print "Usage: %s packagename1 [packagename2 [...]]" % sys.argv[0]
Expand Down
9 changes: 3 additions & 6 deletions search.py → googleplayapi/search.py
Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
#!/usr/bin/python

# Do not remove
GOOGLE_LOGIN = GOOGLE_PASSWORD = AUTH_TOKEN = None

import sys
from pprint import pprint

from config import *
from googleplay import GooglePlayAPI
from helpers import sizeof_fmt, print_header_line, print_result_line
from googleplayapi.config import *
from googleplayapi.googleplay import GooglePlayAPI
from googleplayapi.helpers import sizeof_fmt, print_header_line, print_result_line

if (len(sys.argv) < 2):
print "Usage: %s request [nb_results] [offset]" % sys.argv[0]
Expand Down
12 changes: 12 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
from setuptools import setup, find_packages

version = "1.0.0"

setup(name="googleplayapi",
version=version,
author="Emilien Girault",
author_email="[email protected]",
license="BSD",
description="Google Play API for Android",
url="https://github.com/kanzure/googleplay-api",
packages=find_packages())