Differenze tra le versioni di "Estrarre informazioni e TAG da un file OggVorbis con le sole funzioni di Gambas"
Da Gambas-it.org - Wikipedia.
Riga 4: | Riga 4: | ||
'''Public''' Sub Main() | '''Public''' Sub Main() | ||
− | Dim | + | Dim ogg, s As String |
− | + | Dim i, n, c As Integer | |
− | |||
− | Dim i | ||
− | + | ogg = "<FONT color=gray>''/percorso/del/file.ogg''</font>" | |
− | s = File.Load( | + | s = File.Load(ogg) |
− | |||
<FONT color=gray>' ''Verifica se effettivamente è un file .ogg:''</font> | <FONT color=gray>' ''Verifica se effettivamente è un file .ogg:''</font> | ||
If Left(s, 4) <> "OggS" Then Error.Raise("Attenzione ! Il file caricato non è un file OGG !") | If Left(s, 4) <> "OggS" Then Error.Raise("Attenzione ! Il file caricato non è un file OGG !") | ||
− | Print "File | + | Print "File ogg: "; ogg |
− | Print "\nDimensione: | + | Print "\nDimensione: "; Len(s); " byte" |
− | <FONT color=gray>' '' | + | Print "Canali: "; Asc(s, 40) |
− | + | <FONT color=gray>' ''Estrae la frequenza di campionamento:''</font> | |
− | Print "Frequenza | + | Print "Frequenza: "; Val("&" & Estrazione(s, 44)); " hertz" |
− | + | <FONT color=gray>' ''Estrae il bitrate nominale:''</font> | |
− | Print "Bitrate | + | Print "Bitrate "; Val("&" & Estrazione(s, 52)) \ 1000; " Kbps" |
− | i = InStr(s, "vorbis", | + | <FONT color=gray>' ''Individua il secondo testo "vorbis" nel file:''</font> |
− | + | i = InStr(s, "vorbis", InStr(s, "vorbis") + 5) | |
− | |||
− | |||
− | |||
+ | <FONT color=gray>' ''Individua il byte che indica il numero di caratteri che compongono la stringa del "Vendor":''</font> | ||
+ | n = Asc(s, i + 6) | ||
− | + | <FONT color=gray>' ''Avanza con l'indicatore:''</font> | |
− | + | i += 10 | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | <FONT color=gray>' ''Legge la stringa del "Vendor":''</font> | |
− | + | Print "Vendor: "; Mid(s, i, n) | |
− | + | Print "\nCommenti:" | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | <FONT color=gray>' ''Avanza con l'indicatore:''</font> | |
− | + | i += n | |
− | + | ||
− | n = | + | <FONT color=gray>' ''Individua il byte che indica la quantità di "commenti" presenti nel file ogg:''</font> |
− | + | n = Asc(s, i) | |
− | + | If n = 0 Then Quit | |
− | + | <FONT color=gray>' ''Avanza con l'indicatore:''</font> | |
− | + | i += 4 | |
− | + | <FONT color=gray>' ''Individua il byte che indica il numero di caratteri che compongono la stringa del 1° "Commento":''</font> | |
− | + | c = Asc(s, i) | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | <FONT color=gray>' '' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
+ | <FONT color=gray>' ''Legge i "commenti":''</font> | ||
+ | Repeat | ||
+ | <FONT color=gray>' ''Avanza con l'indicatore:''</font> | ||
+ | i += 4 | ||
+ | <FONT color=gray>' ''Legge la stringa di caratteri del "Commento":''</font> | ||
+ | Print Mid(s, i, c) | ||
+ | <FONT color=gray>' ''Avanza con l'indicatore:''</font> | ||
+ | i += c | ||
+ | <FONT color=gray>' ''Individua il byte che indica il numero di caratteri che compongono la stringa del "Commento":''</font> | ||
+ | c = Asc(s, i) | ||
+ | Dec n | ||
+ | Until n = 0 | ||
+ | |||
'''End''' | '''End''' | ||
− | '''Private''' Function | + | '''Private''' Function Estrazione(t As String, byte As Integer) As String |
− | |||
− | |||
− | |||
− | |||
− | + | Dim rit As String | |
− | For | + | Dim n As Integer |
− | + | ||
+ | For n = byte To byte - 3 Step -1 | ||
+ | rit &= Hex(Asc(t, n), 2) | ||
Next | Next | ||
− | |||
− | |||
− | + | Return rit | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
'''End''' | '''End''' | ||
+ | |||
Versione delle 04:14, 6 ago 2018
E' possibile estrarre informazioni generali e TAG da un file OggVorbis con le sole funzioni di Gambas.
Un possibile codice è il seguente:
Public Sub Main() Dim ogg, s As String Dim i, n, c As Integer ogg = "/percorso/del/file.ogg" s = File.Load(ogg) ' Verifica se effettivamente è un file .ogg: If Left(s, 4) <> "OggS" Then Error.Raise("Attenzione ! Il file caricato non è un file OGG !") Print "File ogg: "; ogg Print "\nDimensione: "; Len(s); " byte" Print "Canali: "; Asc(s, 40) ' Estrae la frequenza di campionamento: Print "Frequenza: "; Val("&" & Estrazione(s, 44)); " hertz" ' Estrae il bitrate nominale: Print "Bitrate "; Val("&" & Estrazione(s, 52)) \ 1000; " Kbps" ' Individua il secondo testo "vorbis" nel file: i = InStr(s, "vorbis", InStr(s, "vorbis") + 5) ' Individua il byte che indica il numero di caratteri che compongono la stringa del "Vendor": n = Asc(s, i + 6) ' Avanza con l'indicatore: i += 10 ' Legge la stringa del "Vendor": Print "Vendor: "; Mid(s, i, n) Print "\nCommenti:" ' Avanza con l'indicatore: i += n ' Individua il byte che indica la quantità di "commenti" presenti nel file ogg: n = Asc(s, i) If n = 0 Then Quit ' Avanza con l'indicatore: i += 4 ' Individua il byte che indica il numero di caratteri che compongono la stringa del 1° "Commento": c = Asc(s, i) ' Legge i "commenti": Repeat ' Avanza con l'indicatore: i += 4 ' Legge la stringa di caratteri del "Commento": Print Mid(s, i, c) ' Avanza con l'indicatore: i += c ' Individua il byte che indica il numero di caratteri che compongono la stringa del "Commento": c = Asc(s, i) Dec n Until n = 0 End Private Function Estrazione(t As String, byte As Integer) As String Dim rit As String Dim n As Integer For n = byte To byte - 3 Step -1 rit &= Hex(Asc(t, n), 2) Next Return rit End