-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from mobiusml/youtube_video_input
YouTube Video as an Input
- Loading branch information
Showing
14 changed files
with
272 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,2 @@ | ||
FROM nvidia/cuda:11.8.0-cudnn8-devel-ubuntu22.04 | ||
RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 | ||
RUN apt-get update && apt-get install -y libgl1 libglib2.0-0 ffmpeg |
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
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,38 @@ | ||
from enum import Enum | ||
import re | ||
|
||
|
||
class VideoSource(str, Enum): | ||
""" | ||
Video sources. | ||
Possible values are "auto" and "youtube". | ||
Attributes: | ||
AUTO (str): auto | ||
YOUTUBE (str): youtube | ||
""" | ||
|
||
AUTO = "auto" | ||
YOUTUBE = "youtube" | ||
|
||
@classmethod | ||
def from_url(cls, url: str) -> "VideoSource": | ||
""" | ||
Get the video source from a URL. | ||
Args: | ||
url (str): the URL | ||
Returns: | ||
VideoSource: the video source | ||
""" | ||
|
||
# TODO: Check that the URL is valid | ||
|
||
youtube_pattern = r"^(?:https?:\/\/)?(?:www\.)?(?:youtube\.com\/watch\?v=|youtube\.[a-zA-Z]{2,3}(\.[a-zA-Z]{2})?\/watch\?v=|youtu\.be\/)([a-zA-Z0-9_-]+)$" | ||
|
||
if re.match(youtube_pattern, url): | ||
return cls.YOUTUBE | ||
else: | ||
return cls.AUTO |
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,54 @@ | ||
from operator import not_ | ||
import pytest | ||
from aana.models.core.video_source import VideoSource | ||
|
||
|
||
def test_video_source_from_url(): | ||
""" | ||
Test that VideoSource.from_url returns the correct VideoSource for a given URL. | ||
""" | ||
# Test a YouTube URL | ||
valid_youtube_urls = [ | ||
"https://youtube.com/watch?v=yModCU1OVHY", | ||
"http://youtube.com/watch?v=yModCU1OVHY", | ||
"https://www.youtube.com/watch?v=yModCU1OVHY", | ||
"http://www.youtube.com/watch?v=yModCU1OVHY", | ||
"www.youtube.com/watch?v=yModCU1OVHY", | ||
"youtube.com/watch?v=yModCU1OVHY", | ||
"https://youtube.de/watch?v=yModCU1OVHY", | ||
"http://youtube.de/watch?v=yModCU1OVHY", | ||
"https://www.youtube.de/watch?v=yModCU1OVHY", | ||
"http://www.youtube.de/watch?v=yModCU1OVHY", | ||
"www.youtube.de/watch?v=yModCU1OVHY", | ||
"youtube.de/watch?v=yModCU1OVHY", | ||
"https://youtu.be/yModCU1OVHY", | ||
"http://youtu.be/yModCU1OVHY", | ||
"https://www.youtu.be/yModCU1OVHY", | ||
"http://www.youtu.be/yModCU1OVHY", | ||
"www.youtu.be/yModCU1OVHY", | ||
"youtu.be/yModCU1OVHY", | ||
"https://www.youtube.co.uk/watch?v=yModCU1OVHY", | ||
"https://www.youtube.co.uk/watch?v=yModCU1O", | ||
"https://www.youtube.com/watch?v=18pCXD709TI", | ||
"https://www.youtube.com/watch?v=18pCXD7", | ||
] | ||
|
||
not_youtube_urls = [ | ||
"https://example.com/video.mp4", | ||
"https://youtube/watch?v=", | ||
"https://www.youtubecom/watch?v=", | ||
"http://.youtube.com/watch?v=abc123", | ||
"https://youtube.co..uk/watch?v=abc123", | ||
"youtube/watch?v=abc123", | ||
"https:/youtube.com/watch?v=abc123", | ||
"http://youtube/watch?v=", | ||
"https://youtu.be/", | ||
"https://www.youtube.com/", | ||
"http://www.youtu.be/watch?v=", | ||
] | ||
|
||
for url in valid_youtube_urls: | ||
assert VideoSource.from_url(url) == VideoSource.YOUTUBE | ||
|
||
for url in not_youtube_urls: | ||
assert VideoSource.from_url(url) == VideoSource.AUTO |
Oops, something went wrong.