Portal    Foro    Buscar    FAQ    Registrarse    Conectarse


Publicar nuevo tema  Responder al tema 
Página 1 de 1
 
 
Obtener Hash De OpenSubtites De Un Video
Autor Mensaje
Responder citando   Descargar mensaje  
Mensaje Obtener Hash De OpenSubtites De Un Video 
 
Hola, estoy trabajando en un cliente de Opensubtitles y en una parte pide generar el hash del vídeo, ellos proporcionan varios códigos de ejemplo pero ninguno de gambas, así que me tocó crearlo a partir de un ejemplo que tenían en PHP, espero que le sirva de ayuda a alguien más.

Public Function getHash(Filename As String) As String
    Dim hFile As File
    Dim fSize As Long
    Dim tmpHash As New Long[]
    Dim i As Integer
    Dim sText As String
    Dim tmpShort As New Variant[]
    Dim Offset As Long
    
    hFile = Open Filename For Input
    hFile.ByteOrder = gb.LittleEndian
    fSize = Stat(Filename).Size
    tmpHash.Add(fsize And 65535)
    tmpHash.Add((Shr(fsize, 16)) And 65535)
    tmpHash.Add(0)
    tmpHash.Add(0)
    
    For i = 0 To 8191
        tmpShort.Clear
        sText = Read #hFile, 2
        tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
        sText = Read #hFile, 2
        tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
        sText = Read #hFile, 2
        tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
        sText = Read #hFile, 2
        tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
        
        tmpHash = AddUINT64(tmpHash, tmpShort)
    Next
    
    Offset = fSize - 65536
    Seek #hFile, IIf(Offset > 0, Offset, 0)
    For i = 0 To 8191
        tmpShort.Clear
        sText = Read #hFile, 2
        tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
        sText = Read #hFile, 2
        tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
        sText = Read #hFile, 2
        tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
        sText = Read #hFile, 2
        tmpShort.Add(IIf(Short@(sText) >= 0, Short@(sText), (Short@(sText) + 65536)))
        
        tmpHash = AddUINT64(tmpHash, tmpShort)
    Next
    hFile.Close()
    
    Return LCase(Hex(tmpHash[3]) & Hex(tmpHash[2]) & Hex(tmpHash[1]) & Hex(tmpHash[0]))
End

Private Function AddUINT64(Hash As Variant[], tmpShort As Variant[]) As Variant[]
    Dim Result As New Variant[]
    Dim Carry As Integer = 0
    Dim i As Integer
    
    Result = [0, 0, 0, 0]
    
    For i = 0 To 3
        If (Hash[i] + tmpShort[i] + Carry) > 65535 Then
            Result[i] = (Hash[i] + tmpShort[i] + Carry) And 65535
            Carry = 1
        Else
            Result[i] = (Hash[i] + tmpShort[i] + Carry)
            Carry = 0
        Endif
    Next
    
    Return Result
End
 

 



 
willicab - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Obtener Hash De OpenSubtites De Un Video 
 
gracias seguramente alguien que le guste el tema películas le sera muy útil.

que tal si te tomas un poquito mas de trabajo y haces un ejemplo de uso y lo subes?

saludos.
 




===================
Software libre, programación libre, vida libre es la Public function Libertad()as Invendible
Proyectos: VisorRV1960,Taller2015,Tanteador
https://sourceforge.net/u/v3ctor-full/profile/
Blog: http://novatocodegambas.blogspot.com.uy/
 
v3ctor - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Responder citando   Descargar mensaje  
Mensaje Re: Obtener Hash De OpenSubtites De Un Video 
 
Gracias por la sugerencia, en estos momentos estoy trabajando en un programa donde lo uso, cuando tenga una versión mínimamente estable publicaré el código
 



 
willicab - Ver perfil del usuarioEnviar mensaje privadoVisitar sitio web del usuario 
Volver arribaPágina inferior
Mostrar mensajes anteriores:    
 
OcultarTemas parecidos
Tema Autor Foro Respuestas último mensaje
No hay nuevos mensajes Video-urgente jolubae Controles/Librerías/Componentes 16 Jueves, 19 Agosto 2010, 21:17 Ver último mensaje
abarzuaf
No hay nuevos mensajes Reproducir Video mgonzalez Aplicaciones/Fragmentos de Código 0 Viernes, 03 May 2013, 22:20 Ver último mensaje
mgonzalez
No hay nuevos mensajes Un Video Tutorial De GIT guadafan Videotutoriales 7 Jueves, 09 Enero 2014, 00:50 Ver último mensaje
jsbsan
No hay nuevos mensajes Reproductor De Video (Reproduce Y Pausa Vi... jsbsan General 8 Martes, 10 Febrero 2015, 16:16 Ver último mensaje
vuott
 

Publicar nuevo tema  Responder al tema  Página 1 de 1
 

Usuarios navegando en este tema: 0 registrados, 0 ocultos y 1 invitado
Usuarios registrados conectados: Ninguno


 
Lista de permisos
No puede crear mensajes
No puede responder temas
No puede editar sus mensajes
No puede borrar sus mensajes
No puede votar en encuestas
No puede adjuntar archivos
Puede descargar archivos
No puede publicar eventos en el calendario



  

 

cron