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 5: Riga 5:
  
 
Mostriamo di seguito un breve codice esemplificativo:
 
Mostriamo di seguito un breve codice esemplificativo:
  '''Private''' a As Byte
+
  Library "libdvdread:4.1.2"
 
 
   
 
   
  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
 
   
 
   
 
  <FONT color=gray>' ''dvd_reader_t* DVDOpen (const char *)''
 
  <FONT color=gray>' ''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.''</font>
 
  ' ''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.''</font>
  '''Private''' Extern DVDOpen(fldvd As String) As Pointer
+
  Private Extern DVDOpen(fldvd As String) As Pointer
 
   
 
   
 
  <FONT color=gray>' ''ifo_handle_t * ifoOpen (dvd_reader_t *dvd, int title)''
 
  <FONT color=gray>' ''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.''</font>
 
  ' ''Opens an IFO and reads in all the data for the IFO file corresponding to the given title.''</font>
  '''Private''' Extern ifoOpen(dvd_reader_t As Pointer, title As Integer) As Pointer    'Ifo_handle_t
+
  Private Extern ifoOpen(dvd_reader_t As Pointer, title As Integer) As Pointer    'Ifo_handle_t
 
   
 
   
 
  <FONT color=gray>' ''dvd_file_t * DVDOpenFile (dvd_reader_t *, int, dvd_read_domain_t)''
 
  <FONT color=gray>' ''dvd_file_t * DVDOpenFile (dvd_reader_t *, int, dvd_read_domain_t)''
 
  ' ''Opens a file on the DVD given the title number and domain.''</font>
 
  ' ''Opens a file on the DVD given the title number and domain.''</font>
  '''Private''' Extern DVDOpenFile(dvd_reader_t As Pointer, dvdI As Integer, dvd_readI As Integer) As Pointer
+
  Private Extern DVDOpenFile(dvd_reader_t As Pointer, dvdI As Integer, dvd_readI As Integer) As Pointer
 
   
 
   
 
  <FONT color=gray>' ''void ifoClose(ifo_handle_t * ifofile)''
 
  <FONT color=gray>' ''void ifoClose(ifo_handle_t * ifofile)''
 
  ' ''Cleans up the IFO information.''</font>
 
  ' ''Cleans up the IFO information.''</font>
  '''Private''' Extern ifoClose(ifop As Pointer)
+
  Private Extern ifoClose(ifop As Pointer)
 
   
 
   
 
  <FONT color=gray>' ''void DVDCloseFile(dvd_file_t * )''
 
  <FONT color=gray>' ''void DVDCloseFile(dvd_file_t * )''
 
  ' ''Closes a file and frees the associated structure.''</font>
 
  ' ''Closes a file and frees the associated structure.''</font>
  '''Private''' Extern DVDCloseFile(dvd_file_t As Pointer)
+
  Private Extern DVDCloseFile(dvd_file_t As Pointer)
 
   
 
   
 
  <FONT color=gray>' ''void DVDClose (dvd_reader_t *dvd)''
 
  <FONT color=gray>' ''void DVDClose (dvd_reader_t *dvd)''
 
  ' ''Closes and cleans up the DVD reader object.''</font>
 
  ' ''Closes and cleans up the DVD reader object.''</font>
  '''Private''' Extern DVDClose(dvd_reader_t As Pointer)
+
  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
 
 
   
 
   
 
   
 
   
Riga 41: Riga 37:
 
   
 
   
 
   Dim dvd, dvdR, p As Pointer
 
   Dim dvd, dvdR, p As Pointer
   Dim b As Byte
+
   Dim a, b As Byte
 
   Dim sh, s1, s2 As Short
 
   Dim sh, s1, s2 As Short
 
   Dim pstm As Stream
 
   Dim pstm As Stream
+
 
 
 
  <FONT color=gray>' ''Apre il disco:''</font>
 
  <FONT color=gray>' ''Apre il disco:''</font>
    dvd = DVDOpen("/dev/dvd")
+
  dvd = DVDOpen("/dev/dvd")
    If IsNull(dvd) Then Error.Raise("Impossibile aprire il DVD: nessun dvd trovato !")
+
  If dvd = 0 Then Error.Raise("Impossibile aprire il DVD: nessun dvd trovato !")
   
 
 
      
 
      
    dvdR = DVDOpenFile(dvd, 0, DVD_READ_MENU_VOBS)
+
  dvdR = DVDOpenFile(dvd, 0, DVD_READ_MENU_VOBS)
    If IsNull(dvdR) Then Error.Raise("Impossibile aprire il file !")
+
  If dvdR = 0 Then Error.Raise("Impossibile aprire il file !")
   
 
   
 
    p = Alloc(2048)
 
 
        
 
        
 
  <FONT color=gray>' ''Carica il gestore video per cercare informazioni relative ai titoli sul disco:''</font>
 
  <FONT color=gray>' ''Carica il gestore video per cercare informazioni relative ai titoli sul disco:''</font>
    p = ifoOpen(dvd, 0)
+
  p = ifoOpen(dvd, 0)
    If IsNull(p) 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" mediante i "Memory-Stream" per estrapolare i dati ricercati:''</font>
 
  <FONT color=gray>' ''Dereferenziamo il "puntatore" mediante i "Memory-Stream" per estrapolare i dati ricercati:''</font>
    pstm = Memory p For Read
+
  pstm = Memory p For Read
   
+
   
    Seek #pstm, 1184
+
  Seek #pstm, 1184
    Read #pstm, s1
+
  Read #pstm, s1
    Seek #pstm, 1218
+
  Seek #pstm, 1218
    Read #pstm, s2
+
  Read #pstm, s2
+
 
    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 sh = 1218 To ((s1 - 1) * 12) + 1218 Step 12
+
    For sh = 1218 To ((s1 - 1) * 12) + 1218 Step 12
        Inc a
+
      Inc a
        Seek #pstm, sh
+
      Seek #pstm, sh
        Read #pstm, b
+
      Read #pstm, b
        Print a, "", b
+
      Print a; "               "; b
      Next
+
    Next
    Else
+
  Else
      Seek #pstm, 1200
+
    Seek #pstm, 1200
      Read #pstm, s1
+
    Read #pstm, s1
      Print "\n\nTitoli presenti: "; s1
+
    Print "\n\nTitoli presenti: "; s1
      Print "\nTitolo          Capitoli"
+
    Print "\nTitolo          Capitoli"
      For sh = 1234 To ((s1 - 1) * 12) + 1234 Step 12
+
    For sh = 1234 To ((s1 - 1) * 12) + 1234 Step 12
        Inc a
+
      Inc a
        Seek #pstm, sh
+
      Seek #pstm, sh
        Read #pstm, b
+
      Read #pstm, b
        Print a, "", b
+
      Print a; "               "; b
      Next
+
    Next
    Endif
+
  Endif
    Print
+
  Print
 
   
 
   
 +
 
 
  <FONT color=gray>' ''Va in chiusura:''</font>
 
  <FONT color=gray>' ''Va in chiusura:''</font>
    ifoClose(p)
+
  ifoClose(p)
    DVDCloseFile(dvdR)
+
  DVDCloseFile(dvdR)
    DVDClose(dvd)
+
  DVDClose(dvd)
 
      
 
      
 
  '''End'''
 
  '''End'''
 +
  
  
  
 
=Riferimenti=
 
=Riferimenti=
* [http://code.mythtv.org/doxygen/dvd__reader_8c.html Il sito del API di dvdread4]
+
* http://code.mythtv.org/doxygen/dvd__reader_8c.html

Versione delle 18:31, 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 sh, s1, s2 As Short
 Dim pstm As Stream
  
' Apre il disco:
  dvd = DVDOpen("/dev/dvd")
  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" 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
      Inc a
      Seek #pstm, sh
      Read #pstm, b
      Print a; "               "; b
    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
      Inc a
      Seek #pstm, sh
      Read #pstm, b
      Print a; "               "; b
    Next
  Endif
  Print

  
' Va in chiusura:
  ifoClose(p)
  DVDCloseFile(dvdR)
  DVDClose(dvd)
   
End



Riferimenti