-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Use full YouTube URLs instead of just video IDs
Use full YouTube URLs instead of just video IDs as the path params for the `/video/` route. Add a new `YouTubeService` that handles parsing YouTube URLs in order to extract the video IDs from them. In the future this same `YoutubeService` will also be used to get video transcripts from the YouTube API. This commit also adds a new `YOUTUBE_CAPTIONS` setting and disables the `/video` route (HTTP Unauthorized) is this setting isn't enabled. `get_url_details.py` is also turned into a service (`URLDetailsService`) because it now depends on two other services (and because previously it was a random top-level file). Also, HTTP caching headers are added to the `/video` route.
- Loading branch information
Showing
22 changed files
with
274 additions
and
131 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
from unittest.mock import sentinel | ||
|
||
import pytest | ||
|
||
from via.services.youtube import YoutubeService, factory | ||
|
||
|
||
class TestYoutubeService: | ||
@pytest.mark.parametrize( | ||
"url,video_id", | ||
[ | ||
("not_an_url", None), | ||
("https://notyoutube:1000000", None), | ||
("https://notyoutube.com", None), | ||
("https://youtube.com", None), | ||
("https://youtube.com?param=nope", None), | ||
("https://youtube.com?v=", None), | ||
("https://www.youtube.com/watch?v=VIDEO_ID", "VIDEO_ID"), | ||
("https://www.youtube.com/watch?v=VIDEO_ID&t=14s", "VIDEO_ID"), | ||
], | ||
) | ||
def test_parse_file_url(self, url, video_id): | ||
assert video_id == YoutubeService.parse_url(url) | ||
|
||
@pytest.mark.parametrize("enabled,expected", [(True, True), (False, False)]) | ||
def test_enabled(self, enabled, expected): | ||
assert YoutubeService(enabled).enabled == expected | ||
|
||
|
||
def test_factory(pyramid_request): | ||
svc = factory(sentinel.context, pyramid_request) | ||
|
||
assert isinstance(svc, YoutubeService) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.