forked from shashankatgit/YoutubeThumbnailMaximizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
url_processor.py
96 lines (69 loc) · 3.03 KB
/
url_processor.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
from get_meta_tags import extractMetas
from flask import request
shareableFolder = "static/share"
def processURL(vidURL, siteURL):
urlparts = vidURL.split('?')
vidID = urlparts[1][2:]
# print 'vid id is :' + vidID
# print 'site is '+siteURL
vidImgURL = 'https://img.youtube.com/vi/' + vidID + '/0.jpg'
print 'vid img link is :' + vidImgURL
metaTags = extractMetas(vidURL)
urlToShare = prepareURLfromVidID(vidID, siteURL)
html = '''
<html>
<head>
<script type="text/javascript" src="../js/pagecontrol.js"></script>
<script type="text/javascript">
function caller()
{
redirect("''' + vidID + '''");
}
</script>
<link rel="canonical" href="''' + urlToShare + '''" />
<meta property="og:locale" content="en_US" />
<meta property="og:type" content="article" />
<meta property="og:title" content="''' + metaTags['title'] + '''" />
<meta property="og:description" content="''' + metaTags['description'] + '''" />
<meta property="og:url" content="''' + urlToShare + '''" />
<meta property="og:site_name" content="ThumbMaximizer" />
<meta property="og:image" content="''' + vidImgURL + '''" />
<meta property="og:image:secure_url" content="''' + vidImgURL + '''" />
<meta property="og:image:width" content="1280" />
<meta property="og:image:height" content="720" />
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:description" content="''' + metaTags['description'] + '''" />
<meta name="twitter:title" content="''' + metaTags['title'] + '''" />
<meta name="twitter:image" content="''' + vidImgURL + '''" />
<title> Link - ''' + metaTags['title'] + '''</title>
<meta name="description" content="''' + metaTags['description'] + '''"/>
<meta itemprop="name" content="''' + metaTags['title'] + '''">
<meta itemprop="description" content="''' + metaTags['description'] + '''">
<meta itemprop="image" content="''' + vidImgURL + '''">
<meta property="og:title" content="''' + metaTags['title'] + '''"/>
<meta property="og:description" content="''' + metaTags['description'] + '''"/>
<meta property="og:image" content="''' + vidImgURL + '''"/>
<meta property="og:image:url" content="''' + vidImgURL + '''"/>
<meta property="og:image:width" content="470"/>
<meta property="og:image:height" content="265"/>
<meta property="og:site_name" content="ThumbMaximizer"/>
<meta name="twitter:card" content="summary_large_image" />
<meta name="twitter:site" content="fbshare" />
<meta name="twitter:title" content="''' + metaTags['title'] + '''" />
<meta name="twitter:description" content="''' + metaTags['description'] + '''" />
<meta name="twitter:image" content="''' + vidImgURL + '''"/>
</head>
<body onload=caller()>
<h4>you will be redirected in a few seconds</h4>
Screenshot
<img src="''' + vidImgURL + '''">
</body>
</html>'''
filePath = shareableFolder + '/' + vidID + '.html'
f= open(filePath,"w+")
f.write(html)
f.close()
return vidID
def prepareURLfromVidID(vidID, siteURL):
print(vidID)
return siteURL + shareableFolder + "/" + vidID + ".html"