From 39ce9f155fc1295a687d1b9ec6470978ca21345c Mon Sep 17 00:00:00 2001 From: Billy Ferguson Date: Tue, 4 Dec 2018 11:00:35 -0500 Subject: [PATCH 1/8] Updates code to run on new oauth login from gmusicapi --- README.md | 19 +++++--- geemusic/utils/music.py | 2 +- requirements.txt | 96 ++++++++++++++++------------------------- 3 files changed, 49 insertions(+), 68 deletions(-) diff --git a/README.md b/README.md index 35e021e..b8a0b55 100644 --- a/README.md +++ b/README.md @@ -93,12 +93,18 @@ $ source .venv/bin/activate $ pip3 install -r requirements.txt ``` -Once the requirements are installed we'll need to create a file, `.env` to store our credentials. Here's an example: +You must first verify you can do this part, this might exception out and if +you're lucky, you can grab one of the alpha numeric strings at the bottom of +exception string and replace below with that alpha numeric device +id. +``` +python -c 'from gmusicapi import Mobileclient as MC; m = MC(); print m.perform_oauth(); +python -c 'from gmusicapi import Mobileclient as MC; m = MC(); print m.oauth_login(""); print m.get_all_songs()[0]' +``` +Once the requirements are installed we'll need to create a file, `.env` to store our credentials. Here's an example: ``` -# Google credentials -GOOGLE_EMAIL=steve@stevegattuso.me -GOOGLE_PASSWORD=password +DEVICE_ID=device_id # Publicly accessible URL to your server, WITHOUT trailing slash APP_URL=https://alexa-geemusic.stevegattuso.me @@ -192,8 +198,7 @@ Once you've named your app and the code has been deployed, the next step is to c | Variable Name | Value | | ------------- | ------------- | -| GOOGLE_EMAIL | YOUR_EMAIL | -| GOOGLE_PASSWORD | YOUR_PASSWORD | +| DEVICE_ID | YOUR_DEVICE_ID | | APP_URL | https://[heroku_app_name].herokuapp.com | | DEBUG_MODE | false | @@ -218,7 +223,7 @@ $ docker build -t geemusic . Finally, run the container with the appropriate environment variables and port forwards. Alternatively set up a compose file or your orchestration engine, but those are outside the scope of this readme. ```bash -$ docker run -d -e GOOGLE_EMAIL=steve@stevegattuso.me -e GOOGLE_PASSWORD=[password] \ +$ docker run -d -e DEVICE_ID=[device-id] \ -e APP_URL=http://alexa-geemusic.stevegattuso.me -p 5000:5000 geemusic ``` diff --git a/geemusic/utils/music.py b/geemusic/utils/music.py index 116db3d..f14a5e3 100644 --- a/geemusic/utils/music.py +++ b/geemusic/utils/music.py @@ -11,7 +11,7 @@ class GMusicWrapper(object): def __init__(self, username, password, logger=None): self._api = Mobileclient() self.logger = logger - success = self._api.login(username, password, getenv('ANDROID_ID', Mobileclient.FROM_MAC_ADDRESS)) + success = self._api.oauth_login(os.environ["ANDROID_ID"]) if not success: raise Exception("Unsuccessful login. Aborting!") diff --git a/requirements.txt b/requirements.txt index 00f0a8d..efd358b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,66 +1,42 @@ -aniso8601==1.2.1 +aniso8601==1.2.0 appdirs==1.4.3 -argcomplete==1.9.2 asn1crypto==0.24.0 -base58==0.2.4 -beautifulsoup4==4.6.0 -boto3==1.7.16 -botocore==1.10.16 -certifi==2018.4.16 -cffi==1.10.0 -cfn-flip==1.0.3 +beautifulsoup4==4.6.3 +certifi==2018.11.29 +cffi==1.11.5 chardet==3.0.4 -click==6.7 -cryptography==2.3.1 -decorator==4.1.2 -docutils==0.14 -durationpy==0.5 -enum34==1.1.6 -Flask==0.12.2 -Flask-Ask==0.9.8 -funcsigs==1.0.2 -future==0.16.0 -fuzzywuzzy==0.15.1 -gmusicapi==10.1.2 +Click==7.0 +cryptography==2.1.4 +decorator==4.3.0 +Flask==0.12.1 +-e git+https://github.com/johnwheeler/flask-ask@fe407646ae404a8c90b363c86d5c4c201b6a5580#egg=Flask_Ask +future==0.17.1 +-e git+https://github.com/simon-weber/gmusicapi@6937a11a26d3e1bf34e13b8bf50f59cb55cbdc03#egg=gmusicapi gpsoauth==0.4.1 -hjson==3.0.1 -httplib2==0.10.3 -idna==2.5 -ipaddress==1.0.18 -itsdangerous==0.24 -Jinja2==2.9.6 -jmespath==0.9.3 -kappa==0.6.0 -lambda-packages==0.19.0 -MarkupSafe==1.0 -MechanicalSoup==0.7.0 +httplib2==0.12.0 +idna==2.7 +itsdangerous==1.1.0 +Jinja2==2.10 +lxml==4.2.5 +MarkupSafe==1.1.0 +MechanicalSoup==0.11.0 mock==2.0.0 -mutagen==1.38 -oauth2client==4.1.2 -pbr==3.1.1 -placebo==0.8.1 +mutagen==1.41.1 +oauth2client==4.1.3 +pbr==5.1.1 +pkg-resources==0.0.0 proboscis==1.2.6.0 -protobuf==3.3.0 -pyasn1==0.3.2 -pyasn1-modules==0.0.11 -pycparser==2.18 -pycryptodomex==3.4.6 -pyOpenSSL==17.2.0 -python-dateutil==2.6.1 -python-Levenshtein==0.12.0 -python-slugify==1.2.4 -PyYAML==3.13 -requests==2.18.3 -rsa==3.4.2 -s3transfer==0.1.13 -six==1.10.0 -testfixtures==6.2.0 -toml==0.9.4 -tqdm==4.19.1 -troposphere==2.2.1 -Unidecode==1.0.22 -urllib3==1.22 -validictory==1.1.1 -Werkzeug==0.12.2 -wsgi-request-logger==0.4.6 -zappa==0.45.1 +protobuf==3.6.1 +pyasn1==0.4.4 +pyasn1-modules==0.2.2 +pycparser==2.19 +pycryptodomex==3.7.2 +pyOpenSSL==17.0.0 +python-dateutil==2.7.5 +PyYAML==3.12 +requests==2.20.1 +rsa==4.0 +six==1.11.0 +urllib3==1.24.1 +validictory==1.1.2 +Werkzeug==0.14.1 From 8608f4781cd203ac54d34c70a561a1f9868a6cd4 Mon Sep 17 00:00:00 2001 From: Billy Ferguson Date: Tue, 4 Dec 2018 11:03:05 -0500 Subject: [PATCH 2/8] Fixes readme --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index b8a0b55..d54b311 100644 --- a/README.md +++ b/README.md @@ -98,8 +98,8 @@ you're lucky, you can grab one of the alpha numeric strings at the bottom of exception string and replace below with that alpha numeric device id. ``` -python -c 'from gmusicapi import Mobileclient as MC; m = MC(); print m.perform_oauth(); -python -c 'from gmusicapi import Mobileclient as MC; m = MC(); print m.oauth_login(""); print m.get_all_songs()[0]' +python -c 'from gmusicapi import Mobileclient as MC; m = MC(); print(m.perform_oauth());' +python -c 'from gmusicapi import Mobileclient as MC; m = MC(); print(m.oauth_login("")); print(m.get_all_songs()[0])' ``` Once the requirements are installed we'll need to create a file, `.env` to store our credentials. Here's an example: From 62bbd15155606c2ea4a074cd4c80024e21821851 Mon Sep 17 00:00:00 2001 From: Billy Ferguson Date: Tue, 4 Dec 2018 11:17:48 -0500 Subject: [PATCH 3/8] Fixes music so it logs in successfully --- geemusic/utils/music.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/geemusic/utils/music.py b/geemusic/utils/music.py index f14a5e3..3e5b1e5 100644 --- a/geemusic/utils/music.py +++ b/geemusic/utils/music.py @@ -1,6 +1,6 @@ +import os from builtins import object from fuzzywuzzy import fuzz -from os import getenv import threading import random @@ -8,10 +8,10 @@ class GMusicWrapper(object): - def __init__(self, username, password, logger=None): + def __init__(self, device_id, logger=None): self._api = Mobileclient() self.logger = logger - success = self._api.oauth_login(os.environ["ANDROID_ID"]) + success = self._api.oauth_login(device_id) if not success: raise Exception("Unsuccessful login. Aborting!") @@ -153,7 +153,7 @@ def get_google_stream_url(self, song_id): return self._api.get_stream_url(song_id) def get_stream_url(self, song_id): - return "%s/alexa/stream/%s" % (getenv('APP_URL'), song_id) + return "%s/alexa/stream/%s" % (os.environ['APP_URL'], song_id) def get_thumbnail(self, artist_art): return artist_art.replace("http://", "https://") @@ -270,5 +270,5 @@ def get_song_data(self, song_id): @classmethod def generate_api(cls, **kwargs): - return cls(getenv('GOOGLE_EMAIL'), getenv('GOOGLE_PASSWORD'), + return cls(os.environ['DEVICE_ID'], **kwargs) From 7a60403d529663b292edffb84dca9b05a8e16c09 Mon Sep 17 00:00:00 2001 From: Billy Ferguson Date: Tue, 4 Dec 2018 11:18:21 -0500 Subject: [PATCH 4/8] Refactors tests based on changes, for some reason the tests are failing though --- tests/test_functional.py | 4 ++-- tests/test_log.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/tests/test_functional.py b/tests/test_functional.py index 5b4cc0f..5e8d49c 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -1,9 +1,9 @@ import unittest +import os import json import uuid import yaml -from os import getenv from geemusic import app, ask from flask_ask import audio @@ -63,7 +63,7 @@ def setUp(self): self.app = app self.ask = ask self.client = self.app.test_client() - self.stream_url = getenv('APP_URL') + self.stream_url = os.environ['APP_URL'] self.custom_token = 'custom_uuid_{0}'.format(str(uuid.uuid4())) @self.ask.intent('TestPlay') diff --git a/tests/test_log.py b/tests/test_log.py index 0a5c366..cb7cf1a 100644 --- a/tests/test_log.py +++ b/tests/test_log.py @@ -25,7 +25,7 @@ class GMusicWrapperNoLogUnitTests(unittest.TestCase): def setUp(self): surpress_warnings() - self.api = GMusicWrapper(getenv("GOOGLE_EMAIL"), getenv("GOOGLE_PASSWORD")) + self.api = GMusicWrapper(getenv("DEVICE_ID")) def tearDown(self): pass @@ -44,7 +44,7 @@ class GMusicWrapperLogUnitTests(unittest.TestCase): def setUp(self): surpress_warnings() logger = logging.getLogger() - self.api = GMusicWrapper(getenv("GOOGLE_EMAIL"), getenv("GOOGLE_PASSWORD"), logger) + self.api = GMusicWrapper(getenv("DEVICE_ID"), logger) def tearDown(self): pass From 71524ce4f7bddab92bb6dce8464d3aae404ca676 Mon Sep 17 00:00:00 2001 From: Billy Ferguson Date: Tue, 4 Dec 2018 14:34:56 -0500 Subject: [PATCH 5/8] Hardcodes default environment variables that don't matter for testing --- tests/test_functional.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_functional.py b/tests/test_functional.py index 5e8d49c..2ee1a3e 100644 --- a/tests/test_functional.py +++ b/tests/test_functional.py @@ -60,6 +60,8 @@ class EnglishAudioIntegrationTests(unittest.TestCase): """ Integration tests of the english Audio Directives """ def setUp(self): + os.environ["ASK_VERIFY_REQUESTS"] = 'False' + os.environ["APP_URL"] = 'http://localhost' self.app = app self.ask = ask self.client = self.app.test_client() From ae6154acdc59084b0d7c4d2c2b362f38c4433e81 Mon Sep 17 00:00:00 2001 From: everyonce Date: Wed, 5 Dec 2018 16:23:19 -0600 Subject: [PATCH 6/8] update Dockerfile for dev --- Dockerfile | 2 +- requirements.txt | 1 - 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 02b4def..0188714 100755 --- a/Dockerfile +++ b/Dockerfile @@ -3,7 +3,7 @@ MAINTAINER Spencer Julian RUN apk update \ && apk upgrade \ - && apk add --update curl wget bash ruby ruby-bundler python3 python3-dev py3-pip dumb-init musl linux-headers build-base libffi-dev openssl-dev ruby-rdoc ruby-irb\ + && apk add --update git curl wget bash ruby ruby-bundler python3 python3-dev py3-pip libxml2-dev libxslt-dev dumb-init musl linux-headers build-base libffi-dev openssl-dev ruby-rdoc ruby-irb\ && rm -rf /var/cache/apk/* \ && mkdir /geemusic diff --git a/requirements.txt b/requirements.txt index efd358b..4dd2c3c 100644 --- a/requirements.txt +++ b/requirements.txt @@ -24,7 +24,6 @@ mock==2.0.0 mutagen==1.41.1 oauth2client==4.1.3 pbr==5.1.1 -pkg-resources==0.0.0 proboscis==1.2.6.0 protobuf==3.6.1 pyasn1==0.4.4 From 810685cae77cb902baa6e3df770d7f7f54a444ea Mon Sep 17 00:00:00 2001 From: Billy Ferguson Date: Thu, 6 Dec 2018 16:43:00 -0500 Subject: [PATCH 7/8] Adds requirements to for tests --- requirements.txt | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/requirements.txt b/requirements.txt index 4dd2c3c..e24f57e 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,21 +2,26 @@ aniso8601==1.2.0 appdirs==1.4.3 asn1crypto==0.24.0 beautifulsoup4==4.6.3 +boto3==1.9.61 +botocore==1.12.61 certifi==2018.11.29 cffi==1.11.5 chardet==3.0.4 Click==7.0 cryptography==2.1.4 decorator==4.3.0 +docutils==0.14 Flask==0.12.1 -e git+https://github.com/johnwheeler/flask-ask@fe407646ae404a8c90b363c86d5c4c201b6a5580#egg=Flask_Ask future==0.17.1 +fuzzywuzzy==0.17.0 -e git+https://github.com/simon-weber/gmusicapi@6937a11a26d3e1bf34e13b8bf50f59cb55cbdc03#egg=gmusicapi gpsoauth==0.4.1 httplib2==0.12.0 idna==2.7 itsdangerous==1.1.0 Jinja2==2.10 +jmespath==0.9.3 lxml==4.2.5 MarkupSafe==1.1.0 MechanicalSoup==0.11.0 @@ -24,6 +29,7 @@ mock==2.0.0 mutagen==1.41.1 oauth2client==4.1.3 pbr==5.1.1 +pkg-resources==0.0.0 proboscis==1.2.6.0 protobuf==3.6.1 pyasn1==0.4.4 @@ -35,7 +41,9 @@ python-dateutil==2.7.5 PyYAML==3.12 requests==2.20.1 rsa==4.0 +s3transfer==0.1.13 six==1.11.0 +testfixtures==6.3.0 urllib3==1.24.1 validictory==1.1.2 Werkzeug==0.14.1 From 24d88bcd23877d872c54f7d84d3bf94035f68bf7 Mon Sep 17 00:00:00 2001 From: Billy Ferguson Date: Thu, 6 Dec 2018 16:47:39 -0500 Subject: [PATCH 8/8] Removes the pkg resources --- requirements.txt | 1 - 1 file changed, 1 deletion(-) diff --git a/requirements.txt b/requirements.txt index e24f57e..884b541 100644 --- a/requirements.txt +++ b/requirements.txt @@ -29,7 +29,6 @@ mock==2.0.0 mutagen==1.41.1 oauth2client==4.1.3 pbr==5.1.1 -pkg-resources==0.0.0 proboscis==1.2.6.0 protobuf==3.6.1 pyasn1==0.4.4