more examples
This commit is contained in:
+17
-17
@@ -1,19 +1,12 @@
|
||||
import os
|
||||
import requests
|
||||
import logging
|
||||
|
||||
# Configuration
|
||||
MUSIC_BASE_DIRECTORY = "/home/pi/music/"
|
||||
SOUND_SCANNING = "/home/pi/piplayer2/sounds/scanning.mp3"
|
||||
SOUND_OK = "/home/pi/piplayer2/sounds/ok-05.mp3"
|
||||
SOUND_SCAN_FAIL = "/home/pi/piplayer2/sounds/fail-05.mp3"
|
||||
SOUND_PLAYBACK_ERROR = "/home/pi/piplayer2/sounds/error.mp3"
|
||||
import requests
|
||||
import time
|
||||
|
||||
MOPIDY_URL = 'http://127.0.0.1:6680/mopidy/rpc'
|
||||
MUSIC_EXTENSIONS = ['.aac', '.ac3', '.aiff', '.amr', '.au', '.flac', '.m4a', '.mid', '.mka', '.mp3', '.ogg', '.ra', '.voc', '.wav', '.wma']
|
||||
HEADERS = { "Content-Type": "application/json" }
|
||||
MUSIC_EXTENSIONS = ('.aac', '.ac3', '.aiff', '.amr', '.au', '.flac', '.m4a', '.mid', '.mka', '.mp3', '.ogg', '.ra', '.voc', '.wav', '.wma')
|
||||
|
||||
logging.basicConfig(level=logging.DEBUG, format='%(asctime)s %(levelname)s - %(message)s')
|
||||
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(levelname)s - %(message)s')
|
||||
|
||||
|
||||
def call(method, params=None):
|
||||
@@ -22,18 +15,19 @@ def call(method, params=None):
|
||||
else:
|
||||
json = '{"jsonrpc": "2.0", "id": 1, "method": "' + method + '" , "params": ' + params + '}'
|
||||
|
||||
response = requests.post(MOPIDY_URL, data=json, headers=HEADERS)
|
||||
logging.debug(response.text)
|
||||
response = requests.post(MOPIDY_URL, data=json)
|
||||
logging.info(response.text)
|
||||
return response
|
||||
|
||||
def clear_playlist():
|
||||
call('core.tracklist.clear')
|
||||
|
||||
def add_uri(filename):
|
||||
logging.debug('Adding ' + filename)
|
||||
logging.info('Adding ' + filename)
|
||||
call('core.tracklist.add', '{"uri": "' + filename + '"}')
|
||||
|
||||
def start_playing():
|
||||
return True
|
||||
call('core.playback.play')
|
||||
|
||||
def play_sound(filename):
|
||||
clear_playlist()
|
||||
@@ -51,13 +45,19 @@ def list_files(dir):
|
||||
|
||||
|
||||
|
||||
|
||||
clear_playlist();
|
||||
clear_playlist()
|
||||
|
||||
filenames = list_files('/home/tilman/Musik')
|
||||
|
||||
for filename in filenames:
|
||||
if filename.lower().endswith(MUSIC_EXTENSIONS):
|
||||
file_uri = 'file://' + filename
|
||||
add_uri(file_uri)
|
||||
|
||||
start_playing()
|
||||
|
||||
time.sleep(3)
|
||||
json = call('core.playback.get_time_position').json()
|
||||
print(json['result'])
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user