more examples
This commit is contained in:
+17
-17
@@ -1,19 +1,12 @@
|
|||||||
import os
|
import os
|
||||||
import requests
|
|
||||||
import logging
|
import logging
|
||||||
|
import requests
|
||||||
# Configuration
|
import time
|
||||||
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"
|
|
||||||
|
|
||||||
MOPIDY_URL = 'http://127.0.0.1:6680/mopidy/rpc'
|
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']
|
MUSIC_EXTENSIONS = ('.aac', '.ac3', '.aiff', '.amr', '.au', '.flac', '.m4a', '.mid', '.mka', '.mp3', '.ogg', '.ra', '.voc', '.wav', '.wma')
|
||||||
HEADERS = { "Content-Type": "application/json" }
|
|
||||||
|
|
||||||
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):
|
def call(method, params=None):
|
||||||
@@ -22,18 +15,19 @@ def call(method, params=None):
|
|||||||
else:
|
else:
|
||||||
json = '{"jsonrpc": "2.0", "id": 1, "method": "' + method + '" , "params": ' + params + '}'
|
json = '{"jsonrpc": "2.0", "id": 1, "method": "' + method + '" , "params": ' + params + '}'
|
||||||
|
|
||||||
response = requests.post(MOPIDY_URL, data=json, headers=HEADERS)
|
response = requests.post(MOPIDY_URL, data=json)
|
||||||
logging.debug(response.text)
|
logging.info(response.text)
|
||||||
|
return response
|
||||||
|
|
||||||
def clear_playlist():
|
def clear_playlist():
|
||||||
call('core.tracklist.clear')
|
call('core.tracklist.clear')
|
||||||
|
|
||||||
def add_uri(filename):
|
def add_uri(filename):
|
||||||
logging.debug('Adding ' + filename)
|
logging.info('Adding ' + filename)
|
||||||
call('core.tracklist.add', '{"uri": "' + filename + '"}')
|
call('core.tracklist.add', '{"uri": "' + filename + '"}')
|
||||||
|
|
||||||
def start_playing():
|
def start_playing():
|
||||||
return True
|
call('core.playback.play')
|
||||||
|
|
||||||
def play_sound(filename):
|
def play_sound(filename):
|
||||||
clear_playlist()
|
clear_playlist()
|
||||||
@@ -51,13 +45,19 @@ def list_files(dir):
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
clear_playlist()
|
||||||
clear_playlist();
|
|
||||||
|
|
||||||
filenames = list_files('/home/tilman/Musik')
|
filenames = list_files('/home/tilman/Musik')
|
||||||
|
|
||||||
for filename in filenames:
|
for filename in filenames:
|
||||||
|
if filename.lower().endswith(MUSIC_EXTENSIONS):
|
||||||
file_uri = 'file://' + filename
|
file_uri = 'file://' + filename
|
||||||
add_uri(file_uri)
|
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