-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from danielduggin2/UTCT-69-Youtube-titles
Added YouTube Plugins
- Loading branch information
Showing
3 changed files
with
86 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
MIT License | ||
|
||
Copyright (c) 2013-present, The YOURLS Contributors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
# Fix Youtube titles [![Listed in Awesome YOURLS!](https://img.shields.io/badge/Awesome-YOURLS-C5A3BE)](https://github.com/YOURLS/awesome-yourls/) | ||
|
||
_Without this plugin_, shortening a Youtube URL returns an incorrect title: <kbd>Before you continue to YouTube</kbd> (read why below) | ||
|
||
**With this plugin**, you get the correct title, ie <kbd>Backyard Squirrel Maze 1.0- Ninja Warrior Course - YouTube</kbd> | ||
|
||
Tested with [YOURLS](https://yourls.org) `1.8.1` and above. | ||
|
||
## Installation | ||
|
||
1. In `/user/plugins`, create a new folder named `fix-youtube-titles` or something like this | ||
2. Drop these files in that directory. | ||
3. Go to the Plugins administration page (eg. `http://sho.rt/admin/plugins.php`) and activate the plugin. | ||
4. Have fun! | ||
|
||
## License | ||
|
||
Do what the hell you want with it. | ||
|
||
## Why is this needed? | ||
|
||
Youtube redirects every unknown user to a page where they need to accept their darn cookies: | ||
|
||
<img src="https://user-images.githubusercontent.com/223647/120112768-85809e80-c177-11eb-952a-d1ab429be086.png" width="300px" /> | ||
|
||
Your YOURLS instance is such an _unknown_ user to Google, since it has no Youtube cookie. This plugin tricks Youtube and makes it think it has one. | ||
|
||
🍪 FTW. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
<?php | ||
/* | ||
Plugin Name: Fix Youtube titles | ||
Plugin URI: https://github.com/ozh/fix-youtube-titles/ | ||
Description: Get correct Youtube video titles | ||
Version: 1.0 | ||
Author: Ozh | ||
Author URI: http://ozh.org/ | ||
*/ | ||
|
||
// No direct call | ||
if( !defined( 'YOURLS_ABSPATH' ) ) die(); | ||
|
||
// Add filters if we're trying to get a page title from Youtube | ||
yourls_add_filter('shunt_get_remote_title', 'ozh_is_youtube_url'); | ||
function ozh_is_youtube_url($false, $url) { | ||
// is this a youtube.com URL ? | ||
if( strpos($url, 'youtube.com') > 0 ) { | ||
// change user agent to "curl". Actually, this is enough to trick Youtube ¯\_(ツ)_/¯ | ||
yourls_add_filter('http_user_agent', function(){return 'curl/7.68.0';}); | ||
|
||
// The <title> tag in Youtube pages is buried down the page : lift limit of bytes retrieved | ||
yourls_add_filter('get_remote_title_max_byte', function(){return '';}); | ||
|
||
// Extra trick : fake the cookie that Youtube expects (requires YOURLS 1.8.2+) | ||
yourls_add_filter('http_request_headers', 'ozh_youtube_add_consent'); | ||
} | ||
|
||
// We don't want to actually interrupt the flow of event so we return false | ||
return $false; | ||
} | ||
|
||
// Add a cookie header to the HTTP request | ||
function ozh_youtube_add_consent($in) { | ||
$in['Cookie']='CONSENT=YES+1337'; | ||
return $in; | ||
} |