Conoscere il numero di titoli e di capitoli presenti in un DVD con l'API di libdvdread4
Da Gambas-it.org - Wikipedia.
Versione del 7 ott 2013 alle 02:37 di Vuott (Discussione | contributi)
Usando alcune poche funzioni esterne della libreria "libdvdread4" è possibile conoscere quanti titoli e quanti capitoli sono presenti un un disco DVD video.
Per fruire delle risorse di libdvdread4 bisognerà avere installata nel sistema la libreria attualmente: "libdvdread.so.4.1.2".
Mostriamo di seguito un creve codice esemplificativo:
Private a As Byte = 1 Library "libdvdread:4.1.2" ' dvd_reader_t* DVDOpen (const char *) ' Opens a block device of a DVD-ROM file, or an image file, or a directory name for a mounted DVD or HD copy of a DVD. Private Extern DVDOpen(fldvd As String) As Pointer ' ifo_handle_t * ifoOpen (dvd_reader_t *dvd, int title) ' Opens an IFO and reads in all the data for the IFO file corresponding to the given title. Private Extern ifoOpen(dvd_reader_t As Pointer, title As Integer) As Pointer 'Ifo_handle_t ' dvd_file_t * DVDOpenFile (dvd_reader_t *, int, dvd_read_domain_t) ' Opens a file on the DVD given the title number and domain. Private Extern DVDOpenFile(dvd_reader_t As Pointer, dvdI As Integer, dvd_readI As Integer) As Pointer ' void ifoClose(ifo_handle_t * ifofile) ' Cleans up the IFO information. Private Extern ifoClose(ifop As Pointer) ' void DVDCloseFile(dvd_file_t * ) ' Closes a file and frees the associated structure. Private Extern DVDCloseFile(dvd_file_t As Pointer) ' void DVDClose (dvd_reader_t *dvd) ' Closes and cleans up the DVD reader object. Private Extern DVDClose(dvd_reader_t As Pointer) Private Enum DVD_READ_INFO_FILE = 0, DVD_READ_INFO_BACKUP_FILE, DVD_READ_MENU_VOBS, DVD_READ_TITLE_VOBS Public Sub Main() Dim dvd, dvdR, p As Pointer Dim b As Byte Dim sh, s1, s2 As Short Dim pstm As Stream ' Apre il disco: dvd = DVDOpen("/dev/dvd") If IsNull(dvd) Then Error.Raise("Impossibile aprire il DVD: nessun dvd trovato !") dvdR = DVDOpenFile(dvd, 0, DVD_READ_MENU_VOBS) If IsNull(dvdR) Then Error.Raise("Impossibile aprire il file !") p = Alloc(2048) ' Carica il gestore video per cercare informazioni relative ai titoli sul disco: p = ifoOpen(dvd, 0) If IsNull(p) Then Error.Raise("Impossibile aprire il gestore video e leggere il file principale IFO !") ' Dereferenziamo il "puntatore" mediante i "Memory-Stream" per estrapolare i dati ricercati: pstm = Memory p For Read Seek #pstm, 1184 Read #pstm, s1 Seek #pstm, 1218 Read #pstm, s2 If s1 + s2 > 0 Then Print "\n\nTitoli presenti: "; s1 Print "\nTitolo Capitoli" For sh = 1218 To ((s1 - 1) * 12) + 1218 Step 12 Seek #pstm, sh Read #pstm, b Print a, "", b Inc a Next Else Seek #pstm, 1200 Read #pstm, s1 Print "\n\nTitoli presenti: "; s1 Print "\nTitolo Capitoli" For sh = 1234 To ((s1 - 1) * 12) + 1234 Step 12 Seek #pstm, sh Read #pstm, b Print a, "", b Inc a Next Endif Print ' Va in chiusura: ifoClose(p) DVDCloseFile(dvdR) DVDClose(dvd) End