Advertisement
Masterjun

quine_video.py

Oct 21st, 2021
1,717
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.03 KB | None | 0 0
  1. import zlib
  2. import io
  3.  
  4. WD = 1280
  5. HG = 720
  6. FRMS = 750
  7.  
  8. fcomp0 = b'x\x9c\xed\x95\xcb\x16\x830\x08D\x87\xff\xff\xe9\x9e\xaaL.$Zw\xbah{b*\t\xafa\xa0\x92BO\xae'
  9. fcomp1 = b"'\xbf\x7f\xff\x8f\xafW|\x14\xc6$\xb6\x9al\xdb&\xdfO\xf2\xb9R\xd4\xd8\xd2\xce\xf1\xb2\xceS~Z\x0e=\xa5"
  10. fcomp2 = b'\xcf\xf4\xdfW\xf3\xaf\x18:\xc8\xc2^F^\xc3\x86\x8e\x98mP\xc3\xda\xc8\x07g\xcck\x11w\xb7-\xf8\xe8\xf9\x97'
  11. fcomp3 = b'_-\x1f\xeb\x12o\xe6\xdd0\xf0=\x9b\x12\xa4\xac\xdbY\xfe5(\xe7\x928\x0c\xe9\x1c\x7f\x9alyg\xedd\x1e'
  12. fcomp4 = b")\x08ey\xbe\x81\xfe\x8e?\x0e\xce\xa2f9\x9f4cj\xdc'\xfd\xebY\xb3\xb9\x04\xfe\xf5V`\xaf\xf5-\xfe"
  13. fcomp5 = b'O\xfdD\xe9\xe5\xd9r\xed\x8b\xa0-\xf0n\x9aQ\xack\xf7_z\xbe\xf9\x87\x8c\xd4j]p\x91?p\xeew\x84'
  14. fcomp6 = b'wp/\xef\x9a\x93\x96\xf5\x1e\xc9\x000CX\xffr\x86\x18\x80\xfb\xc8\x896\xf6w\xc6\xecX\xda\xfcx\xc3\xfcW'
  15. fcomp7 = b'\xdb\xbb\x845s\xbf\xdf1\xb8<c\xcf\x00W\xc8\xf0G\xe2z\x0c\xd3\xc42\x8a\xad\\W\xfdW\xb8(\xe0O.'
  16. fcomp8 = b'\xe1>\xeb\x97\xfc\'\xaf\xa6\x0e;\xe1\xbf"gI\x05\xc9<\x98\xb8]\xfd\xdc\xf5_x\xc7\xde\x05^\xa4?y\xb8'
  17. fcomp9 = b'\xc4\xbf\xf0|\x8d\x8bk\x19\xd1l ~c\x01\x1d\xf8\xbf\xc5\xa5\x93\xab\xba:\xfc\xa1\xfb\xfd|\x00)\xdc\x07\xae'
  18. fcomp = fcomp0+fcomp1+fcomp2+fcomp3+fcomp4+fcomp5+fcomp6+fcomp7+fcomp8+fcomp9
  19. funcomp = list(zlib.decompress(fcomp))
  20. font = [[(1-x)*255 for x in funcomp for j in range(3)][i*128*3:(i+1)*128*3] for i in range(24)]
  21.  
  22. def to4(n):
  23.     return [n&0xFF,(n>>8)&0xFF,(n>>16)&0xFF,(n>>24)&0xFF]
  24. def add4(f,n):
  25.     f += to4(n)
  26. def add4s(f,i):
  27.     for n in i:
  28.         add4(f,n)
  29.  
  30. def wrt(f,fourcc,tp,fn,*argv):
  31.     f += list(fourcc)+[0]*4
  32.     i = len(f)
  33.     f += list(tp)
  34.     fn(f,*argv)
  35.     size = len(f)-i
  36.     f[i-4:i] = to4(size)
  37.  
  38. def strh(f):
  39.     f += list(b'vidsZLIB')
  40.     add4s(f,[0,0,0,1,60,0,FRMS,200000,-1,0,0,HG<<16|WD])
  41. def strf(f):
  42.     i = len(f)
  43.     add4s(f,[0,WD,HG,0x180001])
  44.     f += list(b'ZLIB')
  45.     add4s(f,[WD*HG*3,0,0,0,0,4,0x300FF02])
  46.     size = len(f)-i
  47.     f[i:i+4] = to4(size)
  48. def junk(f,n):
  49.     f += [0]*n
  50. def dstr(a,x,y,c):
  51.     xf = (ord(c)%32)*4
  52.     yf = (ord(c)//32)*6
  53.     for i in range(6):
  54.         ai = ((((HG-1)-(y*2*6+i*2))*WD)+x*2*4)*3
  55.         aj = ((((HG-1)-(y*2*6+i*2))*WD)+(x+1)*2*4)*3
  56.         a[ai:aj] = [z for z in font[yf+i][xf*3:(xf+4)*3] for j in range(2)]
  57.         a[ai-WD*3:aj-WD*3] = [z for z in font[yf+i][xf*3:(xf+4)*3] for j in range(2)]
  58. def comp(f,a):
  59.     f += list(zlib.compress(bytes(a)))
  60. def movi(f,s):
  61.     a = [0 for x in range(3*WD*HG)]
  62.     rx = 0
  63.     ry = 0
  64.     cur = 0
  65.     c = " "
  66.     for i in range(FRMS):
  67.         for skip in range(10):
  68.             if cur>=len(s): break
  69.             while True:
  70.                 if s[cur]=="\n" and (ry+1)==HG//(6*2):
  71.                     rx = 0
  72.                     a = [0]*(WD*3*6*2)+a[:-(WD*3*6*2)]
  73.                 elif s[cur]=="\n":
  74.                     rx = 0
  75.                     ry += 1
  76.                 elif s[cur]==" ":
  77.                     rx += 1
  78.                 else:
  79.                     break
  80.                 cur += 1
  81.                 if cur>=len(s): break
  82.             if cur>=len(s): break
  83.             dstr(a,rx,ry,s[cur])
  84.             cur += 1
  85.             rx += 1
  86.         wrt(f,b'00dc',b'',comp,a)
  87.         f += [0]*(len(f)%2)
  88.  
  89. s2 = ("f = []\n"
  90. "wrt(f,b'RIFF',b'AVI ',lambda f: (\n"
  91. "    wrt(f,b'LIST',b'hdrl',lambda f: (\n"
  92. "        wrt(f,b'avih',b'',add4s,[16667,25000,0,0,FRMS,0,1,0x100000,WD,HG,0,0,0,0]),\n"
  93. "        wrt(f,b'LIST',b'strl',lambda f: (\n"
  94. "            wrt(f,b'strh',b'',strh),\n"
  95. "            wrt(f,b'strf',b'',strf),\n"
  96. "            wrt(f,b'JUNK',b'',junk,4120))),\n"
  97. "        wrt(f,b'JUNK',b'',junk,1318))),\n"
  98. "    wrt(f,b'LIST',b'movi',movi,s+chr(34)*3+s+chr(34)*3+chr(10)*2+s2[:-6])))\n"
  99. "with open('quine_video.avi','wb') as file:\n"
  100. "    file.write(bytes(f))\n"
  101. "\n"
  102. "s = r")
  103.  
  104. s = r"""import zlib
  105. import io
  106.  
  107. WD = 1280
  108. HG = 720
  109. FRMS = 750
  110.  
  111. fcomp0 = b'x\x9c\xed\x95\xcb\x16\x830\x08D\x87\xff\xff\xe9\x9e\xaaL.$Zw\xbah{b*\t\xafa\xa0\x92BO\xae'
  112. fcomp1 = b"'\xbf\x7f\xff\x8f\xafW|\x14\xc6$\xb6\x9al\xdb&\xdfO\xf2\xb9R\xd4\xd8\xd2\xce\xf1\xb2\xceS~Z\x0e=\xa5"
  113. fcomp2 = b'\xcf\xf4\xdfW\xf3\xaf\x18:\xc8\xc2^F^\xc3\x86\x8e\x98mP\xc3\xda\xc8\x07g\xcck\x11w\xb7-\xf8\xe8\xf9\x97'
  114. fcomp3 = b'_-\x1f\xeb\x12o\xe6\xdd0\xf0=\x9b\x12\xa4\xac\xdbY\xfe5(\xe7\x928\x0c\xe9\x1c\x7f\x9alyg\xedd\x1e'
  115. fcomp4 = b")\x08ey\xbe\x81\xfe\x8e?\x0e\xce\xa2f9\x9f4cj\xdc'\xfd\xebY\xb3\xb9\x04\xfe\xf5V`\xaf\xf5-\xfe"
  116. fcomp5 = b'O\xfdD\xe9\xe5\xd9r\xed\x8b\xa0-\xf0n\x9aQ\xack\xf7_z\xbe\xf9\x87\x8c\xd4j]p\x91?p\xeew\x84'
  117. fcomp6 = b'wp/\xef\x9a\x93\x96\xf5\x1e\xc9\x000CX\xffr\x86\x18\x80\xfb\xc8\x896\xf6w\xc6\xecX\xda\xfcx\xc3\xfcW'
  118. fcomp7 = b'\xdb\xbb\x845s\xbf\xdf1\xb8<c\xcf\x00W\xc8\xf0G\xe2z\x0c\xd3\xc42\x8a\xad\\W\xfdW\xb8(\xe0O.'
  119. fcomp8 = b'\xe1>\xeb\x97\xfc\'\xaf\xa6\x0e;\xe1\xbf"gI\x05\xc9<\x98\xb8]\xfd\xdc\xf5_x\xc7\xde\x05^\xa4?y\xb8'
  120. fcomp9 = b'\xc4\xbf\xf0|\x8d\x8bk\x19\xd1l ~c\x01\x1d\xf8\xbf\xc5\xa5\x93\xab\xba:\xfc\xa1\xfb\xfd|\x00)\xdc\x07\xae'
  121. fcomp = fcomp0+fcomp1+fcomp2+fcomp3+fcomp4+fcomp5+fcomp6+fcomp7+fcomp8+fcomp9
  122. funcomp = list(zlib.decompress(fcomp))
  123. font = [[(1-x)*255 for x in funcomp for j in range(3)][i*128*3:(i+1)*128*3] for i in range(24)]
  124.  
  125. def to4(n):
  126.    return [n&0xFF,(n>>8)&0xFF,(n>>16)&0xFF,(n>>24)&0xFF]
  127. def add4(f,n):
  128.    f += to4(n)
  129. def add4s(f,i):
  130.    for n in i:
  131.        add4(f,n)
  132.  
  133. def wrt(f,fourcc,tp,fn,*argv):
  134.    f += list(fourcc)+[0]*4
  135.    i = len(f)
  136.    f += list(tp)
  137.    fn(f,*argv)
  138.    size = len(f)-i
  139.    f[i-4:i] = to4(size)
  140.  
  141. def strh(f):
  142.    f += list(b'vidsZLIB')
  143.    add4s(f,[0,0,0,1,60,0,FRMS,200000,-1,0,0,HG<<16|WD])
  144. def strf(f):
  145.    i = len(f)
  146.    add4s(f,[0,WD,HG,0x180001])
  147.    f += list(b'ZLIB')
  148.    add4s(f,[WD*HG*3,0,0,0,0,4,0x300FF02])
  149.    size = len(f)-i
  150.    f[i:i+4] = to4(size)
  151. def junk(f,n):
  152.    f += [0]*n
  153. def dstr(a,x,y,c):
  154.    xf = (ord(c)%32)*4
  155.    yf = (ord(c)//32)*6
  156.    for i in range(6):
  157.        ai = ((((HG-1)-(y*2*6+i*2))*WD)+x*2*4)*3
  158.        aj = ((((HG-1)-(y*2*6+i*2))*WD)+(x+1)*2*4)*3
  159.        a[ai:aj] = [z for z in font[yf+i][xf*3:(xf+4)*3] for j in range(2)]
  160.        a[ai-WD*3:aj-WD*3] = [z for z in font[yf+i][xf*3:(xf+4)*3] for j in range(2)]
  161. def comp(f,a):
  162.    f += list(zlib.compress(bytes(a)))
  163. def movi(f,s):
  164.    a = [0 for x in range(3*WD*HG)]
  165.    rx = 0
  166.    ry = 0
  167.    cur = 0
  168.    c = " "
  169.    for i in range(FRMS):
  170.        for skip in range(10):
  171.            if cur>=len(s): break
  172.            while True:
  173.                if s[cur]=="\n" and (ry+1)==HG//(6*2):
  174.                    rx = 0
  175.                    a = [0]*(WD*3*6*2)+a[:-(WD*3*6*2)]
  176.                elif s[cur]=="\n":
  177.                    rx = 0
  178.                    ry += 1
  179.                elif s[cur]==" ":
  180.                    rx += 1
  181.                else:
  182.                    break
  183.                cur += 1
  184.                if cur>=len(s): break
  185.            if cur>=len(s): break
  186.            dstr(a,rx,ry,s[cur])
  187.            cur += 1
  188.            rx += 1
  189.        wrt(f,b'00dc',b'',comp,a)
  190.        f += [0]*(len(f)%2)
  191.  
  192. s2 = ("f = []\n"
  193. "wrt(f,b'RIFF',b'AVI ',lambda f: (\n"
  194. "    wrt(f,b'LIST',b'hdrl',lambda f: (\n"
  195. "        wrt(f,b'avih',b'',add4s,[16667,25000,0,0,FRMS,0,1,0x100000,WD,HG,0,0,0,0]),\n"
  196. "        wrt(f,b'LIST',b'strl',lambda f: (\n"
  197. "            wrt(f,b'strh',b'',strh),\n"
  198. "            wrt(f,b'strf',b'',strf),\n"
  199. "            wrt(f,b'JUNK',b'',junk,4120))),\n"
  200. "        wrt(f,b'JUNK',b'',junk,1318))),\n"
  201. "    wrt(f,b'LIST',b'movi',movi,s+chr(34)*3+s+chr(34)*3+chr(10)*2+s2[:-6])))\n"
  202. "with open('quine_video.avi','wb') as file:\n"
  203. "    file.write(bytes(f))\n"
  204. "\n"
  205. "s = r")
  206.  
  207. s = r"""
  208.  
  209. f = []
  210. wrt(f,b'RIFF',b'AVI ',lambda f: (
  211.     wrt(f,b'LIST',b'hdrl',lambda f: (
  212.         wrt(f,b'avih',b'',add4s,[16667,25000,0,0,FRMS,0,1,0x100000,WD,HG,0,0,0,0]),
  213.         wrt(f,b'LIST',b'strl',lambda f: (
  214.             wrt(f,b'strh',b'',strh),
  215.             wrt(f,b'strf',b'',strf),
  216.             wrt(f,b'JUNK',b'',junk,4120))),
  217.         wrt(f,b'JUNK',b'',junk,1318))),
  218.     wrt(f,b'LIST',b'movi',movi,s+chr(34)*3+s+chr(34)*3+chr(10)*2+s2[:-6])))
  219. with open('quine_video.avi','wb') as file:
  220.     file.write(bytes(f))
  221.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement