def __init__(self, parent, title): super(MainFrame, self).__init__(parent, title=title, size=(500, 400)) # Set up the menu functionality menubar = wx.MenuBar() filemenu = wx.Menu() menubar.Append(filemenu,"&File") self.SetMenuBar(menubar) # The box sizer that all widgets will fit in vbox = wx.BoxSizer(wx.VERTICAL) # Set up the playlist selection self.selected_playlists = [] itunes = iTunes() self.playlists = [p.name for p in itunes.playlists() if p.is_music_playlist()] self.plbox = wx.CheckListBox(self, 3, choices=self.playlists) self.Bind(wx.EVT_CHECKLISTBOX, self.set_playlists, id=3) # The directory browser dirbrowse = filebrowse.DirBrowseButton(self, labelText='Destination', startDirectory='/Volumes', toolTip='Choose where to sync', changeCallback=self.set_destination, id=2) dirbrowse.SetValue('Choose where to sync') dirbrowse.Disable() # The choice of what to do self.choice = wx.Choice(self, choices=MainFrame.options, id=1) self.Bind(wx.EVT_CHOICE, self.set_choice, id=1) # Our sync button self.sync_button = wx.Button(self, 4, 'Sync') self.Bind(wx.EVT_BUTTON, self.on_sync, id=4) vbox.AddMany([ (dirbrowse, 0, wx.EXPAND|wx.ALL, 5), (self.choice, 0, wx.EXPAND|wx.ALL, 5), #(dirbrowse, 0, wx.EXPAND|wx.ALL, 5), # Set the proportion to 1 because we want the listbox to resize VERTICAL and HORIZONTAL (self.plbox, 1, wx.EXPAND|wx.ALL, 5), (self.sync_button, 0, wx.ALIGN_BOTTOM|wx.ALIGN_RIGHT|wx.ALL, 5) ]) # We're placing a boxsizer inside of a boxsizer so that we can get # a nice 20 pixel border (padding) around all elements. mainbox = wx.BoxSizer(wx.VERTICAL) mainbox.Add(vbox, 1, wx.EXPAND|wx.ALL, 20) # We have a default where all items are checked indexes = [idx for (idx,p) in enumerate(self.playlists)] self.plbox.SetChecked(indexes) self.SetSizer(mainbox) self.Show()
def on_sync(self, event): global destination itunes = iTunes() progress = None print "Destination is: {0}".format(destination) if not destination or destination == 'Choose where to sync': msg = wx.MessageDialog(self, 'You must enter a destination directory first.', "Error", wx.OK|wx.ICON_INFORMATION) msg.ShowModal() msg.Destroy() return else: destination = os.path.join(destination, 'itunes', 'Music') print "Syncing to: {0}".format(destination) if self.choice.GetCurrentSelection() == 0: # First playlist should be the special 'Music' playlist, which has all tracks total_tracks = len(itunes.playlists()[0].tracks) progress = wx.ProgressDialog('Syncing iTunes Tracks', 'Copying track...', maximum=total_tracks, style=0|wx.PD_CAN_ABORT|wx.PD_ESTIMATED_TIME|wx.PD_REMAINING_TIME) # First we want to write all tracks under the Music playlist, but not write that as an m3u file tracks = [t for t in itunes.playlists()[0].tracks if not t.is_protected()] (synced, skipped) = sync_tracks(tracks, progress) if skipped == -1: # They canceled the sync progress return # Next, finish up by writing the playlists m3u files out playlists = [p for p in itunes.playlists() if p.is_music_playlist()] for playlist in playlists: (synced, skipped) = sync_playlist(playlist, progress) if skipped == -1: # Canceled the sync return msg = wx.MessageDialog(self, 'Synced {0} tracks. {1} tracks could not be synced due to DRM'. format(synced, skipped), "Finished!", wx.OK | wx.ICON_INFORMATION) msg.ShowModal() msg.Destroy() if progress: progress.Destroy()
def __init__(self, arguments): 'Main entry point for iTunes-Discogs.' self.arguments = arguments self.config = Config(arguments.home) self.model = Model(self.config, arguments.database) self.itunes = iTunes(self.model, arguments.library) self.discogs = Discogs(self.model, arguments.junk) if arguments.cli: if not arguments.playlist: arguments.playlist = 'Library' for playlist in self.get_playlists().values(): if playlist.Name == arguments.playlist: self._process_playlist(playlist) else: Window(self) self.shutdown()
def GET(self, playlist_id): it = itunes.iTunes() return simplejson.dumps(it.get_tracks(playlist_id))
def GET(self): it = itunes.iTunes() return simplejson.dumps(it.get_playlists())
from flask import (Flask, render_template, make_response, json, send_from_directory, request, abort) from itunes import iTunes app = Flask(__name__) itunes = iTunes() playlist = itunes.get_playlist('Internet Songs') def make_json_response(data): if not isinstance(data, str): data = json.dumps(data) resp = make_response(data) resp.headers['Content-Type'] = 'application/json' return resp @app.route('/') def index(): return render_template('index.html') @app.route('/tracks') def tracks(): tracks = [track.as_dict() for track in playlist.tracks[:20]] return make_json_response(tracks)
import itunes it = itunes.iTunes() playlists = it.get_playlists() tracks = it.get_tracks(playlists[0]["id"]) print tracks
#!/usr/bin/env python # -*- coding: utf-8 -*- import serial from itunes import iTunes print "Arduino iTunes Remote Controller" ser = serial.serial_for_url("/dev/tty.ArduinoBluetooth", 9600, timeout=1) while True: data = ser.readline().strip() if data: print data p = iTunes() if data == "PLAY": p.playpause() elif data == "PREV": p.previous() elif data == "NEXT": p.next() else: try: volume = int(data) except ValueError: pass else: p.volume = volume