aboutsummaryrefslogtreecommitdiff
path: root/importer/downloader.py
blob: 1dd168463c5bc2a5426cf979d23557eee67f447e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import re

from praw import Reddit

from importer.providers import GReddit, Gfycat, IReddit, Imgur, RedGifs, VReddit, YoutubeDlProviderBase, \
    RawImageProviderBase, Youtube


class Downloader:
    providers = [GReddit, Gfycat, IReddit, Imgur, RedGifs, VReddit, Youtube, RawImageProviderBase,
                 YoutubeDlProviderBase]

    def __init__(self, url: str, reddit: Reddit):
        self.Provider = next(filter(lambda x: re.match(x.regex, url), self.providers))
        self.url = url
        self.reddit = reddit

    def download(self):
        with self.Provider(url=self.url, reddit=self.reddit) as provider:
            provider.download()
            self.paths = provider.paths
            self.downloaded = provider.downloaded