Skip to content

Commit

Permalink
Merge pull request willfarrell#134 from ajliv/update-brew-search
Browse files Browse the repository at this point in the history
Use searchbrew.com for Brew workflow
  • Loading branch information
willfarrell authored Jun 18, 2018
2 parents 1093d4c + 372c814 commit 0819e5e
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 56 deletions.
Binary file modified Package Managers.alfredworkflow
Binary file not shown.
64 changes: 8 additions & 56 deletions src/Brew.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,77 +8,29 @@ class Brew extends Repo
{
protected $id = 'brew';
protected $kind = 'plugins';
protected $url = 'http://braumeister.org';
protected $search_url = 'http://braumeister.org/search/';
protected $url = 'http://searchbrew.com';
protected $search_url = 'http://searchbrew.com/search?q=';

public function search($query)
{
if (!$this->hasMinQueryLength($query)) {
return $this->xml();
}

// special case - exact match
$redirect_check = $this->cache->get_query_data(
$this->pkgs = $this->cache->get_query_json(
$this->id,
$query,
"{$this->search_url}{$query}"
);

$exact_match = (
$redirect_check === '<html><body>You are being <a href="'.$this->url.'/formula/'.$query.'">redirected</a>.</body></html>'
? true
: false
);

if ($exact_match) {
$this->pkgs = $this->cache->get_query_regex(
$this->id,
$query,
"{$this->url}/formula/{$query}",
'/<div id="content">([\s\S]*?)<div id="deps">/i',
1
);
} else {
$this->pkgs = $this->cache->get_query_regex(
$this->id,
$query,
"{$this->search_url}{$query}",
'/<tr class="formula (odd|even)">([\s\S]*?)<\/tr>/i',
2
);
}

foreach ($this->pkgs as $pkg) {
if ($exact_match) {
// name
$title = $query;

// version
preg_match('/<strong class="version spec-stable">([\s\S]*?)<\/strong>/i', $pkg, $matches);
$version = trim(strip_tags($matches[0]));

// details
preg_match('/Homepage: <em><a href="(.*?)">(.*?)<\/a>/i', $pkg, $matches);
$details = strip_tags($matches[1]);
} else {
// name
preg_match('/<a class="formula" href="(.*?)">(.*?)<\/a>/i', $pkg, $matches);
$title = strip_tags($matches[0]);

// version
preg_match('/<strong class="version spec-stable">([\s\S]*?)<\/strong>/i', $pkg, $matches);
$version = trim(strip_tags($matches[0]));

// url
preg_match('/Homepage: <a href="(.*?)">(.*?)<\/a>/i', $pkg, $matches);
$details = strip_tags($matches[1]);
}
foreach ($this->pkgs->data as $pkg) {
$title = $pkg->title;

$this->cache->w->result(
$title,
"{$this->url}/formula/{$title}",
"{$title} v{$version}",
$details,
$this->makeArg($title, $pkg->homepage),
$title,
$pkg->description,
"icon-cache/{$this->id}.png"
);

Expand Down

0 comments on commit 0819e5e

Please sign in to comment.