|
|
|
@ -150,68 +150,27 @@ def pandoc(filename, title, creator, date, website, thumbnail, bio, description,
|
|
|
|
|
|
|
|
|
|
def img_fullurl(parent):
|
|
|
|
|
imgs = parent.findall('.//img')
|
|
|
|
|
print 'len IMG', len(imgs)
|
|
|
|
|
for img in imgs:
|
|
|
|
|
src = img.get('src')
|
|
|
|
|
fullurl = api_thumb_url(src)
|
|
|
|
|
print '----- IMG', ET.tostring(img ), src, fullurl
|
|
|
|
|
if fullurl != None:
|
|
|
|
|
img.set('src', fullurl)
|
|
|
|
|
# fileurl = api_request(src, endpoint)# find url of file
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
gallery_exp=re.compile('<gallery>.*?</gallery>', re.S)
|
|
|
|
|
imgfile_exp=re.compile('(File:(.*?\.(gif|jpg|jpeg|png)))')# (?=File:|<\/gallery>)')
|
|
|
|
|
img_exp=re.compile('(File:|Image:)((.*?)\.(gif|jpg|jpeg|png))(?=\||File:|Image:|<\/gallery>)', re.I)
|
|
|
|
|
video_exp=re.compile('\{\{(.*?)\|(.*?)\}\}')
|
|
|
|
|
gallery_exp=re.compile('<gallery>(.*?)</gallery>', re.S)
|
|
|
|
|
imgfile_exp=re.compile('(File:(.*?)\.(gif|jpg|jpeg|png))')
|
|
|
|
|
|
|
|
|
|
def replace_gallery(content):
|
|
|
|
|
gallery_imgs = []
|
|
|
|
|
gallery_found = re.findall(gallery_exp, content)
|
|
|
|
|
for gallery in gallery_found: # in case there is more than 1 <gallery>
|
|
|
|
|
allfiles =re.findall(imgfile_exp, gallery)
|
|
|
|
|
print 'ALLFILES', allfiles
|
|
|
|
|
for imgfile in allfiles:
|
|
|
|
|
imgfile = imgfile[1]
|
|
|
|
|
#imgsrc = imgfile
|
|
|
|
|
imgsrc = api_file_url(imgfile) # seaarch for original image
|
|
|
|
|
newimg = ''
|
|
|
|
|
gallery_imgs.append(imgsrc)
|
|
|
|
|
print 'GALLERY_IMGS', gallery_imgs
|
|
|
|
|
|
|
|
|
|
ungallery_imgs = " ".join(gallery_imgs)
|
|
|
|
|
print 'ungallery_imgs', ungallery_imgs
|
|
|
|
|
|
|
|
|
|
content = re.sub(gallery_exp, ungallery_imgs, content)
|
|
|
|
|
print 'images content', content
|
|
|
|
|
|
|
|
|
|
## BUG: Images are being replaced as <a>
|
|
|
|
|
# EG: <a class="uri" href="File:Mb-WordNet-tour-version2-08.png">File:Mb-WordNet-tour-version2-08.png</a> <a class="uri" href="File:Labanotation1.jpg">File:Labanotation1.jpg</a>
|
|
|
|
|
|
|
|
|
|
content = re.sub(imgfile_exp, '[[\g<1>]]', content) #add [[ ]] to File:.*?
|
|
|
|
|
content = re.sub(gallery_exp, '\g<1>', content) #remove gallery wrapper
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
video_exp=re.compile('\{\{(.*?)\|(.*?)\}\}')
|
|
|
|
|
vimeo_exp=re.compile('\{\{vimeo\|(.*?)\}\}')
|
|
|
|
|
youtube_exp=re.compile('\{\{youtube\|(.*?)\}\}')
|
|
|
|
|
|
|
|
|
|
def replace_video(content):
|
|
|
|
|
videos = []
|
|
|
|
|
videos_found = re.findall(video_exp, content)
|
|
|
|
|
for video in videos_found:
|
|
|
|
|
video_provider = str(video[0])
|
|
|
|
|
video_hash = str(video[1])
|
|
|
|
|
video_src = None
|
|
|
|
|
if (video_provider.lower()) == 'youtube':
|
|
|
|
|
video_src="https://www.youtube.com/embed/" + video_hash
|
|
|
|
|
elif (video_provider.lower()) == 'vimeo':
|
|
|
|
|
video_src="https://player.vimeo.com/video/" + video_hash
|
|
|
|
|
if video_src:
|
|
|
|
|
videos.append(video_src)
|
|
|
|
|
iframe = "<iframe src='{}' width='600px' height='450px'> </iframe>".format(video_src)
|
|
|
|
|
content = re.sub(video_exp, iframe, content)
|
|
|
|
|
else:
|
|
|
|
|
content = re.sub(video_exp, '', content)
|
|
|
|
|
content = re.sub(vimeo_exp,"<iframe src='https://player.vimeo.com/video/\g<1>' width='600px' height='450px'> </iframe>", content)
|
|
|
|
|
content = re.sub(youtube_exp, "<iframe src='https://www.youtube.com/embed/\g<1>' width='600px' height='450px'> </iframe>", content)
|
|
|
|
|
return content
|
|
|
|
|
|
|
|
|
|
## Video Replacement: problem with video: iframe is placed inside <p> . It shouldn't
|
|
|
|
|
|
|
|
|
|
## replace gallery - not yet there
|
|
|
|
|
|
|
|
|
|