Choggbuster/dvdread.py

43 lines
1.4 KiB
Python
Raw Normal View History

import cffi
import os
import functools
import binascii
from datetime import timedelta
def loadlib(dll_path,*includes,**kwargs):
ffi = cffi.FFI()
for include in includes:
ffi.cdef(open(include).read(),**kwargs)
return ffi,ffi.dlopen(dll_path)
class DVDRead(object):
def __init__(self,path):
self.dvd=None
self.ffi,self.lib = loadlib("libdvdread-8.dll",
"dvd_types.h",
"dvd_reader.h",
"ifo_types.h",
"ifo_read.h",
"ifo_print.h",
"nav_types.h",
"nav_read.h",
"nav_print.h")
self.path=path
self.titles={}
self.open(path)
def __del__(self):
if self.dvd:
self.lib.DVDClose(self.dvd)
def open(self,path):
# self.dvd_css=self.css_lib.dvdcss_open()
self.dvd=self.lib.DVDOpen(bytes(path,"utf8"))
vol_id=self.ffi.new("unsigned char[]",32)
self.lib.DVDDiscID(self.dvd,vol_id)
self.disc_id=str(binascii.hexlify(self.ffi.buffer(vol_id,16)[:]),"utf8")
self.lib.DVDUDFVolumeInfo(self.dvd,vol_id,32,self.ffi.NULL,0)
self.udf_disc_name=str(self.ffi.string(vol_id),"utf8")
self.lib.DVDISOVolumeInfo(self.dvd,vol_id,32,self.ffi.NULL,0)
self.iso_disc_name=str(self.ffi.string(vol_id),"utf8")
self.ffi.release(vol_id)