Differenze tra le versioni di "Conoscere il numero di titoli e di capitoli presenti in un DVD con l'API di libdvdread4"
Da Gambas-it.org - Wikipedia.
Riga 38: | Riga 38: | ||
Dim dvd, dvdR, p As Pointer | Dim dvd, dvdR, p As Pointer | ||
Dim a, b As Byte | Dim a, b As Byte | ||
− | Dim | + | Dim s1, s2 As Short |
− | Dim | + | Dim i as Integer |
− | <FONT color=gray>' ''Apre il disco | + | <FONT color=gray>' ''Apre il disco. E' necessario individuare l'esatto device !''</font> |
− | dvd = DVDOpen("/dev/dvd") | + | dvd = DVDOpen("/dev/dvd") <FONT color=gray>' ''...oppure in taluni casi potrebbe essere, ad esempio, "/dev/sr0"''</font> |
If dvd = 0 Then Error.Raise("Impossibile aprire il DVD: nessun dvd trovato !") | If dvd = 0 Then Error.Raise("Impossibile aprire il DVD: nessun dvd trovato !") | ||
Riga 52: | Riga 52: | ||
If p = 0 Then Error.Raise("Impossibile aprire il gestore video e leggere il file principale IFO !") | If p = 0 Then Error.Raise("Impossibile aprire il gestore video e leggere il file principale IFO !") | ||
− | <FONT color=gray>' ''Dereferenziamo il "puntatore | + | <FONT color=gray>' ''Dereferenziamo il "puntatore" per estrapolare i dati ricercati:''</font> |
− | + | s1 = Short@(p + 1184) | |
− | + | s2 = Short@(p + 1218) | |
− | + | ||
− | |||
− | |||
− | |||
− | |||
If s1 + s2 > 0 Then | If s1 + s2 > 0 Then | ||
Print "\n\nTitoli presenti: "; s1 | Print "\n\nTitoli presenti: "; s1 | ||
Print "\nTitolo Capitoli" | Print "\nTitolo Capitoli" | ||
− | For | + | For i = 1218 To ((s1 - 1) * 12) + 1218 Step 12 |
Inc a | Inc a | ||
− | + | b = Byte@(p + i) | |
− | |||
Print a; " "; b | Print a; " "; b | ||
Next | Next | ||
Else | Else | ||
− | + | s1 = Short@(p + 1200) | |
− | |||
Print "\n\nTitoli presenti: "; s1 | Print "\n\nTitoli presenti: "; s1 | ||
Print "\nTitolo Capitoli" | Print "\nTitolo Capitoli" | ||
− | For | + | For i = 1234 To ((s1 - 1) * 12) + 1234 Step 12 |
Inc a | Inc a | ||
− | + | b = Byte@(p + i) | |
− | |||
Print a; " "; b | Print a; " "; b | ||
Next | Next |
Versione delle 18:42, 11 apr 2016
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 breve codice esemplificativo:
Library "libdvdread:4.1.2" Private Enum DVD_READ_INFO_FILE = 0, DVD_READ_INFO_BACKUP_FILE, DVD_READ_MENU_VOBS, DVD_READ_TITLE_VOBS ' 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) Public Sub Main() Dim dvd, dvdR, p As Pointer Dim a, b As Byte Dim s1, s2 As Short Dim i as Integer ' Apre il disco. E' necessario individuare l'esatto device ! dvd = DVDOpen("/dev/dvd") ' ...oppure in taluni casi potrebbe essere, ad esempio, "/dev/sr0" If dvd = 0 Then Error.Raise("Impossibile aprire il DVD: nessun dvd trovato !") dvdR = DVDOpenFile(dvd, 0, DVD_READ_MENU_VOBS) If dvdR = 0 Then Error.Raise("Impossibile aprire il file !") ' Carica il gestore video per cercare informazioni relative ai titoli sul disco: p = ifoOpen(dvd, 0) If p = 0 Then Error.Raise("Impossibile aprire il gestore video e leggere il file principale IFO !") ' Dereferenziamo il "puntatore" per estrapolare i dati ricercati: s1 = Short@(p + 1184) s2 = Short@(p + 1218) If s1 + s2 > 0 Then Print "\n\nTitoli presenti: "; s1 Print "\nTitolo Capitoli" For i = 1218 To ((s1 - 1) * 12) + 1218 Step 12 Inc a b = Byte@(p + i) Print a; " "; b Next Else s1 = Short@(p + 1200) Print "\n\nTitoli presenti: "; s1 Print "\nTitolo Capitoli" For i = 1234 To ((s1 - 1) * 12) + 1234 Step 12 Inc a b = Byte@(p + i) Print a; " "; b Next Endif Print ' Va in chiusura: ifoClose(p) DVDCloseFile(dvdR) DVDClose(dvd) End