Show More
@@ -59,25 +59,8 b' class YouTubeDownloader(Downloader):' | |||||
59 | videos = yt.filter(YOUTUBE_VIDEO_FORMAT) |
|
59 | videos = yt.filter(YOUTUBE_VIDEO_FORMAT) | |
60 | if len(videos) > 0: |
|
60 | if len(videos) > 0: | |
61 | video = videos[0] |
|
61 | video = videos[0] | |
62 | filename = '{}.{}'.format(video.filename, video.extension) |
|
62 | return Downloader.download(video.url) | |
63 | try: |
|
|||
64 | video.download(on_progress=YouTubeDownloader.on_progress) |
|
|||
65 |
|
||||
66 | file = open(filename, 'rb') |
|
|||
67 | content = file.read() |
|
|||
68 | file.close() |
|
|||
69 |
|
||||
70 | os.remove(filename) |
|
|||
71 | return SimpleUploadedFile(filename, content, video.extension) |
|
|||
72 | except Exception as e: |
|
|||
73 | if os.path.isfile(filename): |
|
|||
74 | os.remove(filename) |
|
|||
75 | raise e |
|
|||
76 |
|
63 | |||
77 | @staticmethod |
|
64 | @staticmethod | |
78 | def handles(url: str) -> bool: |
|
65 | def handles(url: str) -> bool: | |
79 | return YOUTUBE_URL.match(url) |
|
66 | return YOUTUBE_URL.match(url) | |
80 |
|
||||
81 | @staticmethod |
|
|||
82 | def on_progress(bytes, file_size, start): |
|
|||
83 | validate_file_size(file_size) |
|
General Comments 0
You need to be logged in to leave comments.
Login now