Last active
December 14, 2015 22:27
-
-
Save pierrebeaucamp/8839152 to your computer and use it in GitHub Desktop.
Soundcloud Alarm
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# The MIT License (MIT) | |
# | |
# Copyright (c) 2015 Pierre Beaucamp <[email protected]> | |
# | |
# Permission is hereby granted, free of charge, to any person obtaining a copy | |
# of this software and associated documentation files (the "Software"), to deal | |
# in the Software without restriction, including without limitation the rights | |
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | |
# copies of the Software, and to permit persons to whom the Software is | |
# furnished to do so, subject to the following conditions: | |
# | |
# The above copyright notice and this permission notice shall be included in all | |
# copies or substantial portions of the Software. | |
# | |
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | |
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | |
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | |
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | |
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | |
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | |
# SOFTWARE. | |
import os | |
import requests | |
import time | |
import random | |
if __name__ == "__main__": | |
# Let's track the time | |
start_time = time.time() | |
# Turns the Receiver on (ooh, he likes it) | |
os.system("printf '%s\r\n' PO | nc 10.0.0.2 8102") | |
time.sleep(2) | |
os.system("printf '%s\r\n' 06FN | nc 10.0.0.2 8102") | |
# Nulls the Volume | |
for i in range(200): | |
os.system("printf '%s\r\b' VD | nc 10.0.0.2 8102") | |
# Turns it on a nice Volume to wake up | |
for i in range(50): | |
os.system("printf '%s\r\b' VU | nc 10.0.0.2 8102") | |
# Whos favorites are we listening to? | |
users = ['5727592', '8058060'] | |
def playSoundcloud(): | |
# Gets the JSON from Soundcloud | |
url = 'https://api.soundcloud.com/users/' + random.Random(time.time()).choice(users) + '/favorites.json?client_id=f8dc78d527a14157cce82626661b9607' | |
r = requests.get(url) | |
j = r.json() | |
# Plays a Sound | |
os.system('wget ' + j[random.Random(time.time()).randint(0, len(j))]['stream_url'] + '?client_id=f8dc78d527a14157cce82626661b9607 -O - | mplayer -cache 8192 -') | |
while ((time.time() - start_time) < 1800): | |
playSoundcloud() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment