-
Notifications
You must be signed in to change notification settings - Fork 74
/
TumblrPostDownload.py
53 lines (47 loc) · 1.27 KB
/
TumblrPostDownload.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
# -*- coding: utf-8 -*-
"""
Author: Sparrow
Purpose: downloading one entire blog from Tumblr once.
Created: 2017-1.1
"""
import re
import urllib.request
import Tumblrimage
import TumblrVideo
import traceback
from urllib.parse import quote
def getHtml(url):
url = quote(url, safe='/:?=')
try:
page = urllib.request.urlopen(url)
html = page.read().decode('utf-8')
return html
except:
# traceback.print_exc()
print('The URL you requested could not be found In Module PostDownload')
return 'Html'
def vedio_image_judge(url):
html = getHtml(url)
reg = r'<meta property="og:type" content="tumblr-feed:(.*?)" />'
typere = re.compile(reg)
type =re.findall(typere, html)
if type:
print('This is %s' % type[0])
return type[0]
else:
return False
def PostDownload(url):
Type =vedio_image_judge(url)
if Type == 'video':
TumblrVideo.getMP4(url)
elif Type == 'photoset' or 'photo':
Tumblrimage.getImg(url)
else:
print('There is nothing!')
if __name__ == '__main__':
select = 'N'
while not(select == 'Y'):
URL = input('Input url: ')
# vedio_image_judge(URL)
PostDownload(URL)
select = input("Do you want to Quit? [Y/N]")