fork(2) download
  1. import numpy.random
  2. import string
  3. import urllib.request
  4. from moviepy.editor import *
  5.  
  6. def find_between( s, first, last ):
  7. try:
  8. start = s.index( first ) + len( first )
  9. end = s.index( last, start )
  10. return s[start:end]
  11. except ValueError:
  12. return ""
  13. def base36encode(number, alphabet='0123456789abcdefghijklmnopqrstuvwxyz'):
  14. if not isinstance(number, (int)):
  15. raise TypeError('number must be an integer')
  16.  
  17. base36 = ''
  18. sign = ''
  19.  
  20. if number < 0:
  21. sign = '-'
  22. number = -number
  23.  
  24. if 0 <= number < len(alphabet):
  25. return sign + alphabet[number]
  26.  
  27. while number != 0:
  28. number, i = divmod(number, len(alphabet))
  29. base36 = alphabet[i] + base36
  30.  
  31. return sign + base36
  32.  
  33. def base36decode(number):
  34. return int(number, 36)
  35.  
  36.  
  37. for j in range(1,20):
  38. videocliplist=[]
  39. audiocliplist=[]
  40. durationlist=[]
  41. i=0
  42. while i<20:
  43. randint=numpy.random.randint(10**5,10**7)
  44. try: urllib.request.urlopen('http://c...content-available-to-author-only...b.com/embed/' + base36encode(randint))
  45. except urllib.error.HTTPError:
  46. continue
  47. with urllib.request.urlopen('http://c...content-available-to-author-only...b.com/embed/'+base36encode(randint)) as response:
  48. html = response.read().decode("utf-8")
  49.  
  50. try:vidDuration = float(find_between(html, 'false,"duration":', ',"promo_winner"'))
  51. except ValueError:
  52. continue
  53. if vidDuration<3:
  54.  
  55. continue
  56. print(vidDuration)
  57. videourl=find_between(html,'"file":"','","')
  58. print(videourl)
  59. videopath='C:\\coub\\'+str(i)+'.mp4'
  60. try:urllib.request.urlretrieve(videourl,videopath)
  61. except ValueError:
  62.  
  63. continue
  64. except ConnectionResetError:
  65.  
  66. continue
  67. audiourl=find_between(html,'"audio_url":"','","')
  68. print(audiourl)
  69. if audiourl =="":
  70.  
  71. continue
  72. audiopath='C:\\coub\\'+str(i)+'.mp3'
  73. try:urllib.request.urlretrieve(audiourl, audiopath)
  74. except ValueError:
  75.  
  76. continue
  77. """
  78. try:audio = AudioFileClip('C:\\coub\\'+str(i)+'.mp3').set_duration(vidDuration)
  79. except AttributeError:
  80. i = i - 1
  81. continue
  82. except UnicodeDecodeError:
  83. i = i - 1
  84. continue
  85. except OSError:
  86. i = i - 1
  87. continue
  88. """
  89. durationlist.append(vidDuration)
  90. videocliplist.append(videopath)
  91. audiocliplist.append(audiopath)
  92. i+=1
  93. print(videocliplist)
  94. print(len(videocliplist))
  95. print(len(audiocliplist))
  96. print("Nachalo vtoroi fazi")
  97. for k in range(1,6):
  98. print(videocliplist)
  99. try:audioclip=AudioFileClip(audiocliplist[k])
  100. except OSError:
  101. continue
  102. except AttributeError:
  103. continue
  104.  
  105. videoresized=VideoFileClip(videocliplist[k],audio=False).resize((1280,720))
  106. videoresized.set_audio(audioclip)
  107. videoresized.set_duration(durationlist[k])
  108. try: cuter = VideoFileClip('C:\\cut.mp4',)
  109. except OSError:
  110. continue
  111. print(k)
  112. fclip = concatenate_videoclips((videoresized, cuter), method="compose", transition=None)
  113. try:fclip.write_videofile('C:\\coub\\file' + str(k) + '.mp4', fps=30,codec='mpeg4')
  114. except OSError:
  115. continue
  116. for k in range(8, len(videocliplist)):
  117. print(videocliplist)
  118. try:
  119. audioclip = AudioFileClip(audiocliplist[k])
  120. except OSError:
  121. continue
  122. except AttributeError:
  123. continue
  124.  
  125. videoresized = VideoFileClip(videocliplist[k], audio=False).resize((1280, 720))
  126. videoresized.set_audio(audioclip)
  127. videoresized.set_duration(durationlist[k])
  128. try:cuter = VideoFileClip('C:\\cut.mp4', )
  129. except OSError:
  130. continue
  131. print(k)
  132. fclip = concatenate_videoclips((videoresized, cuter), method="compose", transition=None)
  133. try:
  134. fclip.write_videofile('C:\\coub\\file' + str(k) + '.mp4', fps=30, codec='mpeg4')
  135. except OSError:
  136. continue
  137.  
  138.  
  139.  
  140.  
  141.  
  142.  
  143.  
Runtime error #stdin #stdout #stderr 0.26s 30912KB
stdin
Standard input is empty
stdout
Standard output is empty
stderr
Traceback (most recent call last):
  File "./prog.py", line 4, in <module>
ImportError: No module named 'moviepy'