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

Separate media URL #869

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
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
8 changes: 8 additions & 0 deletions cms/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -469,6 +469,14 @@
# FRONTEND_HOST needs a http:// preffix
FRONTEND_HOST = f"http://{FRONTEND_HOST}"

try:
if (FRONTEND_HOST_MEDIA is not None) and ("http" not in FRONTEND_HOST_MEDIA): # noqa: F405
# FRONTEND_HOST_MEDIA needs a http:// preffix
FRONTEND_HOST_MEDIA = f"http://{FRONTEND_HOST_MEDIA}" # noqa: F405
except NameError:
# Ignore it - FRONTEND_HOST_MEDIA is probably not defined
pass

if LOCAL_INSTALL:
SSL_FRONTEND_HOST = FRONTEND_HOST.replace("http", "https")
else:
Expand Down
8 changes: 8 additions & 0 deletions docs/admins_docs.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,14 @@ ADMINS_NOTIFICATIONS = {
- Make the portal workflow public, but at the same time set `GLOBAL_LOGIN_REQUIRED = True` so that only logged in users can see content.
- You can either set `REGISTER_ALLOWED = False` if you want to add members yourself or checkout options on "django-allauth settings" that affects registration in `cms/settings.py`. Eg set the portal invite only, or set email confirmation as mandatory, so that you control who registers.

### 5.24 Configure different URL for media

If you want to use a different base URL for where your media is hosted (for example, if you keep your media directory synchronized to CDN servers), you can specify:

- FRONTEND_HOST_MEDIA: The base URL (e.g. "https://cdn.example.com") where your media should be accessed from

Please note: you will need to ensure that however you're hosting your media files, it adds an Access-Control-Allow-Origin header to allow the main MediaCMS scripts to download from it.

## 6. Manage pages
to be written

Expand Down
4 changes: 4 additions & 0 deletions files/context_processors.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,8 @@ def stuff(request):
ret["ALLOW_RATINGS_CONFIRMED_EMAIL_ONLY"] = settings.ALLOW_RATINGS_CONFIRMED_EMAIL_ONLY
ret["VIDEO_PLAYER_FEATURED_VIDEO_ON_INDEX_PAGE"] = settings.VIDEO_PLAYER_FEATURED_VIDEO_ON_INDEX_PAGE
ret["RSS_URL"] = "/rss"
try:
ret["FRONTEND_HOST_MEDIA"] = settings.FRONTEND_HOST_MEDIA.rstrip('/')
except AttributeError:
ret["FRONTEND_HOST_MEDIA"] = None
return ret
16 changes: 13 additions & 3 deletions files/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,12 @@ def get_encoding_info(self, encoding, full=False):
ep = {}
ep["title"] = encoding.profile.name
ep["url"] = encoding.media_encoding_url
try:
if settings.FRONTEND_HOST_MEDIA is not None:
ep["url"] = settings.FRONTEND_HOST_MEDIA + encoding.media_encoding_url
except Exception:
pass

ep["progress"] = encoding.progress
ep["size"] = encoding.size
ep["encoding_id"] = encoding.id
Expand Down Expand Up @@ -818,14 +824,18 @@ def hls_info(self):
"""

res = {}
prefix = ""
if settings.FRONTEND_HOST_MEDIA is not None:
prefix = settings.FRONTEND_HOST_MEDIA

valid_resolutions = [240, 360, 480, 720, 1080, 1440, 2160]
if self.hls_file:
if os.path.exists(self.hls_file):
hls_file = self.hls_file
p = os.path.dirname(hls_file)
m3u8_obj = m3u8.load(hls_file)
if os.path.exists(hls_file):
res["master_file"] = helpers.url_from_path(hls_file)
res["master_file"] = prefix + helpers.url_from_path(hls_file)
for iframe_playlist in m3u8_obj.iframe_playlists:
uri = os.path.join(p, iframe_playlist.uri)
if os.path.exists(uri):
Expand All @@ -835,7 +845,7 @@ def hls_info(self):
if resolution not in valid_resolutions:
resolution = iframe_playlist.iframe_stream_info.resolution[0]

res["{}_iframe".format(resolution)] = helpers.url_from_path(uri)
res["{}_iframe".format(resolution)] = prefix + helpers.url_from_path(uri)
for playlist in m3u8_obj.playlists:
uri = os.path.join(p, playlist.uri)
if os.path.exists(uri):
Expand All @@ -844,7 +854,7 @@ def hls_info(self):
if resolution not in valid_resolutions:
resolution = playlist.stream_info.resolution[0]

res["{}_playlist".format(resolution)] = helpers.url_from_path(uri)
res["{}_playlist".format(resolution)] = prefix + helpers.url_from_path(uri)
return res

@property
Expand Down
8 changes: 4 additions & 4 deletions templates/cms/media.html
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@

{% if media_object.media_type == "video" %}

<meta property="og:image" content="{{FRONTEND_HOST}}{{media_object.poster_url}}">
<meta property="og:image" content="{{FRONTEND_HOST_MEDIA}}{{media_object.poster_url}}">

<meta name="twitter:card" content="summary_large_image">

Expand All @@ -34,7 +34,7 @@
"url": "{{FRONTEND_HOST}}{{media_object.get_absolute_url}}",
"description": "{% if media_object.summary %}{{media_object.summary}}{% else %}{{media_object.description}}{% endif %}",
"thumbnailUrl": [
"{{FRONTEND_HOST}}{{media_object.poster_url}}"
"{{FRONTEND_HOST_MEDIA}}{{media_object.poster_url}}"
],
"uploadDate": "{{media_object.add_date}}",
"dateModified": "{{media_object.edit_date}}",
Expand All @@ -49,7 +49,7 @@

{% elif media_object.media_type == "audio" %}

<meta property="og:image" content="{{FRONTEND_HOST}}{{media_object.poster_url}}">
<meta property="og:image" content="{{FRONTEND_HOST_MEDIA}}{{media_object.poster_url}}">

<meta name="twitter:card" content="summary_large_image">

Expand All @@ -72,7 +72,7 @@

{% elif media_object.media_type == "image" %}

<meta property="og:image" content="{{FRONTEND_HOST}}{{media_object.original_media_url}}">
<meta property="og:image" content="{{FRONTEND_HOST_MEDIA}}{{media_object.original_media_url}}">

<meta name="twitter:card" content="summary_large_image">

Expand Down
Loading