Skip to content

Commit

Permalink
Feat/revert permanent stream (#11)
Browse files Browse the repository at this point in the history
* Revert "feat(GLUE-14941): change demo page with permanent stream URL (#9)"

This reverts commit 30c4627.

* Revert "Merge pull request #8 from dailymotion/feat/permanent-url"

This reverts commit 2eeb0b4, reversing
changes made to 9bb2613.
  • Loading branch information
kmartin91 committed Mar 14, 2024
1 parent 30c4627 commit 45092a7
Show file tree
Hide file tree
Showing 6 changed files with 108 additions and 293 deletions.
5 changes: 0 additions & 5 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
# 0.0.5 (2024-03-05)

- Add /permanent-stream-url route
- Lock python version to `>=3.11,<3.12` for now (update to python >3.11 will be done in a dedicated PR)

# 0.0.4 (2023-04-03)

- Switch Docker base image from `python:3.11-alpine` to `python:3.11` (fix [#6](https://github.com/dailymotion/demo-stream-urls-server/issues/6))
Expand Down
5 changes: 0 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@ Then run `bin/start-api.sh`.
From your client browse to
`http://<your-server-ip>:8000/stream-urls?video_id=<video_id>&video_formats=<format1<,format2>>`

### Fetch permanent stream URL

Directly point your player to
`http://<your-server-ip>:8000/permanent-stream-url?video_id=<video_id>&video_format=<format>`

#### Note About End-User IP

The Stream URLs Server gets the end-user IP address from the HTTP request made by the latter.
Expand Down
4 changes: 2 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
[project]
name = "demo-stream-urls-server"
version = "0.0.5"
version = "0.0.4"

requires-python = ">= 3.11,<3.12"
requires-python = ">= 3.11"
dependencies = [
"aiohttp>=3.8.4",
"click>=8.1.3",
Expand Down
56 changes: 0 additions & 56 deletions src/dm_stream_urls_server/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,62 +110,6 @@ async def get_stream_urls_route(
) from e


@app.get("/permanent-stream-url")
async def get_permanent_stream_url_route(
video_id: str,
video_format: str,
client_ip: str = Depends(get_client_ip),
authorization: str = Depends(get_access_token),
):
"""Request Dailymotion API to get a video stream URL and redirect to it"""

try:
stream_urls = await get_stream_urls(
video_id=video_id,
video_formats=video_format,
client_ip=client_ip,
authorization=authorization,
)

except aiohttp.ClientResponseError as e:
raise HTTPException(
status_code=e.status,
detail=e.message,
) from e
except Exception as e: # pylint: disable=broad-except
exception_type = type(e).__name__
exception_message = str(e)

logger.error(
"Failed to get stream URL: "
"client_ip=%s, video_id=%s, video_format=%s, "
"exception_type=%s, exception_message=%s",
client_ip,
video_id,
video_format,
exception_type,
exception_message,
)

raise HTTPException(
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
detail="Internal server error",
) from e

try:
stream_url = stream_urls[video_format]
except (KeyError, TypeError):
stream_url = None

if not stream_url:
raise HTTPException(
status_code=status.HTTP_404_NOT_FOUND,
detail=f"Format {video_format} not found",
)

return RedirectResponse(stream_url)


app.mount(
"/demo",
StaticFiles(directory=Path(__file__).parent.joinpath("demo"), html=True),
Expand Down
256 changes: 106 additions & 150 deletions src/dm_stream_urls_server/demo/index.html
Original file line number Diff line number Diff line change
@@ -1,164 +1,120 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="referrer" content="no-referrer" />
<title>Demo</title>
<style>
body {
font-family: sans-serif;
}
<head>
<meta charset="utf-8">
<meta name="referrer" content="no-referrer">
<title>Demo</title>
<style>
body {
font-family: sans-serif;
}

main {
display: flex;
flex-direction: column;
padding: 0 20px;
width: 500px;
}
main {
display: flex;
flex-direction: column;
padding: 0 20px;
width: 500px;
}

h1 {
margin: 10px 0;
}
h1 {
margin: 10px 0;
}

input,
select,
button {
border-radius: 3px;
border: 1px solid #000;
box-sizing: border-box;
min-height: 24px;
padding: 5px;
}
input, select, button {
border-radius: 3px;
border: 1px solid #000;
box-sizing: border-box;
min-height: 24px;
padding: 5px;
}

.input {
margin: 20px 0;
}
.input {
margin: 20px 0;
}

.input > label {
display: block;
font-size: 14px;
font-weight: bold;
margin: 10px 0;
}
.input > label {
display: block;
font-size: 14px;
font-weight: bold;
margin: 10px 0;
}

.input > input,
.input > select {
width: 50%;
}
.input > input, .input > select {
width: 50%;
}

.streamUrl {
margin-top: 40px;
}
.streamUrl {
margin-top: 40px;
}

.streamUrl > input {
width: 100%;
}
.streamUrl > input {
width: 100%;
}

button {
background: #000;
border-radius: 3px;
border: 0;
color: #fff;
font-weight: bold;
padding: 5px 15px;
}
button {
background: #000;
border-radius: 3px;
border: 0;
color: #fff;
font-weight: bold;
padding: 5px 15px;
}

footer {
margin: 2em 0;
}
</style>
</head>
<body>
<main>
<h1>Stream URL Demo Page</h1>
<div class="inputs">
<div class="input">
<label for="video_id">Enter your video xID</label>
<input
id="video_id"
type="text"
name="video_id"
placeholder="Video xid"
/>
</div>
<div class="input">
<label for="format_type">Select quality</label>
<select id="format_type" name="format_type">
<option value="stream_h264_url">stream_h264_url</option>
<option value="stream_h264_hq_url">
stream_h264_hq_url
</option>
<option value="stream_h264_hd_url">
stream_h264_hd_url
</option>
<option value="stream_h264_hd1080_url">
stream_h264_hd1080_url
</option>
<option value="stream_h264_qhd_url">
stream_h264_qhd_url
</option>
<option value="stream_h264_uhd_url">
stream_h264_uhd_url
</option>
<option value="stream_hls_url">stream_hls_url</option>
</select>
</div>
<button id="fetch_btn" name="fetch_btn">Get stream</button>
<div class="input streamUrl">
<label for="stream_url">Fetched stream URL</label>
<input id="stream_url" type="text" name="stream_url" />
</div>
</div>
<video-js id="demo" controls></video-js>
footer {
margin: 2em 0;
}
</style>
</head>
<body>
<main>
<h1>Stream URL Demo Page</h1>
<div class="inputs">
<div class="input">
<label for="video_id">Enter your video xID</label>
<input id="video_id" type="text" name="video_id" placeholder="Video xid" />
</div>
<div class="input">
<label for="format_type">Select quality</label>
<select id="format_type" name="format_type">
<option value="stream_h264_url">stream_h264_url</option>
<option value="stream_h264_hq_url">stream_h264_hq_url</option>
<option value="stream_h264_hd_url">stream_h264_hd_url</option>
<option value="stream_h264_hd1080_url">stream_h264_hd1080_url</option>
<option value="stream_h264_qhd_url">stream_h264_qhd_url</option>
<option value="stream_h264_uhd_url">stream_h264_uhd_url</option>
<option value="stream_hls_url">stream_hls_url</option>
</select>
</div>
<button id="fetch_btn" name="fetch_btn">Get stream</button>
<div class="input streamUrl">
<label for="stream_url">Fetched stream URL</label>
<input id="stream_url" type="text" name="stream_url" />
</div>
</div>
<video-js id="demo" controls></video-js>
<footer>
<a href="/docs">Stream URL Server API documentation</a>
</footer>
</main>
<link href="https://vjs.zencdn.net/7.21.1/video-js.css" rel="stylesheet" />
<script src="https://vjs.zencdn.net/7.21.1/video.min.js"></script>
<script type="text/javascript">
const apiUrl = '/stream-urls'
const fetchBtn = document.getElementById('fetch_btn')
const streamUrlInput = document.getElementById('stream_url')

<h2>Permanent stream</h2>
const videoPlayer = videojs('demo')

<button id="fetch_btn_permanent" name="fetch_btn">
Get a permanent stream
</button>

<footer>
<a href="/docs">Stream URL Server API documentation</a>
</footer>
</main>
<link
href="https://vjs.zencdn.net/7.21.1/video-js.css"
rel="stylesheet"
/>
<script src="https://vjs.zencdn.net/7.21.1/video.min.js"></script>
<script type="text/javascript">
const apiUrl = "/stream-urls";
const permanentApiUrl = "/permanent-stream-url";
const fetchBtn = document.getElementById("fetch_btn");
const fetchPermanentBtn = document.getElementById(
"fetch_btn_permanent"
);
const streamUrlInput = document.getElementById("stream_url");

const videoPlayer = videojs("demo");

fetchBtn.addEventListener("click", () => {
const videoId = document.getElementById("video_id").value;
const formatType = document.getElementById("format_type").value;
fetch(
`${apiUrl}?video_id=${videoId}&video_formats=${formatType}`
)
.then((res) => res.json())
.then((data) => {
videoPlayer.src(data[formatType]);
streamUrlInput.value = data[formatType];
});
});
fetchPermanentBtn.addEventListener("click", () => {
const videoId = document.getElementById("video_id").value;
const formatType = document.getElementById("format_type").value;
fetch(
`${permanentApiUrl}?video_id=${videoId}&video_format=${formatType}`
).then((res) => {
// Redirect to the permanent stream URL
window.location.href = res.url;
});
});
</script>
</body>
fetchBtn.addEventListener('click', () => {
const videoId = document.getElementById('video_id').value
const formatType = document.getElementById('format_type').value
fetch(`${apiUrl}?video_id=${videoId}&video_formats=${formatType}`)
.then((res) => res.json())
.then((data) => {
videoPlayer.src(data[formatType])
streamUrlInput.value = data[formatType]
})
})
</script>
</body>
</html>

0 comments on commit 45092a7

Please sign in to comment.