当前位置: 首页>>代码示例>>Python>>正文


Python File.read方法代码示例

本文整理汇总了Python中mutagen.File.read方法的典型用法代码示例。如果您正苦于以下问题:Python File.read方法的具体用法?Python File.read怎么用?Python File.read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在mutagen.File的用法示例。


在下文中一共展示了File.read方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: main

# 需要导入模块: from mutagen import File [as 别名]
# 或者: from mutagen.File import read [as 别名]
def main():
    # First key: comment in zip file
    zf = zipfile.ZipFile('container.zip', 'r')
    filename = 'tuenti.docx'
    print zf.getinfo(filename).comment
    
    # Extracting:
    zf.extract(filename)
    
    # Second key: hidden in one of the files of the doc
    zf = zipfile.ZipFile(filename, 'r')
    zf.extractall()
    tree = ET.parse('docProps/core.xml')
    root = tree.getroot()
    print root[1].text
    
    # Third key: Lyrics of the mp3
    tag = id3.Tag()
    tag.parse("tuenti.mp3")
    print "KEY3:", tag.lyrics[0].text[1:]
    
    # Fourth key: title of front cover of the mp3
    f = File('tuenti.mp3')
    artwork = f.tags['APIC:'].data
    with open('tuenti.png', 'wb') as img:
        img.write(artwork)
        
    image = Image.open('tuenti.png')
    print image.info['Title']
    
    # Fifth key: subject of the pdf
    data = base64.b64decode(image.info['NextLevel'])
    with open('tuenti.pdf', 'wb') as pdf:
        pdf.write(data)
    with open('tuenti.pdf', 'rb') as pdf:
        parser = PDFParser(pdf)
        doc = PDFDocument(parser)
        print doc.info[0]['Subject'][3::2]
    
    # Sixth key: subtitles of a video in the pdf
    os.system('pdfdetach -saveall tuenti.pdf 2> /dev/null')
    # The key is given as a subtitle, I guess there is a way to read
    # the image and transform it to plain text, but it will take much
    # longer than just copying it by hand
    print('KEY6: XrBV392qT0DqDSCGuGDStdY6_ADKkD_4')
    
    # Seventh key: first line of uuencoded attached file in the video
    # Sorry, it's late and I'm tired of finding python packages
    os.system('mkvextract attachments video.mkv 1:tuenti.txt > /dev/null')
    with open('tuenti.txt', 'r') as f:
        print f.readline()[:-1]
    
    # Eigth key: title of a file in the uudecoded file
    os.system('uudecode tuenti.txt > /dev/null')
    os.system('gzip -cd ramdisk.cpio.gz | cpio -idmv 2> /dev/null')
    for f in os.listdir('.'):
        if f[:4] == 'KEY8':
            filekey = f
    print filekey
    
    # Ninth key: extract the gpg file using the password from filekey
    with open(filekey, 'r') as f:
        password = f.readline()[12:-1]
    gpg = gnupg.GPG()
    with open('LastLevel.txt.gpg', 'r') as f:
        encrypted_string = str(f.read())
    decrypted_data = gpg.decrypt(encrypted_string, passphrase=password)
    print decrypted_data.data.splitlines()[0]
开发者ID:Ferreiros-lab,项目名称:tuentichallenge6,代码行数:70,代码来源:10.py


注:本文中的mutagen.File.read方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。