Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

thomasXwang
Copy link

  • 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

@thomasXwang thomasXwang changed the title Add youtube support Add Youtube & Reddit support Aug 31, 2023
Copy link
Owner

@zqzten zqzten left a 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();
Copy link
Owner

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,
Copy link
Owner

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");
Copy link
Owner

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 {
Copy link
Owner

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/';
Copy link
Owner

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
Copy link
Owner

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?

Copy link
Owner

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!

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ditto

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants