Skip to content

Commit 7d1bc64

Browse files
committed
added pypi package and other stuff :)
1 parent 721f2b3 commit 7d1bc64

File tree

7 files changed

+257
-61
lines changed

7 files changed

+257
-61
lines changed

.gitignore

+88
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# C extensions
7+
*.so
8+
9+
# Distribution / packaging
10+
.Python
11+
env/
12+
build/
13+
develop-eggs/
14+
dist/
15+
downloads/
16+
eggs/
17+
.eggs/
18+
lib/
19+
lib64/
20+
parts/
21+
sdist/
22+
var/
23+
wheels/
24+
*.egg-info/
25+
.installed.cfg
26+
*.egg
27+
28+
# PyInstaller
29+
# Usually these files are written by a python script from a template
30+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
31+
*.manifest
32+
*.spec
33+
34+
# Installer logs
35+
pip-log.txt
36+
pip-delete-this-directory.txt
37+
38+
# Unit test / coverage reports
39+
htmlcov/
40+
.tox/
41+
.coverage
42+
.coverage.*
43+
.cache
44+
nosetests.xml
45+
coverage.xml
46+
*.cover
47+
.hypothesis/
48+
49+
# Translations
50+
*.mo
51+
*.pot
52+
53+
# Django stuff:
54+
*.log
55+
local_settings.py
56+
57+
# Flask stuff:
58+
instance/
59+
.webassets-cache
60+
61+
# Scrapy stuff:
62+
.scrapy
63+
64+
# Sphinx documentation
65+
docs/_build/
66+
67+
# PyBuilder
68+
target/
69+
70+
# Jupyter Notebook
71+
.ipynb_checkpoints
72+
73+
# pyenv
74+
.python-version
75+
76+
# celery beat schedule file
77+
celerybeat-schedule
78+
79+
# SageMath parsed files
80+
*.sage.py
81+
82+
# dotenv
83+
.env
84+
85+
# virtualenv
86+
.venv
87+
venv/
88+
ENV/

__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import autoskip

autoskip/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from . import cli

autoskip/__version__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
__version__ = '1.0.0'

main.py renamed to autoskip/autoskipper.py

+89-61
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,12 @@
44
import dbus
55
import asyncio
66
import os
7-
import sys
7+
import signal
88
import time
99
import json
1010
import threading
1111
from colorama import Fore, Back, Style # Colors in terminal
1212

13-
loop = asyncio.get_event_loop()
14-
1513
DBusGMainLoop(set_as_default=True)
1614

1715

@@ -60,8 +58,6 @@ def create(self, artist):
6058
return self.artists[artist]
6159

6260
def write(self):
63-
# Cleanup
64-
print(self.artists)
6561
# fixed_artists = {i: self.artists[i] for i in self.artists if self.artists[i] != self.default}
6662
with open(self.file, "w") as f:
6763
json.dump(self.artists, f, indent=4)
@@ -89,9 +85,10 @@ def do_nothing(*args, **kwargs):
8985

9086

9187
def skip():
88+
print(Fore.RED + 'Skipped!' + Style.RESET_ALL, end=' ')
9289
get_info = dbus.SessionBus()
9390
spotify_bus = get_info.get_object("org.mpris.MediaPlayer2.spotify", "/org/mpris/MediaPlayer2")
94-
# status = spotify_bus.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus', dbus_interface='org.freedesktop.DBus.Properties')
91+
status = spotify_bus.Get('org.mpris.MediaPlayer2.Player', 'PlaybackStatus', dbus_interface='org.freedesktop.DBus.Properties')
9592
spotify_bus.Next(dbus_interface='org.mpris.MediaPlayer2.Player', reply_handler=do_nothing, error_handler=do_nothing)
9693

9794

@@ -135,67 +132,82 @@ def song_print(song):
135132
skip()
136133

137134

138-
def command_handler(command):
135+
def toggle():
139136
config = Config()
137+
138+
if config.autoskip:
139+
print(Fore.RED + 'Autoskip disabled' + Style.RESET_ALL, end=' ')
140+
else:
141+
print(Fore.GREEN + 'Autoskip enabled' + Style.RESET_ALL, end=' ')
142+
config.autoskip = not config.autoskip
143+
config.write()
144+
145+
146+
def bls():
140147
song = Song()
141148
song_config = SongConfig()
142149

143-
def toggle():
144-
if config.autoskip:
145-
print(Fore.RED + 'Autoskip disabled' + Style.RESET_ALL, end=' ')
146-
else:
147-
print(Fore.GREEN + 'Autoskip enabled' + Style.RESET_ALL, end=' ')
148-
config.autoskip = not config.autoskip
149-
config.write()
150-
151-
def bls():
152-
current_song = song_config.create(song.artist)
153-
if song.title in current_song["blacklisted_songs"]:
154-
current_song["blacklisted_songs"].remove(song.title)
155-
text = f'{Fore.RED}Removed{Style.RESET_ALL} "{song.title}" from blacklisted songs'
156-
else:
157-
current_song["blacklisted_songs"].append(song.title)
158-
text = f'{Fore.GREEN}Added{Style.RESET_ALL} "{song.title}" to blacklisted songs'
159-
skip()
150+
current_song = song_config.create(song.artist)
151+
if song.title in current_song["blacklisted_songs"]:
152+
current_song["blacklisted_songs"].remove(song.title)
153+
text = f'{Fore.RED}Removed{Style.RESET_ALL} "{song.title}" from blacklisted songs'
154+
else:
155+
current_song["blacklisted_songs"].append(song.title)
156+
text = f'{Fore.GREEN}Added{Style.RESET_ALL} "{song.title}" to blacklisted songs'
157+
skip()
160158

161-
print(text, end=' ')
162-
song_config.write()
159+
print(text, end=' ')
160+
song_config.write()
163161

164-
def bla():
165-
current_song = song_config.create(song.artist)
166-
if current_song["blacklisted"]:
167-
text = f'{Fore.RED}Removed{Style.RESET_ALL} "{song.artist}" from blacklisted artists'
168-
else:
169-
text = f'{Fore.GREEN}Added{Style.RESET_ALL} "{song.title}" to blacklisted artists'
170-
skip()
171-
172-
current_song["blacklisted"] = not current_song["blacklisted"]
173-
print(text, end=' ')
174-
song_config.write()
175-
176-
def wls():
177-
current_song = song_config.create(song.artist)
178-
if song.title in current_song["whitelisted_songs"]:
179-
current_song["whitelisted_songs"].remove(song.title)
180-
text = f'{Fore.RED}Removed{Style.RESET_ALL} "{song.title}" from whitelisted songs'
181-
else:
182-
current_song["whitelisted_songs"].append(song.title)
183-
text = f'{Fore.GREEN}Added{Style.RESET_ALL} "{song.title}" to whitelisted songs'
184162

185-
print(text, end=' ')
186-
song_config.write()
163+
def bla():
164+
song = Song()
165+
song_config = SongConfig()
166+
167+
current_song = song_config.create(song.artist)
168+
if current_song["blacklisted"]:
169+
text = f'{Fore.RED}Removed{Style.RESET_ALL} "{song.artist}" from blacklisted artists'
170+
else:
171+
text = f'{Fore.GREEN}Added{Style.RESET_ALL} "{song.title}" to blacklisted artists'
172+
skip()
187173

188-
def wla():
189-
current_song = song_config.create(song.artist)
190-
if current_song["whitelisted"]:
191-
text = f'{Fore.RED}Removed{Style.RESET_ALL} "{song.artist}" from whitelisted artists'
192-
else:
193-
text = f'{Fore.GREEN}Added{Style.RESET_ALL} "{song.title}" to whitelisted artists'
174+
current_song["blacklisted"] = not current_song["blacklisted"]
175+
print(text, end=' ')
176+
song_config.write()
194177

195-
current_song["whitelisted"] = not current_song["whitelisted"]
196-
print(text, end=' ')
197-
song_config.write()
198178

179+
def wls():
180+
song = Song()
181+
song_config = SongConfig()
182+
183+
current_song = song_config.create(song.artist)
184+
if song.title in current_song["whitelisted_songs"]:
185+
current_song["whitelisted_songs"].remove(song.title)
186+
text = f'{Fore.RED}Removed{Style.RESET_ALL} "{song.title}" from whitelisted songs'
187+
else:
188+
current_song["whitelisted_songs"].append(song.title)
189+
text = f'{Fore.GREEN}Added{Style.RESET_ALL} "{song.title}" to whitelisted songs'
190+
191+
print(text, end=' ')
192+
song_config.write()
193+
194+
195+
def wla():
196+
song = Song()
197+
song_config = SongConfig()
198+
199+
current_song = song_config.create(song.artist)
200+
if current_song["whitelisted"]:
201+
text = f'{Fore.RED}Removed{Style.RESET_ALL} "{song.artist}" from whitelisted artists'
202+
else:
203+
text = f'{Fore.GREEN}Added{Style.RESET_ALL} "{song.title}" to whitelisted artists'
204+
205+
current_song["whitelisted"] = not current_song["whitelisted"]
206+
print(text, end=' ')
207+
song_config.write()
208+
209+
210+
def command_handler(command):
199211
commands = {
200212
't': toggle,
201213
'toggle': toggle,
@@ -212,13 +224,20 @@ def wla():
212224

213225

214226
class InputThread(threading.Thread):
227+
def signal_handler(sig, frame):
228+
# print('\nExiting')
229+
os._exit(1)
230+
231+
# Ctrl + C
232+
signal.signal(signal.SIGINT, signal_handler)
233+
215234
def run(self):
216235
while True:
217236
command = input()
218237
command_handler(command.split(' '))
219238

220239

221-
async def main():
240+
async def main(loop):
222241
# Bad but necessary to prevent rerunning on the same song.
223242
global past_song
224243
config = Config()
@@ -260,12 +279,21 @@ def on_properties_changed(interface_name, changed_properties, invalidated_proper
260279
score = variant.value["xesam:autoRating"].value
261280
song = Song(title, artist, score)
262281
# Comparing objects doesn't work so it compares the dict.
263-
if song.__dict__ != past_song.__dict__:
282+
# != (" ", " ", " ") to prevent skipping when spotify is used on another device and
283+
# metadata cannot be extrected.
284+
if song.__dict__ != past_song.__dict__ and (title, artist, score) != (" ", " ", " "):
264285
past_song = song
265286
song_print(song)
266287

267288
properties.on_properties_changed(on_properties_changed)
268289
await loop.create_future()
290+
input_thread.join()
291+
292+
293+
def run():
294+
loop = asyncio.get_event_loop()
295+
loop.run_until_complete(main(loop))
296+
269297

270-
loop.run_until_complete(main())
271-
input_thread.join()
298+
if __name__ == "__main__":
299+
run()

autoskip/cli.py

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#!/usr/bin/env python3
2+
from . import autoskipper
3+
import argparse
4+
5+
6+
def main():
7+
parser = argparse.ArgumentParser()
8+
parser.add_argument('--toggle', '-t', action='store_const', const=True, help='Toggle autoskipper')
9+
parser.add_argument('--skip', '-s', action='store_const', const=True, help='Skip song')
10+
parser.add_argument('--whitelist-song', '-wls', action='store_const', const=True, help='Toggle whitelist for current song')
11+
parser.add_argument('--whitelist-artist', '-wla', action='store_const', const=True, help='Toggle whitelist for current artist')
12+
parser.add_argument('--blacklist-song', '-bls', action='store_const', const=True, help='Toggle blacklist for current song')
13+
parser.add_argument('--blacklist-artist', '-bla', action='store_const', const=True, help='Toggle blacklist for current artist')
14+
parser.add_argument('--run', '-r', action='store_const', const=True, help='Run CLI')
15+
args = parser.parse_args()
16+
17+
# Could be done with dict, but this is easily read.
18+
if args.whitelist_artist:
19+
autoskipper.wla()
20+
21+
if args.blacklist_artist:
22+
autoskipper.bla()
23+
24+
if args.whitelist_song:
25+
autoskipper.wls()
26+
27+
if args.blacklist_song:
28+
autoskipper.bls()
29+
30+
if args.skip:
31+
autoskipper.skip()
32+
33+
if args.toggle:
34+
autoskipper.toggle()
35+
36+
# Makes a dict of all args used. Checked in order to determine if the program should be run.
37+
fixed_args = {i: args.__dict__[i] for i in args.__dict__ if args.__dict__[i] is not None}
38+
if not fixed_args or args.run:
39+
autoskipper.run()
40+
41+
42+
if __name__ == "__main__":
43+
main()

setup.py

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
#!/usr/bin/env python3
2+
3+
from setuptools import setup, find_packages
4+
import re
5+
import io
6+
7+
with open('README.md', 'r') as f:
8+
long_description = f.read()
9+
10+
with io.open('autoskip/__version__.py', 'rt', encoding='utf8') as f:
11+
version = re.search(r'__version__ = \'(.*?)\'', f.read()).group(1)
12+
13+
setup(
14+
name='spotify-skipper',
15+
version=version,
16+
author='Blatzar',
17+
author_email='blatzar@gmail.com',
18+
description='Blacklist artists and songs, no login needed.',
19+
packages=find_packages(),
20+
url='https://github.com/Blatzar/spotify-skipper',
21+
keywords=['spotify', 'skip'],
22+
install_requires=[
23+
'colorama',
24+
'dbus-python',
25+
'dbus_next',
26+
'asyncio',
27+
'argparse'
28+
],
29+
long_description=long_description,
30+
long_description_content_type='text/markdown',
31+
entry_points={
32+
'console_scripts': ['autoskip=autoskip.cli:main'],
33+
}
34+
)

0 commit comments

Comments
 (0)