mirror of
https://github.com/beetbox/beets.git
synced 2025-12-06 08:39:17 +01:00
playing around with very basic iPod support
--HG-- branch : device
This commit is contained in:
parent
ec861e499c
commit
210d4f3af3
2 changed files with 66 additions and 0 deletions
51
beets/device.py
Normal file
51
beets/device.py
Normal file
|
|
@ -0,0 +1,51 @@
|
|||
import gpod
|
||||
import os
|
||||
import sys
|
||||
import socket
|
||||
import locale
|
||||
|
||||
def start_sync(pod):
|
||||
# Make sure we have a version of libgpod with these
|
||||
# iPhone-specific functions.
|
||||
if hasattr(gpod, 'itdb_start_sync'):
|
||||
gpod.itdb_start_sync(pod._itdb)
|
||||
def stop_sync(pod):
|
||||
if hasattr(gpod, 'itdb_stop_sync'):
|
||||
gpod.itdb_stop_sync(pod._itdb)
|
||||
|
||||
def pod_path(name):
|
||||
#FIXME: os.path.expanduser('~') to get $HOME is hacky!
|
||||
return os.path.join(os.path.expanduser('~'), '.gvfs', name)
|
||||
|
||||
def get_pod(path):
|
||||
return gpod.Database(path)
|
||||
|
||||
def add(pod, items):
|
||||
def cbk(db, track, it, total):
|
||||
print 'copying', track
|
||||
start_sync(pod)
|
||||
try:
|
||||
for item in items:
|
||||
track = pod.new_Track()
|
||||
track['userdata'] = {
|
||||
'transferred': 0,
|
||||
'hostname': socket.gethostname(),
|
||||
'charset': locale.getpreferredencoding(),
|
||||
'pc_mtime': os.stat(item.path).st_mtime,
|
||||
}
|
||||
track._set_userdata_utf8('filename', item.path.encode())
|
||||
track['artist'] = item.artist
|
||||
track['title'] = item.title
|
||||
track['BPM'] = item.bpm
|
||||
track['genre'] = item.genre
|
||||
track['album'] = item.album
|
||||
track['cd_nr'] = item.disc
|
||||
track['cds'] = item.disctotal
|
||||
track['track_nr'] = item.track
|
||||
track['tracks'] = item.tracktotal
|
||||
track['tracklen'] = int(item.length * 1000)
|
||||
pod.copy_delayed_files(cbk)
|
||||
finally:
|
||||
pod.close()
|
||||
stop_sync(pod)
|
||||
|
||||
15
bts
15
bts
|
|
@ -176,6 +176,21 @@ class BeetsApp(cmdln.Cmdln):
|
|||
from beets.player.bpd import Server
|
||||
Server(self.lib, host, int(port), password).run()
|
||||
|
||||
def do_dadd(self, subcmd, opts, name, *criteria):
|
||||
"""${cmd_name}: add files to a device
|
||||
|
||||
${cmd_usage}
|
||||
${cmd_option_list}
|
||||
"""
|
||||
q = ' '.join(criteria)
|
||||
if not q.strip(): q = None
|
||||
items = self.lib.items(query=q)
|
||||
|
||||
from beets import device
|
||||
path = device.pod_path(name)
|
||||
pod = device.get_pod(path)
|
||||
|
||||
device.add(pod, items)
|
||||
|
||||
if __name__ == '__main__':
|
||||
app = BeetsApp()
|
||||
|
|
|
|||
Loading…
Reference in a new issue