/usr/lib/python3/dist-packages/dvdvideo/volume.py is in python3-dvdvideo 0.20140413.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
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 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 | """
@copyright: 2009 Bastian Blank <waldi@debian.org>
@license: GNU GPL-3
"""
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 3 as
# published by the Free Software Foundation.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import itertools
from .ifo import MalformedIfoHeaderError, VmgIfo, VtsIfo
from .vob import MenuVob, TitleVob
class MalformedVolumePartError(Exception):
pass
class VmgUdf:
def __init__(self, media):
try:
file_ifo = media['VIDEO_TS.IFO']
file_bup = media['VIDEO_TS.BUP']
except KeyError as e:
raise MalformedVolumePartError('Missing file %s' % e.args[0]) from e
file_vob = media.get('VIDEO_TS.VOB')
self.fileset = FileSetUdf(media, file_ifo, file_bup, file_vob)
self.ifo = VmgIfo(self.fileset.ifo)
self.bup = VmgIfo(self.fileset.bup)
self.menu_vob = file_vob and MenuVob(self.fileset.menu_vob)
def dump(self):
return iter(self.fileset)
class VtsUdf:
def __init__(self, media, titleset):
prefix = 'VTS_%02d' % titleset
try:
file_ifo = media['%s_0.IFO' % prefix]
file_bup = media['%s_0.BUP' % prefix]
except KeyError as e:
raise MalformedVolumePartError('Missing file %s' % e.args[0])
file_menu_vob = media.get('%s_0.VOB' % prefix)
file_title_vob = []
for i in range(1, 10):
try:
vob = media['%s_%d.VOB' % (prefix, i)]
file_title_vob.append(vob)
except KeyError:
break
self.fileset = FileSetUdf(media, file_ifo, file_bup, file_menu_vob, file_title_vob)
try:
self.ifo = VtsIfo(self.fileset.ifo)
except MalformedIfoHeaderError:
raise MalformedVolumePartError
try:
self.bup = VtsIfo(self.fileset.bup)
except MalformedIfoHeaderError:
self.bup = None
if file_menu_vob:
self.menu_vob = MenuVob(self.fileset.menu_vob)
else:
self.menu_vob = None
self.title_vob = TitleVob(self.fileset.title_vob)
def dump(self):
return iter(self.fileset)
class FileSetUdf:
class File:
def __init__(self, media, name, location, length):
self._media, self.name, self.location, self.length = media, name, location, length
def __iter__(self):
cur = 0
self.seek(cur)
while cur < self.length:
r = self.read(min(512, self.length - cur))
cur += len(r) // 2048
yield r
def __repr__(self):
return '<%s with name: %r; location: %d; length: %d>' % (
self.__class__.__name__,
self.name,
self.location,
self.length,
)
def _read(self, count):
sector = self._media.tell()
if sector < self.location:
raise RuntimeError
if sector + count > self.location + self.length:
raise RuntimeError
return self._media.read(count)
def _seek(self, offset, **kw):
if offset > self.length:
raise RuntimeError
self._media.seek(self.location + offset, **kw)
class FileIfo(File):
def read(self, count=1):
return self._read(count)
def read_sector(self, offset, count=1):
self.seek(offset)
return self.read(count)
def seek(self, offset):
self._seek(offset)
class FileVob(File):
def read(self, count=1):
try:
return self._read(count)
except IOError:
self._media.seek(self._media.tell() + count)
return bytes(count * 2048)
def seek(self, offset):
self._seek(0, start_encrypted=True)
self._seek(offset)
def __init__(self, media, ifo, bup, menu_vob, title_vob=[]):
input = [ifo, bup]
if menu_vob:
input.insert(1, menu_vob)
input[-1:-1] = title_vob
i = input[0]
j = input[1]
ad_i = i.entry.ad[0]
ad_j = j.entry.ad[0]
location = ad_i.location_absolute
length = ad_j.location_absolute - location
files = [self.FileIfo(media, i.name, location, length)]
for i, j in itertools.zip_longest(input[1:-1], input[2:]):
ad_i = i.entry.ad[0]
ad_j = j.entry.ad[0]
location = ad_i.location_absolute
length = ad_j.location_absolute - location
files.append(self.FileVob(media, i.name, location, length))
i = input[-1]
ad_i = i.entry.ad[0]
location = ad_i.location_absolute
length = files[0].length
files.append(self.FileIfo(media, i.name, location, length))
self.list = files[:]
self.ifo = files.pop(0)
self.bup = files.pop(-1)
if menu_vob:
self.menu_vob = files.pop(0)
else:
self.menu_vob = None
self.title_vob = files
def __iter__(self):
return iter(self.list)
|