1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60
|
# This file contains some code to test the DAAPClient as stand-alone application.
import sys
import logging
from .client import DAAPClient
log = logging.getLogger(__name__)
def main():
connection = DAAPClient()
if len(sys.argv) > 1:
host = sys.argv[1]
else:
host = "localhost"
if len(sys.argv) > 2:
port = sys.argv[2]
else:
port = 3689
logging.basicConfig(
level=logging.DEBUG, format='%(asctime)s %(levelname)s %(message)s'
)
try:
# do everything in a big try, so we can disconnect at the end
connection.connect(host, port)
# auth isn't supported yet. Just log in
session = connection.login()
library = session.library()
log.debug("Library name is `%r`", library.name)
tracks = library.tracks()
# demo - save the first track to disk
# print("Saving %s by %s to disk as 'track.mp3'"%(tracks[0].name, tracks[0].artist))
# tracks[0].save("track.mp3")
if len(tracks) > 0:
tracks[0].atom.printTree()
else:
print('No Tracks')
session.update()
print(session.revision)
finally:
# this here, so we logout even if there's an error somewhere,
# or itunes will eventually refuse more connections.
print("--------------")
try:
session.logout()
except Exception:
pass
if __name__ == '__main__':
main()
|