import numpy.random
import string
import urllib.request
from moviepy.editor import *
def find_between( s, first, last ):
try:
start = s.index( first ) + len( first )
end = s.index( last, start )
return s[start:end]
except ValueError:
return ""
def base36encode(number, alphabet='0123456789abcdefghijklmnopqrstuvwxyz'):
if not isinstance(number, (int)):
raise TypeError('number must be an integer')
base36 = ''
sign = ''
if number < 0:
sign = '-'
number = -number
if 0 <= number < len(alphabet):
return sign + alphabet[number]
while number != 0:
number, i = divmod(number, len(alphabet))
base36 = alphabet[i] + base36
return sign + base36
def base36decode(number):
return int(number, 36)
for j in range(1,20):
videocliplist=[]
audiocliplist=[]
durationlist=[]
i=0
while i<20:
randint=numpy.random.randint(10**5,10**7)
try: urllib.request.urlopen('http://c...content-available-to-author-only...b.com/embed/' + base36encode(randint))
except urllib.error.HTTPError:
continue
with urllib.request.urlopen('http://c...content-available-to-author-only...b.com/embed/'+base36encode(randint)) as response:
html = response.read().decode("utf-8")
try:vidDuration = float(find_between(html, 'false,"duration":', ',"promo_winner"'))
except ValueError:
continue
if vidDuration<3:
continue
print(vidDuration)
videourl=find_between(html,'"file":"','","')
print(videourl)
videopath='C:\\coub\\'+str(i)+'.mp4'
try:urllib.request.urlretrieve(videourl,videopath)
except ValueError:
continue
except ConnectionResetError:
continue
audiourl=find_between(html,'"audio_url":"','","')
print(audiourl)
if audiourl =="":
continue
audiopath='C:\\coub\\'+str(i)+'.mp3'
try:urllib.request.urlretrieve(audiourl, audiopath)
except ValueError:
continue
"""
try:audio = AudioFileClip('C:\\coub\\'+str(i)+'.mp3').set_duration(vidDuration)
except AttributeError:
i = i - 1
continue
except UnicodeDecodeError:
i = i - 1
continue
except OSError:
i = i - 1
continue
"""
durationlist.append(vidDuration)
videocliplist.append(videopath)
audiocliplist.append(audiopath)
i+=1
print(videocliplist)
print(len(videocliplist))
print(len(audiocliplist))
print("Nachalo vtoroi fazi")
for k in range(1,6):
print(videocliplist)
try:audioclip=AudioFileClip(audiocliplist[k])
except OSError:
continue
except AttributeError:
continue
videoresized=VideoFileClip(videocliplist[k],audio=False).resize((1280,720))
videoresized.set_audio(audioclip)
videoresized.set_duration(durationlist[k])
try: cuter = VideoFileClip('C:\\cut.mp4',)
except OSError:
continue
print(k)
fclip = concatenate_videoclips((videoresized, cuter), method="compose", transition=None)
try:fclip.write_videofile('C:\\coub\\file' + str(k) + '.mp4', fps=30,codec='mpeg4')
except OSError:
continue
for k in range(8, len(videocliplist)):
print(videocliplist)
try:
audioclip = AudioFileClip(audiocliplist[k])
except OSError:
continue
except AttributeError:
continue
videoresized = VideoFileClip(videocliplist[k], audio=False).resize((1280, 720))
videoresized.set_audio(audioclip)
videoresized.set_duration(durationlist[k])
try:cuter = VideoFileClip('C:\\cut.mp4', )
except OSError:
continue
print(k)
fclip = concatenate_videoclips((videoresized, cuter), method="compose", transition=None)
try:
fclip.write_videofile('C:\\coub\\file' + str(k) + '.mp4', fps=30, codec='mpeg4')
except OSError:
continue
aW1wb3J0IG51bXB5LnJhbmRvbQppbXBvcnQgc3RyaW5nCmltcG9ydCB1cmxsaWIucmVxdWVzdApmcm9tIG1vdmllcHkuZWRpdG9yIGltcG9ydCAqCgpkZWYgZmluZF9iZXR3ZWVuKCBzLCBmaXJzdCwgbGFzdCApOgogICAgdHJ5OgogICAgICAgIHN0YXJ0ID0gcy5pbmRleCggZmlyc3QgKSArIGxlbiggZmlyc3QgKQogICAgICAgIGVuZCA9IHMuaW5kZXgoIGxhc3QsIHN0YXJ0ICkKICAgICAgICByZXR1cm4gc1tzdGFydDplbmRdCiAgICBleGNlcHQgVmFsdWVFcnJvcjoKICAgICAgICByZXR1cm4gIiIKZGVmIGJhc2UzNmVuY29kZShudW1iZXIsIGFscGhhYmV0PScwMTIzNDU2Nzg5YWJjZGVmZ2hpamtsbW5vcHFyc3R1dnd4eXonKToKICAgIGlmIG5vdCBpc2luc3RhbmNlKG51bWJlciwgKGludCkpOgogICAgICAgIHJhaXNlIFR5cGVFcnJvcignbnVtYmVyIG11c3QgYmUgYW4gaW50ZWdlcicpCgogICAgYmFzZTM2ID0gJycKICAgIHNpZ24gPSAnJwoKICAgIGlmIG51bWJlciA8IDA6CiAgICAgICAgc2lnbiA9ICctJwogICAgICAgIG51bWJlciA9IC1udW1iZXIKCiAgICBpZiAwIDw9IG51bWJlciA8IGxlbihhbHBoYWJldCk6CiAgICAgICAgcmV0dXJuIHNpZ24gKyBhbHBoYWJldFtudW1iZXJdCgogICAgd2hpbGUgbnVtYmVyICE9IDA6CiAgICAgICAgbnVtYmVyLCBpID0gZGl2bW9kKG51bWJlciwgbGVuKGFscGhhYmV0KSkKICAgICAgICBiYXNlMzYgPSBhbHBoYWJldFtpXSArIGJhc2UzNgoKICAgIHJldHVybiBzaWduICsgYmFzZTM2CgpkZWYgYmFzZTM2ZGVjb2RlKG51bWJlcik6CiAgICByZXR1cm4gaW50KG51bWJlciwgMzYpCgoKZm9yIGogaW4gcmFuZ2UoMSwyMCk6CiAgICB2aWRlb2NsaXBsaXN0PVtdCiAgICBhdWRpb2NsaXBsaXN0PVtdCiAgICBkdXJhdGlvbmxpc3Q9W10KICAgIGk9MAogICAgd2hpbGUgaTwyMDoKICAgICAgICByYW5kaW50PW51bXB5LnJhbmRvbS5yYW5kaW50KDEwKio1LDEwKio3KQogICAgICAgIHRyeTogdXJsbGliLnJlcXVlc3QudXJsb3BlbignaHR0cDovL2MuLi5jb250ZW50LWF2YWlsYWJsZS10by1hdXRob3Itb25seS4uLmIuY29tL2VtYmVkLycgKyBiYXNlMzZlbmNvZGUocmFuZGludCkpCiAgICAgICAgZXhjZXB0IHVybGxpYi5lcnJvci5IVFRQRXJyb3I6CiAgICAgICAgICAgIGNvbnRpbnVlCiAgICAgICAgd2l0aCB1cmxsaWIucmVxdWVzdC51cmxvcGVuKCdodHRwOi8vYy4uLmNvbnRlbnQtYXZhaWxhYmxlLXRvLWF1dGhvci1vbmx5Li4uYi5jb20vZW1iZWQvJytiYXNlMzZlbmNvZGUocmFuZGludCkpIGFzIHJlc3BvbnNlOgogICAgICAgICAgICBodG1sID0gcmVzcG9uc2UucmVhZCgpLmRlY29kZSgidXRmLTgiKQoKICAgICAgICB0cnk6dmlkRHVyYXRpb24gPSBmbG9hdChmaW5kX2JldHdlZW4oaHRtbCwgJ2ZhbHNlLCJkdXJhdGlvbiI6JywgJywicHJvbW9fd2lubmVyIicpKQogICAgICAgIGV4Y2VwdCBWYWx1ZUVycm9yOgogICAgICAgICAgICBjb250aW51ZQogICAgICAgIGlmIHZpZER1cmF0aW9uPDM6CgogICAgICAgICAgICBjb250aW51ZQogICAgICAgIHByaW50KHZpZER1cmF0aW9uKQogICAgICAgIHZpZGVvdXJsPWZpbmRfYmV0d2VlbihodG1sLCciZmlsZSI6IicsJyIsIicpCiAgICAgICAgcHJpbnQodmlkZW91cmwpCiAgICAgICAgdmlkZW9wYXRoPSdDOlxcY291YlxcJytzdHIoaSkrJy5tcDQnCiAgICAgICAgdHJ5OnVybGxpYi5yZXF1ZXN0LnVybHJldHJpZXZlKHZpZGVvdXJsLHZpZGVvcGF0aCkKICAgICAgICBleGNlcHQgVmFsdWVFcnJvcjoKCiAgICAgICAgICAgIGNvbnRpbnVlCiAgICAgICAgZXhjZXB0IENvbm5lY3Rpb25SZXNldEVycm9yOgoKICAgICAgICAgICAgY29udGludWUKICAgICAgICBhdWRpb3VybD1maW5kX2JldHdlZW4oaHRtbCwnImF1ZGlvX3VybCI6IicsJyIsIicpCiAgICAgICAgcHJpbnQoYXVkaW91cmwpCiAgICAgICAgaWYgYXVkaW91cmwgPT0iIjoKCiAgICAgICAgICAgIGNvbnRpbnVlCiAgICAgICAgYXVkaW9wYXRoPSdDOlxcY291YlxcJytzdHIoaSkrJy5tcDMnCiAgICAgICAgdHJ5OnVybGxpYi5yZXF1ZXN0LnVybHJldHJpZXZlKGF1ZGlvdXJsLCBhdWRpb3BhdGgpCiAgICAgICAgZXhjZXB0IFZhbHVlRXJyb3I6CgogICAgICAgICAgICBjb250aW51ZQogICAgICAgICIiIgogICAgICAgIHRyeTphdWRpby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XRpb24oZHVyYXRpb25saXN0W2tdKQogICAgICAgIHRyeTpjdXRlciA9IFZpZGVvRmlsZUNsaXAoJ0M6XFxjdXQubXA0JywgKQogICAgICAgIGV4Y2VwdCBPU0Vycm9yOgogICAgICAgICAgICBjb250aW51ZQogICAgICAgIHByaW50KGspCiAgICAgICAgZmNsaXAgPSBjb25jYXRlbmF0ZV92aWRlb2NsaXBzKCh2aWRlb3Jlc2l6ZWQsIGN1dGVyKSwgbWV0aG9kPSJjb21wb3NlIiwgdHJhbnNpdGlvbj1Ob25lKQogICAgICAgIHRyeToKICAgICAgICAgICAgZmNsaXAud3JpdGVfdmlkZW9maWxlKCdDOlxcY291YlxcZmlsZScgKyBzdHIoaykgKyAnLm1wNCcsIGZwcz0zMCwgY29kZWM9J21wZWc0JykKICAgICAgICBleGNlcHQgT1NFcnJvcjoKICAgICAgICAgICAgY29udGludWUKCgoKCgoK