Ticket #292: output_download_py_content-encoding.patch

File output_download_py_content-encoding.patch, 1.2 KB (added by flexget, 3 months ago)
  • flexget/plugins/output_download.py

     
    55import logging 
    66import shutil 
    77import filecmp 
     8import zlib 
    89from flexget.plugin import * 
    910from sqlalchemy import Column, String, Integer, DateTime 
    1011from flexget.manager import Base 
     
    176177 
    177178        mimetype = f.headers.gettype() 
    178179 
     180        if f.headers.get('content-encoding') in ('gzip', 'x-gzip', 'deflate'): 
     181            decompressor = zlib.decompressobj(15+32) 
     182        else: 
     183            decompressor = None 
     184 
    179185        # generate temp file, with random md5 sum ..  
    180186        # url alone is not random enough, it has happened that there are two entries with same url 
    181187        import hashlib 
     
    193199        outfile = open(datafile, 'wb') 
    194200        try: 
    195201            while 1: 
    196                 data = f.read(buffer_size) 
     202                if decompressor: 
     203                    data = decompressor.decompress(f.read(buffer_size)) 
     204                else: 
     205                    data = f.read(buffer_size) 
    197206                if not data: 
    198207                    log.debug('wrote file %s' % datafile) 
    199208                    break