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

Commit

Permalink
fixes #13 - Add device_id parameter (default iface by default)
Browse files Browse the repository at this point in the history
  • Loading branch information
jaymoulin committed Nov 1, 2018
1 parent 6984d51 commit c990ed7
Show file tree
Hide file tree
Showing 7 changed files with 69 additions and 35 deletions.
25 changes: 14 additions & 11 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -91,16 +91,16 @@ It will *NOT* upload already existing files, *ONLY* new files while the daemon i
[--uploader_id UPLOADER_ID] [-o]
optional arguments:
-h, --help show this help message and exit
--directory DIRECTORY, -d DIRECTORY
-h, --help show this help message and exit
--directory DIRECTORY, -d DIRECTORY
Music Folder to upload from (default: .)
--oauth OAUTH, -a OAUTH
--oauth OAUTH, -a OAUTH
Path to oauth file (default: ~/oauth)
-r, --remove Remove files if present (default: False)
--uploader_id UPLOADER_ID, -u UPLOADER_ID
-r, --remove Remove files if present (default: False)
--uploader_id UPLOADER_ID, -u UPLOADER_ID
Uploader identification (should be an uppercase MAC
address) (default: <current eth0 MAC address>)
-o, --oneshot Upload folder and exit (default: False)
-o, --oneshot Upload folder and exit (default: False)
Downloader
~~~~~~~~~~
Expand All @@ -112,11 +112,14 @@ This program will download all your uploaded musics from Google Music to a given
usage: google-music-download [-h] [--directory DIRECTORY] [--oauth OAUTH]
optional arguments:
-h, --help show this help message and exit
--directory DIRECTORY, -d DIRECTORY
Music Folder to download to (default: .)
--oauth OAUTH, -a OAUTH
Path to oauth file (default: ~/oauth)
-h, --help show this help message and exit
--directory DIRECTORY, -d DIRECTORY
Music Folder to download to (default: .)
--oauth OAUTH, -a OAUTH
Path to oauth file (default: ~/oauth)
--device_id DEVICE_ID, -i DEVICE_ID
Device identification (should be an uppercase MAC
address) (default: <current eth0 MAC address>)
=====
Expand Down
11 changes: 8 additions & 3 deletions downloader/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ This work is based upon `Simon Weber's Google Music API <https://github.com/simo
Installation
------------

This program needs `netifaces` Python library to work.

.. code::
apt-get install python3-pip build-essential
Expand Down Expand Up @@ -65,11 +67,14 @@ This program will download all your uploaded musics from Google Music to a given
usage: google-music-download [-h] [--directory DIRECTORY] [--oauth OAUTH]
optional arguments:
-h, --help show this help message and exit
--directory DIRECTORY, -d DIRECTORY
-h, --help show this help message and exit
--directory DIRECTORY, -d DIRECTORY
Music Folder to download to (default: .)
--oauth OAUTH, -a OAUTH
--oauth OAUTH, -a OAUTH
Path to oauth file (default: ~/oauth)
--uploader_id UPLOADER_ID, -u UPLOADER_ID
Uploader identification (should be an uppercase MAC
address) (default: <current eth0 MAC address>)
=====
Expand Down
24 changes: 19 additions & 5 deletions downloader/google_music_manager_downloader/download.py
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys, time, logging, os.path, argparse, os
import sys, time, logging, os.path, netifaces, argparse, os
from gmusicapi import Musicmanager

__all__ = ['download']

__DEFAULT_IFACE__ = netifaces.gateways()['default'][netifaces.AF_INET][1]
__DEFAULT_MAC__ = netifaces.ifaddresses(__DEFAULT_IFACE__)[netifaces.AF_LINK][0]['addr'].upper()

def download(directory=".", oauth=os.environ['HOME'] + "/oauth"):

def download(directory=".", oauth=os.environ['HOME'] + "/oauth", device_id=__DEFAULT_MAC__):
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info("Init Daemon - Press Ctrl+C to quit")
api = Musicmanager()
if not api.login(oauth):
if not api.login(oauth, device_id):
print("Error with oauth credentials")
sys.exit(1)

Expand All @@ -32,9 +35,20 @@ def download(directory=".", oauth=os.environ['HOME'] + "/oauth"):
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--directory", '-d', default='.', help="Music Folder to download to (default: .)")
parser.add_argument("--oauth", '-a', default=os.environ['HOME'] + '/oauth', help="Path to oauth file (default: ~/oauth)")
parser.add_argument(
"--oauth",
'-a',
default=os.environ['HOME'] + '/oauth',
help="Path to oauth file (default: ~/oauth)"
)
parser.add_argument(
"--device_id",
'-i',
default=__DEFAULT_MAC__,
help="Uploader identification (should be an uppercase MAC address) (default: <current eth0 MAC address>)"
)
args = parser.parse_args()
download(args.directory, args.oauth)
download(args.directory, oauth=args.oauth, device_id=args.device_id)


if __name__ == "__main__":
Expand Down
4 changes: 2 additions & 2 deletions downloader/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import setup, find_packages

__version__ = '1.1.0'
__version__ = '1.2.0'

setup(
name='google_music_manager_downloader',
Expand All @@ -14,7 +14,7 @@
author_email="[email protected]",
description="Google MusicManager package to manage your music library to Google Music - Download module",
long_description=open('README.rst').read(),
install_requires=["google_music_manager_auth"],
install_requires=["google_music_manager_auth", "netifaces"],
include_package_data=True,
url='http://github.com/jaymoulin/google-music-manager',
classifiers=[
Expand Down
4 changes: 2 additions & 2 deletions uploader/README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ It will *NOT* upload already existing files, *ONLY* new files while the daemon i
--oauth OAUTH, -a OAUTH
Path to oauth file (default: ~/oauth)
-r, --remove Remove files if present (default: False)
--uploader_id UPLOADER_ID, -u UPLOADER_ID
Uploader identification (should be an uppercase MAC
--device_id DEVICE_ID, -i DEVICE_ID
Device identification (should be an uppercase MAC
address) (default: <current eth0 MAC address>)
-o, --oneshot Upload folder and exit (default: False)
Expand Down
34 changes: 23 additions & 11 deletions uploader/google_music_manager_uploader/uploader_daemon.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@ def on_created(self, event):
if os.path.isdir(self.path):
files = [file for file in glob.glob(glob.escape(self.path) + '/**/*', recursive=True)]
for file_path in files:
upload_file(self.api, file_path, self.logger, self.oauth, self.uploader_id, self.remove)
upload_file(self.api, file_path, self.logger, remove=self.remove)
else:
upload_file(self.api, event.src_path, self.logger, self.oauth, self.uploader_id, self.remove)
upload_file(self.api, event.src_path, self.logger, remove=self.remove)


def upload_file(api, file_path, logger, oauth=os.environ['HOME'] + '/oauth', uploader_id=__DEFAULT_MAC__, remove=False):
def upload_file(api, file_path, logger, remove=False):
retry = 5
while retry > 0:
try:
Expand All @@ -46,8 +46,13 @@ def upload_file(api, file_path, logger, oauth=os.environ['HOME'] + '/oauth', upl
raise e


def upload(directory='.', oauth=os.environ['HOME'] + '/oauth', remove=False, uploader_id=__DEFAULT_MAC__,
oneshot=False):
def upload(
directory='.',
oauth=os.environ['HOME'] + '/oauth',
remove=False,
uploader_id=__DEFAULT_MAC__,
oneshot=False
):
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)
logger.info("Init Daemon - Press Ctrl+C to quit")
Expand All @@ -70,7 +75,7 @@ def upload(directory='.', oauth=os.environ['HOME'] + '/oauth', remove=False, upl
observer.start()
files = [file for file in glob.glob(glob.escape(directory) + '/**/*', recursive=True)]
for file_path in files:
upload_file(api, file_path, logger, oauth, uploader_id, remove)
upload_file(api, file_path, logger, remove=remove)
if oneshot:
sys.exit(0)
try:
Expand All @@ -84,12 +89,19 @@ def upload(directory='.', oauth=os.environ['HOME'] + '/oauth', remove=False, upl
def main():
parser = argparse.ArgumentParser()
parser.add_argument("--directory", '-d', default='.', help="Music Folder to upload from (default: .)")
parser.add_argument("--oauth", '-a', default=os.environ['HOME'] + '/oauth',
help="Path to oauth file (default: ~/oauth)")
parser.add_argument(
"--oauth",
'-a',
default=os.environ['HOME'] + '/oauth',
help="Path to oauth file (default: ~/oauth)"
)
parser.add_argument("-r", "--remove", action='store_true', help="Remove files if present (default: False)")
parser.add_argument("--uploader_id", '-u',
default=__DEFAULT_MAC__,
help="Uploader identification (should be an uppercase MAC address) (default: <current eth0 MAC address>)")
parser.add_argument(
"--uploader_id",
'-u',
default=__DEFAULT_MAC__,
help="Uploader identification (should be an uppercase MAC address) (default: <current eth0 MAC address>)"
)
parser.add_argument("--oneshot", '-o', action='store_true', help="Upload folder and exit (default: False)")
args = parser.parse_args()
upload(args.directory, args.oauth, args.remove, args.uploader_id, args.oneshot)
Expand Down
2 changes: 1 addition & 1 deletion uploader/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from setuptools import setup, find_packages

__version__ = '1.2.3'
__version__ = '1.2.4'

setup(
name='google_music_manager_uploader',
Expand Down

0 comments on commit c990ed7

Please sign in to comment.