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

Invidious as youtube cache #260

Closed
theScrabi opened this issue Dec 5, 2018 · 7 comments
Closed

Invidious as youtube cache #260

theScrabi opened this issue Dec 5, 2018 · 7 comments
Labels
enhancement Improvement of an existing feature help wanted Extra attention is needed stale

Comments

@theScrabi
Copy link

theScrabi commented Dec 5, 2018

Hei there, I really love invidious :D.

I am living in a student dorm in germany, and we have a really bad internet connection there. This is why we had to limit the data access for everyone who tries to connect to outside of our network.
I was wondering if Invidious could utilize for example youtube-dl to cache (or precache if subscibed) videos, so if a video gets watched more than once invidious will deliver the locally stored version.

regs Schabi

@omarroth
Copy link
Contributor

omarroth commented Dec 6, 2018

Not currently.

Invidious does cache video info though, so I could see that being a possible route. An external script would:

  • Connect to the Invidious DB and pull list of ids
  • Use youtube-dl or another tool to download streams, and provide local URLs for them
  • Update the info field to point to local streams
  • Change the updated field to far future so Invidious won't overwrite it

I expect that could work very well, and I would be more than happy to help you if you would like to pursue it.
Invidious uses PostgreSQL, and the video schema is here.

If you have any questions or issues feel free to contact me on the Invidious Matrix Server.

@elypter
Copy link

elypter commented Dec 7, 2018

if you got access to a faster network you could also cache it locally to watch later. kinda like megaupload works i assume. there are tools to save websites for offline tools but invidious could do this internally as well. there are several mothods to save data locally in the browser aside from cookies. i think localStorage is the one for a purpose like this.

@omarroth
Copy link
Contributor

omarroth commented Feb 7, 2019

Since there hasn't been any discussion on this issue for several months I'm going to close this, however I would very much like to see something like this exist.

There is now a Matrix Server for Invidious if you would like any help writing a script to do something like this. Please feel free to get in touch.

@omarroth omarroth closed this as completed Feb 7, 2019
@traderp
Copy link

traderp commented May 1, 2019

I'm interested in working on this if other developers want to join. My recommendation would be to use IPFS or libp2p. There are viable ways to run node in the browser. End users would maintain their own video cache while Invidious is active. On the server, archive nodes could increase content availability and serve pinned video (and circumvent YouTube censorship).

@omarroth omarroth added enhancement Improvement of an existing feature help wanted Extra attention is needed labels May 31, 2019
@omarroth omarroth reopened this May 31, 2019
@leonklingele
Copy link
Contributor

leonklingele commented Aug 5, 2019

@theScrabi you can set up nginx as a reverse proxy for invidious and configure a proxy_cache: https://nginx.org/en/docs/http/ngx_http_proxy_module.html#proxy_cache

This works on my side (replace INVIDIOUS_HOSTNAME with the hostname / IP address of your upstream instance):

# Outside server-block
# Use a maximum of 512GB for the cache which will be valid for 31 days.
proxy_cache_path /etc/nginx/cache levels=1:2 use_temp_path=off keys_zone=invidious_videos_cache:10m inactive=31d max_size=512g;

server {
# ...
	location ~ /(latest_version|videoplayback) {
		proxy_pass http://INVIDIOUS_HOSTNAME:3000;
		proxy_http_version 1.1;
		proxy_set_header Connection "";

		# Do not remove the following directives.
		# Otherwise the cache will not be populated.
		proxy_ignore_headers Cache-Control;
		proxy_ignore_headers Expires;
		proxy_ignore_headers X-Accel-Expires;
		proxy_hide_header Cache-Control;
		proxy_hide_header Expires;
		proxy_hide_header Pragma;

		add_header X-Cache-Status $upstream_cache_status;

		proxy_cache invidious_videos_cache;
		proxy_cache_key "invidious_videos-$request_uri";
		proxy_cache_methods GET;
		proxy_cache_valid 200 31d; # Used for /videoplayback responses
		proxy_cache_valid 302 31d; # Used for /latest_version responses
	}
# ...
}

@leonklingele
Copy link
Contributor

I have updated my comment above, caching of videos with nginx works fine now.

@github-actions
Copy link

github-actions bot commented Dec 2, 2020

This issue has been automatically marked as stale and will be closed in 30 days because it has not had recent activity and is much likely outdated. If you think this issue is still relevant and applicable, you just have to post a comment and it will be unmarked.

@github-actions github-actions bot added the stale label Dec 2, 2020
@github-actions github-actions bot closed this as completed Jan 2, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
enhancement Improvement of an existing feature help wanted Extra attention is needed stale
Projects
None yet
Development

No branches or pull requests

5 participants