-
Notifications
You must be signed in to change notification settings - Fork 31
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Youtube & Reddit support #38
base: master
Are you sure you want to change the base?
Conversation
thomasXwang
commented
Aug 30, 2023
- Need to get Youtube API credentials, and input them at line 14 of youtube.php
- Need to add the script filter to the Alfred workflow
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for this great contribution! Please check the comments to make changes to proceed, thanks again!
$reddit_url = "https://www.reddit.com/api/subreddit_autocomplete_v2.json"; | ||
$api_call = $reddit_url . '?' . http_build_query($params); | ||
$headers = array("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3; charset=utf-8"); | ||
$ch = curl_init(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This can be simplified to utilize the request
function provided in util/request.php
.
'query' => urlencode($query), | ||
'include_over_18' => false, | ||
'include_profiles' => false, | ||
'limit' => 7, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggest to change limit to 9 as Alfred defaults to show 9 results
]; | ||
$reddit_url = "https://www.reddit.com/api/subreddit_autocomplete_v2.json"; | ||
$api_call = $reddit_url . '?' . http_build_query($params); | ||
$headers = array("User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/58.0.3029.110 Safari/537.3; charset=utf-8"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the user-agent header seems to be redundant and can be omitted
->quicklookurl($url); | ||
} | ||
} | ||
} else { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
the else case can be ommited as it is suggested to add a normal Web Search with the same keyword as fallback
// See following link for YouTube API quotas | ||
// https://developers.google.com/youtube/v3/determine_quota_cost?hl=fr | ||
|
||
$cacheDir = __DIR__ . '/icon-cache/'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The cache dir should be placed to Alfred's default workflow cache dir: getenv('alfred_workflow_cache').'/youtube'
then Alfred can automatically manage it with no need to provide an explicit clear method.
Also, please utilize the functions in util/download.php
to do file downloading & caching, you can check imdb.php
as a simple usage example.
->arg('https://www.youtube.com/watch?v=' . $videoId) | ||
->icon($cachePath) | ||
->autocomplete($title) | ||
->data(['cachePath' => $cachePath]); // Store the cache path in the result data |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we also add copy
and quicklookurl
here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Please make screenshot with the same theme as others (Alfred macOS without an Alfred icon), and make sure your screenshot is captured by ⌘⇧4 then space with shadow, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ditto