Differenze tra le versioni di "Estrarre informazioni e TAG da un file OggVorbis con le sole funzioni di Gambas"
Da Gambas-it.org - Wikipedia.
(6 versioni intermedie di uno stesso utente non sono mostrate) | |||
Riga 2: | Riga 2: | ||
Un possibile codice è il seguente: | Un possibile codice è il seguente: | ||
− | + | Public Sub Main() | |
− | Dim | + | Dim ogg, s As String |
− | Dim | + | Dim i, n, c As Integer |
− | |||
− | |||
− | |||
+ | ogg = "<FONT color=darkgreen>''/percorso/del/file.ogg''</font>" | ||
− | + | s = File.Load(ogg) | |
− | + | <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 !") | |
− | + | Print "File ogg: "; ogg | |
− | + | Print "\nDimensione: "; Len(s); " byte" | |
− | + | Print "Canali: "; Asc(s, 40) | |
− | + | <FONT color=gray>' ''Estrae la frequenza di campionamento:''</font> | |
− | + | Print "Frequenza: "; Val("&" & Estrazione(s, 44)); " hertz" | |
− | + | <FONT color=gray>' ''Estrae il bitrate nominale:''</font> | |
− | <FONT color=gray>' ''Estrae | + | Print "Bitrate "; Val("&" & Estrazione(s, 52)) \ 1000; " Kbps" |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | <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>' '' | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | + | <FONT color=gray>' ''Avanza con l'indicatore:''</font> | |
− | + | i += 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>' ''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 | ||
− | + | Private Function Estrazione(t As String, byte As Integer) As String | |
− | Dim | + | Dim rit As String |
− | Dim | + | Dim n As Integer |
− | + | ||
+ | For n = byte To byte - 3 Step -1 | ||
+ | rit &= Hex(Asc(t, n), 2) | ||
+ | Next | ||
+ | |||
+ | Return rit | ||
− | + | End | |
− | + | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
=Riferimenti= | =Riferimenti= | ||
− | + | * http://www.xiph.org/vorbis/doc/Vorbis_I_spec.html | |
+ | * https://kid3.sourceforge.io/kid3_en.html#tag3 |
Versione attuale delle 04:07, 24 nov 2023
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