parameters: (filename)
docstring: Create metadata hash values for mythvideo files
      return a hash value
      return u'' if the was an error with the video file or the video file length was zero bytes
docstring_summary: Create metadata hash values for mythvideo files
      return a hash value
      return u'' if the was an error with the video file or the video file length was zero bytes
docstring_tokens: Create metadata hash values for mythvideo files return a hash value return u if the was an error with the video file or the video file length was zero bytes
function: def hashFile(filename):
      '''Create metadata hash values for mythvideo files
      return a hash value
      return u'' if the was an error with the video file or the video file length was zero bytes
      '''
      # Use the MythVideo hashing protocol when the video is in a storage groups
      if filename[0] != u'/':
          hash_value = mythbeconn.getHash(filename, u'Videos')
          if hash_value == u'NULL':
              return u''
          else:
              return hash_value
  
      # Use a local hashing routine when video is not in a Videos storage group
      # For original code: http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes#Python
      try:
          longlongformat = 'q'  # long long
          bytesize = struct.calcsize(longlongformat)
          f = open(filename, "rb")
          filesize = os.path.getsize(filename)
          hash = filesize
          if filesize < 65536 * 2:    # Video file is too small
                 return u''
          for x in range(65536/bytesize):
                  buffer = f.read(bytesize)
                  (l_value,)= struct.unpack(longlongformat, buffer)
                  hash += l_value
                  hash = hash & 0xFFFFFFFFFFFFFFFF #to remain as 64bit number
          f.seek(max(0,filesize-65536),0)
          for x in range(65536/bytesize):
                  buffer = f.read(bytesize)
                  (l_value,)= struct.unpack(longlongformat, buffer)
                  hash += l_value
                  hash = hash & 0xFFFFFFFFFFFFFFFF
          f.close()
          returnedhash =  "%016x" % hash
          return returnedhash
  
      except(IOError):    # Accessing to this video file caused and error
          return u''
function_tokens: def hashFile ( filename ) : # Use the MythVideo hashing protocol when the video is in a storage groups if filename [ 0 ] != u'/' : hash_value = mythbeconn . getHash ( filename , u'Videos' ) if hash_value == u'NULL' : return u'' else : return hash_value # Use a local hashing routine when video is not in a Videos storage group # For original code: http://trac.opensubtitles.org/projects/opensubtitles/wiki/HashSourceCodes#Python try : longlongformat = 'q' # long long bytesize = struct . calcsize ( longlongformat ) f = open ( filename , "rb" ) filesize = os . path . getsize ( filename ) hash = filesize if filesize < 65536 * 2 : # Video file is too small return u'' for x in range ( 65536 / bytesize ) : buffer = f . read ( bytesize ) ( l_value , ) = struct . unpack ( longlongformat , buffer ) hash += l_value hash = hash & 0xFFFFFFFFFFFFFFFF #to remain as 64bit number f . seek ( max ( 0 , filesize - 65536 ) , 0 ) for x in range ( 65536 / bytesize ) : buffer = f . read ( bytesize ) ( l_value , ) = struct . unpack ( longlongformat , buffer ) hash += l_value hash = hash & 0xFFFFFFFFFFFFFFFF f . close ( ) returnedhash = "%016x" % hash return returnedhash except ( IOError ) : # Accessing to this video file caused and error return u''