Skip to content

Commit

Permalink
updated bilibili, Sina Weibo, Zhihu with latest API
Browse files Browse the repository at this point in the history
fixed #12
  • Loading branch information
zqzten committed Feb 2, 2019
1 parent 712e719 commit b62c156
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 62 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Support basic suggestions.

### Zhihu

Support direct term suggestions and preview.
Support basic suggestions.

![zhihu](screenshots/zhihu.png)

Expand Down Expand Up @@ -120,7 +120,7 @@ If you want an alternative to search exactly what you typed, you can add custom
* Baidu: `https://www.baidu.com/s?wd={query}`
* Zhihu: `https://www.zhihu.com/search?q={query}`
* bilibili: `https://search.bilibili.com/all?keyword={query}`
* Sina Weibo: `https://s.weibo.com/weibo/{query}`
* Sina Weibo: `https://s.weibo.com/weibo?q={query}`
* Taobao: `https://s.taobao.com/search?q={query}`
* JoyBuy: `https://search.jd.com/Search?enc=utf-8&keyword={query}`
* Bangumi: `http://bangumi.tv/subject_search/{query}`
Expand Down
Binary file modified screenshots/sinaweibo.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified screenshots/zhihu.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion src/bilibili.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

$wf = new Workflow;

$response = request('https://api.bilibili.cn/suggest?term='.urlencode($query));
$response = request('https://s.search.bilibili.com/main/suggest?term='.urlencode($query));
$json = json_decode($response, true);

foreach ($json as $key => $value) {
Expand Down
6 changes: 3 additions & 3 deletions src/info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ require_once('baidu.php');</string>
<key>spaces</key>
<string></string>
<key>url</key>
<string>{query}</string>
<string>https://www.zhihu.com/search?q={query}</string>
<key>utf8</key>
<true/>
</dict>
Expand Down Expand Up @@ -782,7 +782,7 @@ require_once('sinaweibo.php');</string>
<key>spaces</key>
<string></string>
<key>url</key>
<string>https://s.weibo.com/weibo/{query}</string>
<string>https://s.weibo.com/weibo?q={query}</string>
<key>utf8</key>
<true/>
</dict>
Expand Down Expand Up @@ -1263,7 +1263,7 @@ require_once('moegirlpedia.php');</string>
<string>proxy</string>
</array>
<key>version</key>
<string>1.10</string>
<string>1.11</string>
<key>webaddress</key>
<string>https://github.com/AkikoZ/alfred-web-search-suggest</string>
</dict>
Expand Down
13 changes: 6 additions & 7 deletions src/sinaweibo.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,18 @@

$wf = new Workflow;

$response = request('https://s.weibo.com/ajax/suggestion?where=gs_weibo&key='.urlencode($query));
$response = request('https://s.weibo.com/Ajax_Search/suggest?key='.urlencode('#'.$query));
$json = json_decode($response);
$data = $json->data;

foreach ($data as $sugg) {
$key = $sugg->key;
$count = $sugg->count;
$word = $sugg->word;
$wf->result()
->title($key)
->subtitle($count.' results')
->arg($key)
->title($word)
->subtitle('Search 新浪微博 for '.$word)
->arg($word)
->icon(ICON)
->autocomplete($key);
->autocomplete($word);
}

echo $wf->output();
61 changes: 12 additions & 49 deletions src/zhihu.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,60 +4,23 @@
require_once('vendor/joetannenbaum/alfred-workflow/Workflow.php');
require_once('vendor/joetannenbaum/alfred-workflow/Result.php');
require_once('util/request.php');
require_once('util/download.php');

const ICON = '861BE674-55FF-4779-A44A-A02FF66440B0.png';

$wf = new Workflow;

$download_dir = getenv('alfred_workflow_cache').'/zhihu';
initDownloadDir(true);

$response = request('https://www.zhihu.com/autocomplete?token='.urlencode($query));
$json = json_decode($response)[0];

foreach ($json as $sugg) {
if (is_array($sugg)) {
$matched = true;
$type = $sugg[0];
$title = html_entity_decode($sugg[1], ENT_QUOTES | ENT_HTML5);
switch ($type) {
case 'topic':
$subtitle = '【话题】'.$sugg[6].' 个精选回答';
$arg = 'https://www.zhihu.com/'.$type.'/'.$sugg[2];
$icon = saveAndReturnFile(str_replace('_s', '_m', $sugg[3]));
break;
case 'people':
$subtitle = '【用户】'.html_entity_decode($sugg[5], ENT_QUOTES | ENT_HTML5);
$arg = 'https://www.zhihu.com/'.$type.'/'.$sugg[2];
$icon = saveAndReturnFile(str_replace('_s', '_m', $sugg[3]));
break;
case 'question':
$subtitle = '【问题】'.$sugg[4].' 个回答';
$arg = 'https://www.zhihu.com/'.$type.'/'.$sugg[3];
$icon = ICON;
break;
case 'article':
$subtitle = '【文章】'.$sugg[4].' 个赞';
$arg = 'https://zhuanlan.zhihu.com/p/'.$sugg[3];
$icon = ICON;
break;
default:
$matched = false;
break;
}

if ($matched) {
$wf->result()
->title($title)
->subtitle($subtitle)
->arg($arg)
->icon($icon)
->autocomplete($title)
->copy($title)
->quicklookurl($arg);
}
}
$response = request('https://www.zhihu.com/api/v4/search/suggest?q='.urlencode($query));
$json = json_decode($response);
$suggest = $json->suggest;

foreach ($suggest as $sugg) {
$query = $sugg->query;
$wf->result()
->title($query)
->subtitle('Search 知乎 for '.$query)
->arg($query)
->icon(ICON)
->autocomplete($query);
}

echo $wf->output();

0 comments on commit b62c156

Please sign in to comment.