File size: 949 Bytes
7288748
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from typing import Any

from pytube import YouTube

from video import YoutubeVideo
from utils import accepts_types
from transforming.transform import Transform

class AddDescriptionTransform(Transform):
    """
    Transform a Video object using PyTube. Adds title to YouTube video DTO. 
    It's a concrete Transform.
    """
    
    @accepts_types(YoutubeVideo)
    def apply(self, video: YoutubeVideo) -> YoutubeVideo:
        
        yt = YouTube(video.url)
        
        video_With_description_params = {
            "channel_name": video.channel_name,
            "url": video.url,
            "title": video.title,
            "description": self._get_video_description(yt),
            "transcription": video.transcription,
            "segments": video.segments
        }
        
        return YoutubeVideo(**video_With_description_params)
    
    def _get_video_description(self, yt: Any) -> str:
        return str(yt.description)