Skip to content

Commit

Permalink
Merge pull request #39 from erik/drop-py2
Browse files Browse the repository at this point in the history
Drop support for Python 2
  • Loading branch information
erik authored Mar 2, 2018
2 parents b7f09db + 9283f11 commit 34a7c7a
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 37 deletions.
52 changes: 26 additions & 26 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,14 @@ By default, lastcast will scrobble music playing on Spotify,
Google Play Music, SoundCloud, and Plex, but can be configured to
scrobble any media player that supports Chromecast.

**Python 2 is no longer supported as of lastcast 1.0.0.**

If you need Python 2, please install ``lastcast==0.7.0``.

Getting started
---------------

``pip install lastcast``
``pip3 install lastcast``

Set up an initial configuration with the configuration
creation tool:
Expand All @@ -24,34 +28,10 @@ If you'd prefer to set up the configuration manually, modify
Once the configuration file is in place, just run ``lastcast`` to connect to
the Chromecast and start scrobbling!

Detailed macOS setup
--------------------

(for anyone not familiar with Python and pip)

Enter the following commands in your Terminal (Terminal.app, iTerm2, etc.):

1. ``sudo easy_install pip``
2. ``sudo pip install --upgrade lastcast --ignore-installed six``
3. ``lastcast --wizard``

This will prompt you to create a last.fm API application and then ask for your
login information, which will only be stored locally on your computer.

You may get an error on step 2 about ``cc`` missing. If this is the case,
install xcode by running ``xcode-select --install`` and retry step 2.

Now everything should be set up. When you want to start scrobbling, simply
run ``lastcast`` in the terminal.

Generally, I run lastcast like so: ``while true; do lastcast; sleep 5; done``.
This will help in case lastcast crashes for whatever reason (please open an issue
if you see something go wrong!)

Linux / systemd instructions
----------------------------

1. ``sudo pip install --upgrade lastcast``
1. ``sudo pip3 install --upgrade lastcast``
2. ``lastcast --wizard``
3. Edit the code block below as needed (remember to fill in the config path!)
and write to ``/usr/lib/systemd/system/lastcast.service``
Expand All @@ -74,6 +54,26 @@ Linux / systemd instructions
WantedBy=network-online.target
Detailed macOS setup
--------------------

(for anyone not familiar with Python and pip)

Enter the following commands in your Terminal (Terminal.app, iTerm2, etc.):

1. ``brew install python3``
2. ``sudo pip3 install --upgrade lastcast``
3. ``lastcast --wizard``

This will prompt you to create a last.fm API application and then ask for your
login information, which will only be stored locally on your computer.

You may get an error on step 2 about ``cc`` missing. If this is the case,
install xcode by running ``xcode-select --install`` and retry step 2.

Now everything should be set up. When you want to start scrobbling, simply
run ``lastcast`` in the terminal.

No Chromecast devices found?
----------------------------

Expand Down
15 changes: 8 additions & 7 deletions lastcast/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
logging.basicConfig()

# Default set of apps to scrobble from.
APP_WHITELIST = [u'Spotify', u'Google Play Music', u'SoundCloud', u'Plex']
APP_WHITELIST = ['Spotify', 'Google Play Music', 'SoundCloud', 'Plex']

SCROBBLE_THRESHOLD_PCT = 0.50
SCROBBLE_THRESHOLD_SECS = 120
Expand Down Expand Up @@ -144,7 +144,7 @@ def _connect_chromecast(self, available_devices=None):
self.cast = None

if not available_devices:
available_devices = pychromecast.get_chromecasts(tries=1, retry_wait=0.01)
available_devices = pychromecast.get_chromecasts(tries=1)

matching_devices = [
c for c in available_devices
Expand Down Expand Up @@ -181,9 +181,10 @@ def _on_media_controller_status(self, status):
# whichever comes first).
#
# Don't scrobble the same thing over and over
if meta != self.last_scrobbled and \
(self.current_time > SCROBBLE_THRESHOLD_SECS or \
(self.current_time / status.duration) >= SCROBBLE_THRESHOLD_PCT):
hit_threshold = self.current_time > SCROBBLE_THRESHOLD_SECS or \
(self.current_time / status.duration) >= SCROBBLE_THRESHOLD_PCT

if meta != self.last_scrobbled and hit_threshold:
self._log_scrobble(meta)

def _log_now_playing(self, track_meta):
Expand All @@ -205,7 +206,7 @@ def _log_now_playing(self, track_meta):
def _log_scrobble(self, track_meta):
''' Scrobble current track to user's profile. '''

click.echo(u'Scrobbling: {artist} - {title} [{album}]'.format(**track_meta))
click.echo('Scrobbling: {artist} - {title} [{album}]'.format(**track_meta))

for scrobbler in self.scrobblers:
try:
Expand Down Expand Up @@ -386,7 +387,7 @@ def main(config, wizard):
# If we have any devices missing, periodically try to connect to them
if retry_missing and missing and i % RECONNECT_INTERVAL == 0:
click.echo('Retrying missing devices: %s' % ', '.join(missing))
available = pychromecast.get_chromecasts(tries=1, retry_wait=0.01)
available = pychromecast.get_chromecasts(tries=1)

new_devices, missing = connect_to_devices(config, missing, available)
listeners.extend(new_devices)
Expand Down
22 changes: 18 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
import sys
from setuptools import setup


# Be verbose about Python < 3.4 being deprecated.
if sys.version_info < (3, 4):
print('\n' * 3 + '*' * 64)
print('lastcast requires Python 3.4+, and might be broken if run with\n'
'this version of Python.')
print('*' * 64 + '\n' * 3)


setup(
name='lastcast',
version='0.7.0',
version='1.0.0',
description='Scrobble music to last.fm from Chromecast.',
author='Erik Price',
url='https://github.com/erik/lastcast',
Expand All @@ -14,10 +23,15 @@
],
},
license='MIT',
classifiers=[
"Programming Language :: Python",
"Programming Language :: Python :: 3",
"Operating System :: OS Independent",
],
install_requires=[
'PyChromecast==1.0.3',
'click==6.2',
'PyChromecast==2.0.0',
'click==6.7',
'pylast==1.7.0',
'toml==0.9.1',
'toml==0.9.4',
]
)

0 comments on commit 34a7c7a

Please sign in to comment.