#!/usr/bin/env python
# -*- coding: utf-8 -*-
import sys, os
import base64
def getAttribute(Tag):
, ,s = Tag[Tag.find(' id=')+4:]
, ,s = s[s.find('"')+1:]
, ,s = s[:s.find('"')]
, ,return s
def parseBinaryContent(filename):
, ,
# filename = sys.argv[1]
, ,if filename[-4:] == '.fb2':
, , , , dirname = filename[:-4]+'_pic'
, ,else:
, , , , exit()
, ,if not os.path.isdir(dirname):
, , , ,os.mkdir(dirname)
, ,flag = False
, ,bina = False
, ,S = ''
, ,#------------------------
, ,path = os.getcwd()
, ,fin = os.path.join(path, filename)
, ,f = open(fin, 'rb')
, ,d = f.read()
, ,
, ,for n in d:
, , , ,if bina:
, , , , , ,if chr(n) == '<':
, , , , , , , ,print('5')
, , , , , , , ,dd = base64.urlsafe_b64decode(S) #()
, , , , , , , ,hh = open(os.path.join(dirname, name_Pic), 'wb')
, , , , , , , ,hh.write(dd)
, , , , , , , ,hh.close()
, , , , , , , ,bina = False
, , , , , ,else:
, , , , , , , ,S = S + chr(n)
, , , , , ,continue
, , , ,if chr(n) == '<': # начало тега
, , , , , ,
, , , , , ,flag = True
, , , , , ,Tag = ''
, , , ,else:
, , , , , ,if flag:
, , , , , , , ,if chr(n) == '>':
, , , , , , , , , ,
, , , , , , , , , ,flag = False
, , , , , , , , , ,if Tag.find('binary')> -1:
, , , , , , , , , , # print(Tag)
, , , , , , , , , , , ,bina = True
, , , , , , , , , , , ,S = ''
, , , , , , , , , , , ,name_Pic = getAttribute(Tag)
, , , , , , , , , , , ,
, , , , , , , , , , , ,
, , , , , , , ,else:
, , , , , , , , , ,Tag = Tag + chr(n)
, , , , , ,
, , , , , , , ,
parseBinaryContent('Ho.fb2')