MythTV master
track.py
Go to the documentation of this file.
1# Copyright (C) 2013 Johannes Dewender
2#
3# This program is free software: you can redistribute it and/or modify
4# it under the terms of the GNU Lesser General Public License as published by
5# the Free Software Foundation, either version 3 of the License, or
6# (at your option) any later version.
7#
8# This program is distributed in the hope that it will be useful,
9# but WITHOUT ANY WARRANTY; without even the implied warranty of
10# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11# GNU Lesser General Public License for more details.
12#
13# You should have received a copy of the GNU Lesser General Public License
14# along with this program. If not, see <http://www.gnu.org/licenses/>.
15#
16# Please submit bug reports to GitHub:
17# https://github.com/JonnyJD/python-discid/issues
18"""Track class
19"""
20
21from ctypes import c_int, c_void_p, c_char_p
22
23from discid.libdiscid import _LIB
24from discid.util import _decode, _sectors_to_seconds
25
26
27class Track(object):
28 """Track objects are part of the :class:`Disc` class.
29 """
30
31 def __init__(self, disc, number):
32 self._disc = disc
33 self._number = number
34 assert self._disc._handle.value is not None
35
36 def __str__(self):
37 assert self._disc._success
38 return str(self.number)
39
40 _LIB.discid_get_track_offset.argtypes = (c_void_p, c_int)
41 _LIB.discid_get_track_offset.restype = c_int
43 assert self._disc._success
44 return _LIB.discid_get_track_offset(self._disc._handle, self.number)
45
46 _LIB.discid_get_track_length.argtypes = (c_void_p, c_int)
47 _LIB.discid_get_track_length.restype = c_int
49 assert self._disc._success
50 return _LIB.discid_get_track_length(self._disc._handle, self.number)
51
52 try:
53 _LIB.discid_get_track_isrc.argtypes = (c_void_p, c_int)
54 _LIB.discid_get_track_isrc.restype = c_char_p
55 except AttributeError:
56 pass
57 def _get_track_isrc(self):
58 assert self._disc._success
59 if "isrc" in self._disc._requested_features:
60 try:
61 result = _LIB.discid_get_track_isrc(self._disc._handle,
62 self.number)
63 except AttributeError:
64 return None
65 else:
66 return _decode(result)
67 else:
68 return None
69
70
71 @property
72 def number(self):
73 """The track number"""
74 return self._number
75
76 @property
77 def offset(self):
78 """The track offset"""
79 return self._get_track_offset()
80
81 @property
82 def sectors(self):
83 """The track length in sectors"""
84 return self._get_track_length()
85
86 length = sectors
87 """This is an alias for :attr:`sectors`"""
88
89 @property
90 def seconds(self):
91 """Track length in seconds"""
92 return _sectors_to_seconds(self.sectors)
93
94 @property
95 def isrc(self):
96 """The International Standard Recording Code
97
98 This will be `None` when the `"isrc"` feature was not requested
99 or not supported, otherwise this is a :obj:`unicode` or
100 :obj:`str <python:str>` object.
101 """
102 return self._get_track_isrc()
103
104
105# vim:set shiftwidth=4 smarttab expandtab:
def sectors(self)
Definition: track.py:82
def __str__(self)
Definition: track.py:36
def isrc(self)
Definition: track.py:95
def seconds(self)
Definition: track.py:90
def number(self)
Definition: track.py:72
def _get_track_isrc(self)
Definition: track.py:57
def __init__(self, disc, number)
Definition: track.py:31
def _get_track_offset(self)
Definition: track.py:42
def offset(self)
Definition: track.py:77
def _get_track_length(self)
Definition: track.py:48
def _decode(byte_string)
Definition: util.py:36
def _sectors_to_seconds(sectors)
Definition: util.py:46