See the changelog. :)
[rox-ripper.git] / cd_logic.py
bloba761cf3dc515faf6b8eb68f73dd5e39c4a01492c
1 """
2 cd_logic.py
3 Uses the CD library to control the CD and return it's status.
5 Copyright 2003 Ron Kuslak <rds@rdsarts.com>
6 All rights reserved.
8 This program is free software; you can redistribute it and/or modify
9 it under the terms of the GNU General Public License as published by
10 the Free Software Foundation; either version 2 of the License.
12 This program is distributed in the hope that it will be useful
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program; if not, write to the Free Software
19 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 """
21 import CDLow as cd
23 updated = False
25 def set_dev(dev='/dev/cdrom'):
26 """ Changes the CD device. Makes change. Dances poorly. """
27 cd.cd_close()
28 cd.cd.path = str(dev)
29 cd.cd_open()
30 updated = False
31 return
33 def get_disc_id():
34 temp = cd.get_tracks_id()
35 id = temp['id']
36 return int(id[0])
38 def get_cddb_id():
39 temp = cd.get_tracks_id()
40 id = temp['id']
41 return id
43 def get_track_time():
44 min, sec, temp = cd.get_status(1)['rel']
45 return ((min * 60) + sec)
47 def get_track_time_total(track=None):
48 if not track: track = current_track()
49 t1, t2, t3, min, sec, t4, t5, t6 = cd.get_track_length(track)
50 return ((min * 60) + sec)
52 def get_dev():
53 return str(cd.cd.path)
55 def check_dev():
56 # print cd.get_drive_status()
57 try:
58 return cd.get_drive_status()
59 except IOError, err:
60 print "IOError. Passing 0. Error was " + str(err)
61 return -1
63 def total_tracks():
64 #try:
65 return cd.get_tracks_id()['end_t']
66 # return int(cd_info['end_t'])
67 #except :
68 # return 0
69 #excect: # We should not reach here!
70 # print 'ERROR IN cd.py - total_tracks(). Please report this error.'
71 # return
73 def current_track():
74 # try:
75 temp = cd.get_status(1)
76 return int(temp['cur_t'])
77 # except:
78 return -1
79 def update():
80 try:
81 status = cd.get_status()
82 except:
83 status = 0
85 if status == 0:
86 updated = True
88 def get_status():
89 """ Returns CD's playing state. Yes, this is just a wrapper around
90 get_status. DEAL. ;)"""
91 try:
92 status = cd.get_status()
93 except:
94 # print "Error in play_pause"
95 # # TODO: Do something. :P
96 return 0
97 return status
99 def play(track = 1):
100 cd.play(track, total_tracks())
102 def stop():
103 cd.stop()
104 update()
106 def eject():
107 cd.eject()
108 update()
110 def next():
111 """ Advances CD one track, or puts it at track 1 if at last. """
113 next = current_track() + 1
114 last_t = total_tracks()
115 if next < last_t:
116 play(next)
117 else:
118 play(1)
119 update()
120 return 0
122 def prev():
123 prev = current_track() - 1
125 if prev == 0:
126 prev = (total_tracks() - 1)
128 play(prev)
129 update()
130 return 0
132 def pause():
133 cd.pause()
134 update()
136 def jump(seconds):
137 cd.skip(0, seconds)