2

I developed to play youtube video through iframe and it almost works. but there is also have videos that can't be played in django template(SSR). However above some videos can played in react(CSR).

enter image description here

For example as below

work youtube url: https://youtu.be/bPCYR5Wec-g

not work youtube url: https://www.youtube.com/watch?v=d7d-e4BHs0w

How to play this youtube videos?

Mingyu Choi
  • 71
  • 1
  • 7
  • 1
    Check this [answer](https://stackoverflow.com/a/55661292). I thought the owner of the channel disabled embedding their videos, but, probably there are other reasons not necessary by the owner but from YouTube themself that disables certain videos from being embed - like copyright issues or any other obscure/non-disclosed reasons... – Marco Aurelio Fernandez Reyes Jun 09 '22 at 13:55
  • 1
    @MingyuChoi You have a correct Answer, why not accept it? (mark it as correct by clicking the tick). The video you want is blocked by Youtube and is "not available" to your device. – VC.One Jun 12 '22 at 06:40

2 Answers2

2

After checking this answer, I embed the video https://www.youtube.com/watch?v=d7d-e4BHs0w using jsfiddle and I got the following text:

Video unavailable

This video has content from LatinAutor - UMPG, who blocked its playing on this website or in this application.

The reason is not shown if you copy/paste the embed link in your browser - i.e. https://www.youtube.com/embed/d7d-e4BHs0w

TL;DR: The video might be not available due to the owner disabled their videos for embedding or YouTube themselfs disables certain videos from being embed - due to copyright issues or any other obscure/non-disclosed reasons...

0

Had a similar issue when using iframes in Django, I could embed most of the videos but some popular music videos would not load and simply display: Video unavailable. To fix it had to manually set the Referer header by adding this line to settings.py:

SECURE_REFERRER_POLICY = "no-referrer-when-downgrade"

Turns out Django does not set Referer in request headers by default, and for some videos (e.g. popular music videos that are copyrighted) youtube checks if the Referer has a host name (e.g http://localhost:8000/ in dev or https://examplesite.com), if the Referer is not set or it is simply an IP (e.g. 192.168.1.1:8000) then the video won't play. The "no-referrer-when-downgrade" is 1 of the Django referrer policy settings that adds the referer header except when downgrading from https to http and worked for me.