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

20240216-0854 #82

Merged
merged 4 commits into from
Feb 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion frontend/config.php
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
// The array follows a title link structure:
// "TITLE" => "LINK",
$footerLinks = [
"About" => "https://github.com/UTCWeb/utctiny#utctiny",
"About" => "https://utc.teamdynamix.com/TDClient/2717/Portal/Requests/ServiceDet?ID=50665",
"Privacy" => "https://www.utc.edu/about/privacy",
"Manage My Links" => "/admin/",
];
21 changes: 21 additions & 0 deletions user/plugins/fix-youtube-titles/LICENSE
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.
28 changes: 28 additions & 0 deletions user/plugins/fix-youtube-titles/README.md
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.
37 changes: 37 additions & 0 deletions user/plugins/fix-youtube-titles/plugin.php
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;
}
Loading