├── .gitignore ├── LICENSE ├── README.md ├── images ├── 1.png └── 2.png └── tumblr.py /.gitignore: -------------------------------------------------------------------------------- 1 | # Byte-compiled / optimized / DLL files 2 | __pycache__/ 3 | *.py[cod] 4 | *$py.class 5 | 6 | # C extensions 7 | *.so 8 | 9 | # Distribution / packaging 10 | .Python 11 | env/ 12 | build/ 13 | develop-eggs/ 14 | dist/ 15 | downloads/ 16 | eggs/ 17 | .eggs/ 18 | lib/ 19 | lib64/ 20 | parts/ 21 | sdist/ 22 | var/ 23 | *.egg-info/ 24 | .installed.cfg 25 | *.egg 26 | 27 | # PyInstaller 28 | # Usually these files are written by a python script from a template 29 | # before PyInstaller builds the exe, so as to inject date/other infos into it. 30 | *.manifest 31 | *.spec 32 | 33 | # Installer logs 34 | pip-log.txt 35 | pip-delete-this-directory.txt 36 | 37 | # Unit test / coverage reports 38 | htmlcov/ 39 | .tox/ 40 | .coverage 41 | .coverage.* 42 | .cache 43 | nosetests.xml 44 | coverage.xml 45 | *,cover 46 | .hypothesis/ 47 | 48 | # Translations 49 | *.mo 50 | *.pot 51 | 52 | # Django stuff: 53 | *.log 54 | 55 | # Sphinx documentation 56 | docs/_build/ 57 | 58 | # PyBuilder 59 | target/ 60 | 61 | #Ipython Notebook 62 | .ipynb_checkpoints 63 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2016 兵兵 王 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # tumblr-capturer 2 | 3 | Capture video links in someone's tumblr blog. 4 | 5 | ## Install the depend lib 6 | 7 | ```python 8 | pip3 install pytumblr 9 | ``` 10 | 11 | ## Install 12 | 13 | - Just download the last release in [releases](https://github.com/ZxBing0066/tumblr-capturer/releases) and then run the app. 14 | - clone this repository and then enter the folder then just run `python3 tumblr.py`. 15 | 16 | ## Usage 17 | 18 | ![1](https://github.com/ZxBing0066/tumblr-capturer/raw/master/images/1.png) 19 | 20 | ![2](https://github.com/ZxBing0066/tumblr-capturer/raw/master/images/2.png) 21 | 22 | ## Info 23 | 24 | 1. Python Version: V3.0+ 25 | 2. Packager: pyinstaller 26 | 3. Used libs: pytumblr 27 | -------------------------------------------------------------------------------- /images/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZxBing0066/tumblr-capturer/591002766a11ca343681d55c883c7e700888f6cb/images/1.png -------------------------------------------------------------------------------- /images/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/ZxBing0066/tumblr-capturer/591002766a11ca343681d55c883c7e700888f6cb/images/2.png -------------------------------------------------------------------------------- /tumblr.py: -------------------------------------------------------------------------------- 1 | #!/usr/local/bin/python3 2 | 3 | import tkinter as tk 4 | import pytumblr as pytumblr 5 | import threading 6 | 7 | # Authenticate via OAuth 8 | client = pytumblr.TumblrRestClient( 9 | 'mLvXdqzLEzBIqS3JO7IyDmjI8jdY61qMDTRzTUdf6ojmXOYufX' 10 | ) 11 | 12 | # Make the request 13 | # likes = client.likes() 14 | 15 | # print(likes) 16 | 17 | # followings = client.following()['blogs'] 18 | # followings = client.following(offset=0, limit=10)['blogs'] 19 | 20 | # for following in followings: 21 | # print(following['name']) 22 | # pass 23 | 24 | # info = client.info() 25 | # print(info) 26 | 27 | # def getFollowing(offset=0, limit=20): 28 | # return client.following(offset=offset, limit=limit)['blogs'] 29 | 30 | # def getAllFollowing(): 31 | # allFollowing = [] 32 | # currentLength = 0 33 | # maxLength = info['user']['following'] 34 | # while currentLength < maxLength: 35 | # following = client.following(offset=currentLength, limit=20)['blogs'] 36 | # print(currentLength) 37 | # for _following in following: 38 | # print(_following['name']) 39 | # allFollowing.extend(following) 40 | # currentLength += len(following) 41 | # return allFollowing 42 | 43 | # allFollowing = getAllFollowing() 44 | # for following in allFollowing: 45 | # print(following['name']) 46 | #print(len(allFollowing)) 47 | 48 | #posts = client.posts('listentoloveme', type='video')['posts'] 49 | 50 | def getAllPosts(name): 51 | allPosts = [] 52 | currentLength = 0 53 | maxLength = 1 54 | while currentLength < maxLength: 55 | posts = client.posts(name, type='video', offset=currentLength, limit=20) 56 | maxLength = posts['total_posts'] 57 | posts = posts['posts'] 58 | allPosts.extend(posts) 59 | currentLength += len(posts) 60 | return allPosts 61 | 62 | #allPosts = getAllPosts('listentoloveme') 63 | #for post in allPosts: 64 | # print(post['video_url']) 65 | 66 | LIMIT = 20 67 | 68 | class Application(tk.Frame): 69 | def __init__(self, master=None): 70 | tk.Frame.__init__(self, master) 71 | self.state = 'wait' 72 | self.pack() 73 | self.createWidgets() 74 | 75 | def createWidgets(self): 76 | self.label = tk.Label(self, text='input tumblr username U want to grab') 77 | self.label.pack(side='top') 78 | 79 | self.input = tk.Entry(self) 80 | self.input.pack(side='top') 81 | self.input.insert('end', '') 82 | 83 | self.hi_there = tk.Button(self, text='get', command=self.getContent) 84 | self.hi_there.pack(side="top") 85 | 86 | self.textArea = tk.Text(self) 87 | self.textArea.pack(side='bottom') 88 | 89 | def getContent(self): 90 | if self.state == 'loading': 91 | self.state = 'waitToStop' 92 | print('waitToStop') 93 | return 94 | elif self.state == 'waitToStop': 95 | print('please wait to stop first') 96 | return 97 | name = self.input.get() 98 | print('start to grab:', name) 99 | self.getAllPosts(name) 100 | 101 | def getAllPosts(self, name): 102 | self.state = 'loading' 103 | t = threading.Thread(target=self.getPosts, args=(name, 0)) 104 | t.setDaemon(True) 105 | t.start() 106 | 107 | def getPosts(self, name, currentLength): 108 | print('wait to load %s to %s:' % (currentLength, currentLength + LIMIT)) 109 | posts = client.posts(name, type='video', offset=currentLength, limit=LIMIT) 110 | maxLength = posts['total_posts'] 111 | posts = posts['posts'] 112 | currentLength += len(posts) 113 | text = '' 114 | for post in posts: 115 | if('video_url' in post): 116 | text += (post['video_url'] + '\n') 117 | self.textArea.insert('end', text) 118 | print(text, currentLength, maxLength) 119 | if self.state == 'waitToStop': 120 | self.state = 'wait' 121 | print('stop to load more') 122 | return 123 | if currentLength >= maxLength or len(posts) == 0: 124 | print('end, no more') 125 | return 126 | else: 127 | t = threading.Thread(target=self.getPosts, args=(name, currentLength)) 128 | t.setDaemon(True) 129 | t.start() 130 | 131 | 132 | root = tk.Tk() 133 | app = Application(master=root) 134 | app.mainloop() --------------------------------------------------------------------------------