├── Douban Movie.alfredworkflow ├── readme.md ├── screenshot ├── screenshot.png └── screenshot2.png └── src ├── db.py ├── favicons ├── 1.png ├── 2.png ├── 3.png ├── 4.png ├── 5.png ├── 6.png ├── 7.png ├── 8.png ├── 9.png ├── unknow.png └── unknow2.png ├── feedback.py ├── feedback.pyc ├── icon.png └── info.plist /Douban Movie.alfredworkflow: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/Douban Movie.alfredworkflow -------------------------------------------------------------------------------- /readme.md: -------------------------------------------------------------------------------- 1 | ## Douban Movie Workflow 2 | ![GitHub top language](https://img.shields.io/github/languages/top/swim2sun/Douban-Movie-Workflow.svg) 3 | [![GitHub release](https://img.shields.io/github/release/swim2sun/Douban-Movie-Workflow.svg)](https://github.com/swim2sun/Douban-Movie-Workflow/releases) 4 | [![Github All Releases](https://img.shields.io/github/downloads/swim2sun/Douban-Movie-Workflow/total.svg)](https://github.com/swim2sun/Douban-Movie-Workflow/releases) 5 | 6 | 用于搜索电影的豆瓣评分。[下载](https://github.com/swim2sun/Douban-Movie-Workflow/releases) 7 | ![截图](screenshot/screenshot2.png) 8 | -------------------------------------------------------------------------------- /screenshot/screenshot.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/screenshot/screenshot.png -------------------------------------------------------------------------------- /screenshot/screenshot2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/screenshot/screenshot2.png -------------------------------------------------------------------------------- /src/db.py: -------------------------------------------------------------------------------- 1 | # encoding:utf-8 2 | __author__ = 'youxiangyang' 3 | from feedback import Feedback 4 | import urllib.request, urllib.parse, urllib.error 5 | import urllib.request, urllib.error, urllib.parse 6 | import sys 7 | import re 8 | 9 | keyword = sys.argv[1] 10 | headers = { 11 | 'User-Agent': 'Mozilla/5.0 (iPhone; CPU iPhone OS 10_3_3 like Mac OS X) AppleWebKit/603.3.8 (KHTML, like Gecko) Version/10.0 Mobile/14G60 Safari/602.1', 12 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 13 | # 'Accept-Encoding':'gzip, deflate, sdch', 14 | 'Accept-Language': 'zh-cn', 15 | 'Cache-Control': 'max-age=0', 16 | 'Host': 'm.douban.com', 17 | 'DNT': '1' 18 | } 19 | request = urllib.request.Request("https://m.douban.com/search?type=1002&query=" + urllib.parse.quote(keyword), None, headers) 20 | response = urllib.request.urlopen(request) 21 | 22 | html = response.read() 23 | patten1 = re.compile(r'(\s\s+)|\n') 24 | html = re.sub(patten1, ' ', html.decode('utf-8')); 25 | find_re = re.compile( 26 | r'
  • \s\s\s(.+?).+?

    (.+?)', 27 | re.DOTALL) 28 | 29 | fb = Feedback() 30 | for x in find_re.findall(html): 31 | link = "https://movie.douban.com" + x[0][6:] # 链接 32 | title = x[1] # 片名 包含别名 33 | # content = x[2] # 简介 34 | rating = x[2].strip() # 评价 35 | # rate_count = x[4] # 评价数 36 | try: 37 | rateNum = str(int(float(rating))) 38 | halfRate = int((float(rating) + 0.5) / 2) 39 | except (TypeError, ValueError): 40 | rateNum = 'unknow' 41 | halfRate = 0 42 | fb.add_item(title, 43 | subtitle="★★★★★☆☆☆☆☆"[(5 - halfRate) * 3:(10 - halfRate) * 3] + " " + rating, 44 | arg=link, icon='favicons/' + rateNum + '.png') 45 | print(fb) 46 | 47 | -------------------------------------------------------------------------------- /src/favicons/1.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/1.png -------------------------------------------------------------------------------- /src/favicons/2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/2.png -------------------------------------------------------------------------------- /src/favicons/3.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/3.png -------------------------------------------------------------------------------- /src/favicons/4.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/4.png -------------------------------------------------------------------------------- /src/favicons/5.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/5.png -------------------------------------------------------------------------------- /src/favicons/6.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/6.png -------------------------------------------------------------------------------- /src/favicons/7.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/7.png -------------------------------------------------------------------------------- /src/favicons/8.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/8.png -------------------------------------------------------------------------------- /src/favicons/9.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/9.png -------------------------------------------------------------------------------- /src/favicons/unknow.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/unknow.png -------------------------------------------------------------------------------- /src/favicons/unknow2.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/favicons/unknow2.png -------------------------------------------------------------------------------- /src/feedback.py: -------------------------------------------------------------------------------- 1 | #author: Peter Okma 2 | import xml.etree.ElementTree as et 3 | import sys 4 | import importlib 5 | importlib.reload(sys) 6 | 7 | class Feedback(): 8 | """Feeback used by Alfred Script Filter 9 | 10 | Usage: 11 | fb = Feedback() 12 | fb.add_item('Hello', 'World') 13 | fb.add_item('Foo', 'Bar') 14 | print fb 15 | 16 | """ 17 | 18 | def __init__(self): 19 | self.feedback = et.Element('items') 20 | 21 | def __repr__(self): 22 | """XML representation used by Alfred 23 | 24 | Returns: 25 | XML string 26 | """ 27 | return et.tostring(self.feedback).decode('utf-8'); 28 | 29 | def add_item(self, title, subtitle="", arg="", valid="yes", autocomplete="", icon="icon.png"): 30 | """ 31 | Add item to alfred Feedback 32 | 33 | Args: 34 | title(str): the title displayed by Alfred 35 | Keyword Args: 36 | subtitle(str): the subtitle displayed by Alfred 37 | arg(str): the value returned by alfred when item is selected 38 | valid(str): whether or not the entry can be selected in Alfred to trigger an action 39 | autcomplete(str): the text to be inserted if an invalid item is selected. This is only used if 'valid' is 'no' 40 | icon(str): filename of icon that Alfred will display 41 | """ 42 | item = et.SubElement(self.feedback, 'item', uid=str(len(self.feedback)), 43 | arg=arg, valid=valid, autocomplete=autocomplete) 44 | _title = et.SubElement(item, 'title') 45 | _title.text = title 46 | _sub = et.SubElement(item, 'subtitle') 47 | _sub.text = subtitle 48 | _icon = et.SubElement(item, 'icon') 49 | _icon.text = icon 50 | 51 | -------------------------------------------------------------------------------- /src/feedback.pyc: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/feedback.pyc -------------------------------------------------------------------------------- /src/icon.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/swim2sun/Douban-Movie-Workflow/09551a7c67e1641bb3bc8e458fb54850d0e138f3/src/icon.png -------------------------------------------------------------------------------- /src/info.plist: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | bundleid 6 | io.github.swim2sun 7 | category 8 | Tools 9 | connections 10 | 11 | 353A9AB9-5BFF-4DF7-91E0-A6CE56F60226 12 | 13 | 14 | destinationuid 15 | A5816188-347E-404F-98E4-89C4A002F662 16 | modifiers 17 | 0 18 | modifiersubtext 19 | 20 | 21 | 22 | 4ACEF39F-2AEA-4F39-88CD-407D2D024B8F 23 | 24 | 25 | destinationuid 26 | 353A9AB9-5BFF-4DF7-91E0-A6CE56F60226 27 | modifiers 28 | 0 29 | modifiersubtext 30 | 31 | 32 | 33 | 34 | createdby 35 | swim2sun 36 | description 37 | Search movie from 'movie.douban.com' 38 | disabled 39 | 40 | name 41 | Douban Movie 42 | objects 43 | 44 | 45 | config 46 | 47 | plusspaces 48 | 49 | url 50 | {query} 51 | utf8 52 | 53 | 54 | type 55 | alfred.workflow.action.openurl 56 | uid 57 | A5816188-347E-404F-98E4-89C4A002F662 58 | version 59 | 0 60 | 61 | 62 | config 63 | 64 | action 65 | 1 66 | argument 67 | 1 68 | hotkey 69 | 0 70 | hotmod 71 | 0 72 | hotstring 73 | 74 | leftcursor 75 | 76 | modsmode 77 | 0 78 | relatedAppsMode 79 | 0 80 | 81 | type 82 | alfred.workflow.trigger.hotkey 83 | uid 84 | 4ACEF39F-2AEA-4F39-88CD-407D2D024B8F 85 | version 86 | 1 87 | 88 | 89 | config 90 | 91 | argumenttype 92 | 0 93 | escaping 94 | 127 95 | keyword 96 | db 97 | queuedelaycustom 98 | 3 99 | queuedelayimmediatelyinitially 100 | 101 | queuedelaymode 102 | 0 103 | queuemode 104 | 1 105 | script 106 | # encoding:utf-8 107 | __author__ = 'youxiangyang' 108 | from feedback import Feedback 109 | import urllib 110 | import urllib2 111 | import re 112 | 113 | keyword = '{query}' 114 | param = {"search_text": keyword} 115 | data = urllib.urlencode(param) 116 | headers = { 117 | 'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_11_1) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.80 Safari/537.36', 118 | 'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8', 119 | # 'Accept-Encoding':'gzip, deflate, sdch', 120 | 'Accept-Language': 'zh-CN,zh;q=0.8,en-US;q=0.6,en;q=0.4', 121 | 'Cache-Control': 'max-age=0', 122 | 'Host': 'movie.douban.com', 123 | 'Proxy-Connection': 'keep-alive', 124 | 'Upgrade-Insecure-Requests': '1' 125 | } 126 | request = urllib2.Request("https://movie.douban.com/subject_search", data, headers) 127 | response = urllib2.urlopen(request) 128 | html = response.read() 129 | 130 | patten1 = re.compile(r'(\s\s+)|\n') 131 | html = re.sub(patten1, ' ', html) 132 | patten2 = re.compile(r'(<span style="font-size:12px;">)|</span>') 133 | patten3 = re.compile(r'<div class="star clearfix">\s*?<span class="pl">') 134 | html = re.sub(patten3, '<div class="star clearfix"> <span class="rating_nums"> </span><span class="pl">', html) 135 | find_re = re.compile( 136 | r'<a class="nbg.+?<img src="(.+?)".+?<div class="pl2">.+?<a href="(.+?)".+?>(.+?)</a>.+?<p class="pl">(.+?)</p>.+?<div class="star clearfix">.*?<span class="rating_nums">(.*?)</span>.*?<span class="pl">(.+?)</span>', 137 | re.DOTALL) 138 | 139 | fb = Feedback() 140 | for x in find_re.findall(html): 141 | iconUrl = x[0] # icon 142 | link = x[1] # 链接 143 | title = x[2] # 片名 包含别名 144 | title = re.sub(patten2, '', title) 145 | content = x[3] # 简介 146 | rating = x[4].strip() # 评价 147 | rate_count = x[5] # 评价数 148 | if rating: 149 | rateNum = str(int(float(rating))) 150 | else: 151 | rateNum = 'unknow' 152 | rating = '?.?' 153 | fb.add_item(rating+"\t"+title, 154 | subtitle=rate_count+"\t"+content, 155 | arg=link,icon='favicons/'+rateNum+'.png') 156 | print fb 157 | 158 | title 159 | 豆瓣电影 160 | type 161 | 3 162 | withspace 163 | 164 | 165 | type 166 | alfred.workflow.input.scriptfilter 167 | uid 168 | 353A9AB9-5BFF-4DF7-91E0-A6CE56F60226 169 | version 170 | 0 171 | 172 | 173 | readme 174 | 175 | uidata 176 | 177 | 353A9AB9-5BFF-4DF7-91E0-A6CE56F60226 178 | 179 | ypos 180 | 30 181 | 182 | 4ACEF39F-2AEA-4F39-88CD-407D2D024B8F 183 | 184 | ypos 185 | 30 186 | 187 | A5816188-347E-404F-98E4-89C4A002F662 188 | 189 | ypos 190 | 30 191 | 192 | 193 | webaddress 194 | https://github.com/swim2sun 195 | 196 | 197 | --------------------------------------------------------------------------------