Skip to content

Commit

Permalink
fix youtube url detection
Browse files Browse the repository at this point in the history
  • Loading branch information
jrodal98 committed May 26, 2023
1 parent b7d1053 commit 41508da
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 2 deletions.
2 changes: 1 addition & 1 deletion tests/manual/inject_urls_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@

from tests.manual.test_helper import run_tests

text = "This is my website: https://www.jrodal.com/ and this is one of my posts: https://www.jrodal.com/posts/how-to-deploy-rocket-rust-web-app-on-vps/"
text = "This is my website: https://www.jrodal.com/ and this is one of my posts: https://www.jrodal.com/posts/how-to-deploy-rocket-rust-web-app-on-vps/ and this is a yt video: https://www.youtube.com/watch?v=--khbXchTeE" # noqa

if __name__ == "__main__":
run_tests(text)
2 changes: 1 addition & 1 deletion tldrwl/summarize.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ def __init__(self, *, text_summarizer: Optional[TextSummarizer] = None) -> None:
self._summarizer = text_summarizer or Gpt35TurboTextSummarizer()

async def _transform_text(self, text: str) -> str:
if YoutubeTransformer.get_video_id(text):
if YoutubeTransformer.is_youtube_url(text):
self._logger.debug(f"Using YoutubeSummarizer on {text}")
return await YoutubeTransformer(text).get_text()
elif WebpageTransformer.is_url(text):
Expand Down
5 changes: 5 additions & 0 deletions tldrwl/transformers/youtube_transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
from tldrwl.transformers.transformer import Transformer

from tldrwl.exception import TldrwlVideoUrlParsingException
from tldrwl.transformers.webpage_transformer import WebpageTransformer


class YoutubeTransformer(Transformer):
Expand All @@ -23,6 +24,10 @@ def __init__(self, url: str) -> None:
self._url = url
self._logger = logging.getLogger(__name__)

@classmethod
def is_youtube_url(cls, url: str) -> bool:
return WebpageTransformer.is_url(url) and cls.get_video_id(url) is not None

@classmethod
def get_video_id(cls, url: str) -> Optional[str]:
match = cls._pattern.search(url)
Expand Down

0 comments on commit 41508da

Please sign in to comment.