def downloadAlbum(self, images):
        folderName = GLOBAL.config['filename'].format(**self.post)
        folderDir = self.directory / folderName

        imagesLenght = images["count"]
        howManyDownloaded = 0
        duplicates = 0

        try:
            if not os.path.exists(folderDir):
                os.makedirs(folderDir)
        except FileNotFoundError:
            folderDir = self.directory / self.post['POSTID']
            os.makedirs(folderDir)

        print(folderName)

        for i in range(imagesLenght):

            extension = self.validateExtension(images["images"][i]["ext"])

            imageURL = self.IMGUR_IMAGE_DOMAIN + images["images"][i][
                "hash"] + extension

            filename = "_".join([
                str(i + 1),
                nameCorrector(images["images"][i]['title']),
                images["images"][i]['hash']
            ]) + extension
            shortFilename = str(i + 1) + "_" + images["images"][i]['hash']

            print("\n  ({}/{})".format(i + 1, imagesLenght))

            try:
                getFile(filename, shortFilename, folderDir, imageURL, indent=2)
                howManyDownloaded += 1
                print()

            except FileAlreadyExistsError:
                print("  The file already exists" + " " * 10, end="\n\n")
                duplicates += 1

            except TypeInSkip:
                print("  Skipping...")
                howManyDownloaded += 1

            except Exception as exception:
                print("\n  Could not get the file")
                print(
                    "  " +
                    "{class_name}: {info}\nSee CONSOLE_LOG.txt for more information"
                    .format(class_name=exception.__class__.__name__,
                            info=str(exception)) + "\n")
                print(GLOBAL.log_stream.getvalue(), noPrint=True)

        if duplicates == imagesLenght:
            raise FileAlreadyExistsError
        elif howManyDownloaded + duplicates < imagesLenght:
            raise AlbumNotDownloadedCompletely(
                "Album Not Downloaded Completely")
    def __init__(self, directory, POST):
        try:
            POST['mediaURL'] = self.getLink(POST['postURL'])
        except IndexError:
            raise NotADownloadableLinkError("Could not read the page source")

        POST['postExt'] = getExtension(POST['mediaURL'])

        if not os.path.exists(directory): os.makedirs(directory)
        title = nameCorrector(POST['postTitle'])
        """Filenames are declared here"""

        print(POST["postSubmitter"] + "_" + title + "_" + POST['postId'] +
              POST['postExt'])

        fileDir = directory / (POST["postSubmitter"] + "_" + title + "_" +
                               POST['postId'] + POST['postExt'])
        tempDir = directory / (POST["postSubmitter"] + "_" + title + "_" +
                               POST['postId'] + ".tmp")

        try:
            getFile(fileDir, tempDir, POST['mediaURL'])
        except FileNameTooLong:
            fileDir = directory / (POST['postId'] + POST['postExt'])
            tempDir = directory / (POST['postId'] + ".tmp")

            getFile(fileDir, tempDir, POST['mediaURL'])
    def download(self, image):
        extension = self.validateExtension(image["ext"])
        imageURL = self.IMGUR_IMAGE_DOMAIN + image["hash"] + extension

        filename = GLOBAL.config['filename'].format(**self.post) + extension
        shortFilename = self.post['POSTID'] + extension

        getFile(filename, shortFilename, self.directory, imageURL)
Beispiel #4
0
    def __init__(self, directory, POST):
        POST['EXTENSION'] = getExtension(POST['CONTENTURL'])
        if not os.path.exists(directory): os.makedirs(directory)

        filename = GLOBAL.config['filename'].format(**POST) + POST["EXTENSION"]
        shortFilename = POST['POSTID'] + POST['EXTENSION']

        getFile(filename, shortFilename, directory, POST['CONTENTURL'])
Beispiel #5
0
    def downloadAlbum(self, images, count):
        folderName = GLOBAL.config['filename'].format(**self.post)
        folderDir = self.directory / folderName

        howManyDownloaded = 0
        duplicates = 0

        try:
            if not os.path.exists(folderDir):
                os.makedirs(folderDir)
        except FileNotFoundError:
            folderDir = self.directory / self.post['POSTID']
            os.makedirs(folderDir)

        print(folderName)

        for i in range(count):
            path = urllib.parse.urlparse(images[i]['url']).path
            extension = os.path.splitext(path)[1]

            filename = "_".join([
                str(i + 1), images[i]['id']
            ]) + extension
            shortFilename = str(i + 1) + "_" + images[i]['id']

            print("\n  ({}/{})".format(i + 1, count))

            try:
                getFile(filename, shortFilename, folderDir,
                        images[i]['url'], indent=2)
                howManyDownloaded += 1
                print()

            except FileAlreadyExistsError:
                print("  The file already exists" + " " * 10, end="\n\n")
                duplicates += 1

            except TypeInSkip:
                print("  Skipping...")
                howManyDownloaded += 1

            except Exception as exception:
                print("\n  Could not get the file")
                print(
                    "  " +
                    "{class_name}: {info}\nSee CONSOLE_LOG.txt for more information".format(
                        class_name=exception.__class__.__name__,
                        info=str(exception)) +
                    "\n")
                print(GLOBAL.log_stream.getvalue(), noPrint=True)

        if duplicates == count:
            raise FileAlreadyExistsError
        if howManyDownloaded + duplicates < count:
            raise AlbumNotDownloadedCompletely(
                "Album Not Downloaded Completely"
            )
    def __init__(self, directory, POST):
        i = 0
        for key in POST['CONTENTURL']:
            i = i + 1
            extension = getExtension(key)
            if not os.path.exists(directory): os.makedirs(directory)

            filename = GLOBAL.config['filename'].format(
                **POST) + ' - ' + str(i) + extension
            print(filename)
            shortFilename = POST['POSTID'] + ' - ' + str(i) + extension

            getFile(filename, shortFilename, directory, key)
Beispiel #7
0
    def __init__(self, directory, POST):
        try:
            POST['MEDIAURL'] = self.getLink(POST['CONTENTURL'])
        except IndexError:
            raise NotADownloadableLinkError("Could not read the page source")

        POST['EXTENSION'] = getExtension(POST['MEDIAURL'])

        if not os.path.exists(directory): os.makedirs(directory)

        filename = GLOBAL.config['filename'].format(**POST) + POST["EXTENSION"]
        shortFilename = POST['POSTID'] + POST['EXTENSION']

        getFile(filename, shortFilename, directory, POST['MEDIAURL'])
Beispiel #8
0
    def __init__(self, directory, post):
        extension = ".mp4"
        if not os.path.exists(directory):
            os.makedirs(directory)

        filename = GLOBAL.config['filename'].format(**post) + extension
        shortFilename = post['POSTID'] + extension

        try:
            FNULL = open(os.devnull, 'w')
            subprocess.call("ffmpeg", stdout=FNULL, stderr=subprocess.STDOUT)
        except BaseException:
            getFile(filename, shortFilename, directory, post['CONTENTURL'])
            print("FFMPEG library not found, skipping merging video and audio")
        else:
            videoName = post['POSTID'] + "_video"
            videoURL = post['CONTENTURL']
            audioName = post['POSTID'] + "_audio"
            audioURL = videoURL[:videoURL.rfind('/')] + '/DASH_audio.mp4'

            print(directory, filename, sep="\n")

            getFile(videoName, videoName, directory, videoURL, silent=True)
            getFile(audioName, audioName, directory, audioURL, silent=True)
            try:
                self._mergeAudio(videoName, audioName, filename, shortFilename,
                                 directory)
            except KeyboardInterrupt:
                os.remove(directory / filename)
                os.remove(directory / audioName)

                os.rename(directory / videoName, directory / filename)
Beispiel #9
0
    def __init__(self,directory,POST):
        POST['postExt'] = getExtension(POST['postURL'])
        if not os.path.exists(directory): os.makedirs(directory)
        title = nameCorrector(POST['postTitle'])

        """Filenames are declared here"""

        print(POST["postSubmitter"]+"_"+title+"_"+POST['postId']+POST['postExt'])

        fileDir = directory / (
            POST["postSubmitter"]+"_"+title+"_"+POST['postId']+POST['postExt']
        )
        tempDir = directory / (
            POST["postSubmitter"]+"_"+title+"_"+POST['postId']+".tmp"
        )

        try:
            getFile(fileDir,tempDir,POST['postURL'])
        except FileNameTooLong:
            fileDir = directory / (POST['postId']+POST['postExt'])
            tempDir = directory / (POST['postId']+".tmp")

            getFile(fileDir,tempDir,POST['postURL'])
Beispiel #10
0
    def __init__(self, directory, post):
        extension = ".mp4"
        if not os.path.exists(directory): os.makedirs(directory)

        filename = GLOBAL.config['filename'].format(**post) + extension
        shortFilename = post['POSTID'] + extension

        try:
            FNULL = open(os.devnull, 'w')
            subprocess.call("ffmpeg", stdout=FNULL, stderr=subprocess.STDOUT)
        except:
            getFile(filename, shortFilename, directory, post['CONTENTURL'])
            print("FFMPEG library not found, skipping merging video and audio")
        else:
            videoName = post['POSTID'] + "_video"
            videoURL = post['CONTENTURL']
            audioName = post['POSTID'] + "_audio"
            audioURL = [
                videoURL[:videoURL.rfind('/')] + '/DASH_audio.mp4',
                videoURL[:videoURL.rfind('/')] + '/audio?source=fallback.mp4'
            ]

            print(directory, filename, sep="\n")

            getFile(videoName, videoName, directory, videoURL, silent=True)

            for x in audioURL:
                try:
                    getFile(audioName, audioName, directory, x, silent=True)
                except Exception as e:
                    pass
                else:
                    break
            else:
                # Could not find a valid audio file, do not try to merge.
                print("No audio for this video.")
                os.rename(directory / videoName, directory / filename)
                return

            try:
                self._mergeAudio(videoName, audioName, filename, shortFilename,
                                 directory)
            except KeyboardInterrupt:
                os.remove(directory / filename)
                os.remove(directory / audioName)

                os.rename(directory / videoName, directory / filename)
    def __init__(self, directory, post):
        try:
            IMAGES = self.getLinks(post['CONTENTURL'])
        except urllib.error.HTTPError:
            raise NotADownloadableLinkError("Not a downloadable link")

        imagesLenght = len(IMAGES)
        howManyDownloaded = imagesLenght
        duplicates = 0

        if imagesLenght == 1:

            extension = getExtension(IMAGES[0])
            """Filenames are declared here"""

            filename = GLOBAL.config['filename'].format(
                **post) + post["EXTENSION"]
            shortFilename = post['POSTID'] + extension

            imageURL = IMAGES[0]
            if 'https://' not in imageURL or 'http://' not in imageURL:
                imageURL = "https://" + imageURL

            getFile(filename, shortFilename, directory, imageURL)

        else:
            filename = GLOBAL.config['filename'].format(**post)

            print(filename)

            folderDir = directory / filename

            try:
                if not os.path.exists(folderDir):
                    os.makedirs(folderDir)
            except FileNotFoundError:
                folderDir = directory / post['POSTID']
                os.makedirs(folderDir)

            for i in range(imagesLenght):

                extension = getExtension(IMAGES[i])

                filename = str(i + 1) + extension
                imageURL = IMAGES[i]
                if 'https://' not in imageURL and 'http://' not in imageURL:
                    imageURL = "https://" + imageURL

                print("  ({}/{})".format(i + 1, imagesLenght))
                print("  {}".format(filename))

                try:
                    getFile(filename, filename, folderDir, imageURL, indent=2)
                    print()
                except FileAlreadyExistsError:
                    print("  The file already exists" + " " * 10, end="\n\n")
                    duplicates += 1
                    howManyDownloaded -= 1

                except Exception as exception:
                    # raise exception
                    print("\n  Could not get the file")
                    print("  " + "{class_name}: {info}".format(
                        class_name=exception.__class__.__name__,
                        info=str(exception)) + "\n")
                    howManyDownloaded -= 1

            if duplicates == imagesLenght:
                raise FileAlreadyExistsError
            elif howManyDownloaded + duplicates < imagesLenght:
                raise AlbumNotDownloadedCompletely(
                    "Album Not Downloaded Completely")
Beispiel #12
0
    def __init__(self, directory, post):
        self.imgurClient = self.initImgur()

        imgurID = self.getId(post['CONTENTURL'])
        content = self.getLink(imgurID)

        if not os.path.exists(directory): os.makedirs(directory)

        if content['type'] == 'image':

            try:
                post['MEDIAURL'] = content['object'].mp4
            except AttributeError:
                post['MEDIAURL'] = content['object'].link

            post['EXTENSION'] = getExtension(post['MEDIAURL'])

            filename = GLOBAL.config['filename'].format(
                **post) + post["EXTENSION"]
            shortFilename = post['POSTID'] + post['EXTENSION']

            getFile(filename, shortFilename, directory, post['MEDIAURL'])

        elif content['type'] == 'album':
            images = content['object'].images
            imagesLenght = len(images)
            howManyDownloaded = imagesLenght
            duplicates = 0

            filename = GLOBAL.config['filename'].format(**post)

            print(filename)

            folderDir = directory / filename

            try:
                if not os.path.exists(folderDir):
                    os.makedirs(folderDir)
            except FileNotFoundError:
                folderDir = directory / post['POSTID']
                os.makedirs(folderDir)

            for i in range(imagesLenght):
                try:
                    imageURL = images[i]['mp4']
                except KeyError:
                    imageURL = images[i]['link']

                images[i]['Ext'] = getExtension(imageURL)

                filename = (str(i + 1) + "_" +
                            nameCorrector(str(images[i]['title'])) + "_" +
                            images[i]['id'])

                shortFilename = (str(i + 1) + "_" + images[i]['id'])

                print("\n  ({}/{})".format(i + 1, imagesLenght))

                try:
                    getFile(filename,
                            shortFilename,
                            folderDir,
                            imageURL,
                            indent=2)
                    print()
                except FileAlreadyExistsError:
                    print("  The file already exists" + " " * 10, end="\n\n")
                    duplicates += 1
                    howManyDownloaded -= 1

                except Exception as exception:
                    print("\n  Could not get the file")
                    print("  " + "{class_name}: {info}".format(
                        class_name=exception.__class__.__name__,
                        info=str(exception)) + "\n")
                    howManyDownloaded -= 1

            if duplicates == imagesLenght:
                raise FileAlreadyExistsError
            elif howManyDownloaded + duplicates < imagesLenght:
                raise AlbumNotDownloadedCompletely(
                    "Album Not Downloaded Completely")
Beispiel #13
0
    def __init__(self, directory, post):
        try:
            IMAGES = self.getLinks(post['postURL'])
        except urllib.error.HTTPError:
            raise NotADownloadableLinkError("Not a downloadable link")

        imagesLenght = len(IMAGES)
        howManyDownloaded = imagesLenght
        duplicates = 0

        if imagesLenght == 1:

            extension = getExtension(IMAGES[0])
            """Filenames are declared here"""

            title = nameCorrector(post['postTitle'])
            print(post["postSubmitter"] + "_" + title + "_" + post['postId'] +
                  extension)

            fileDir = directory / (post["postSubmitter"] + "_" + title + "_" +
                                   post['postId'] + extension)
            tempDir = directory / (post["postSubmitter"] + "_" + title + "_" +
                                   post['postId'] + ".tmp")

            imageURL = IMAGES[0]
            if 'https://' not in imageURL and 'http://' not in imageURL:
                imageURL = "https://" + imageURL

            try:
                getFile(fileDir, tempDir, imageURL)
            except FileNameTooLong:
                fileDir = directory / (post['postId'] + extension)
                tempDir = directory / (post['postId'] + '.tmp')
                getFile(fileDir, tempDir, imageURL)

        else:
            title = nameCorrector(post['postTitle'])
            print(post["postSubmitter"] + "_" + title + "_" + post['postId'],
                  end="\n\n")

            folderDir = directory / (post["postSubmitter"] + "_" + title +
                                     "_" + post['postId'])

            try:
                if not os.path.exists(folderDir):
                    os.makedirs(folderDir)
            except FileNotFoundError:
                folderDir = directory / post['postId']
                os.makedirs(folderDir)

            for i in range(imagesLenght):

                extension = getExtension(IMAGES[i])

                fileName = str(i + 1)
                imageURL = IMAGES[i]
                if 'https://' not in imageURL and 'http://' not in imageURL:
                    imageURL = "https://" + imageURL

                fileDir = folderDir / (fileName + extension)
                tempDir = folderDir / (fileName + ".tmp")

                print("  ({}/{})".format(i + 1, imagesLenght))
                print("  {}".format(fileName + extension))

                try:
                    getFile(fileDir, tempDir, imageURL, indent=2)
                    print()
                except FileAlreadyExistsError:
                    print("  The file already exists" + " " * 10, end="\n\n")
                    duplicates += 1
                    howManyDownloaded -= 1

                except Exception as exception:
                    # raise exception
                    print("\n  Could not get the file")
                    print("  " + "{class_name}: {info}".format(
                        class_name=exception.__class__.__name__,
                        info=str(exception)) + "\n")
                    howManyDownloaded -= 1

            if duplicates == imagesLenght:
                raise FileAlreadyExistsError
            elif howManyDownloaded + duplicates < imagesLenght:
                raise AlbumNotDownloadedCompletely(
                    "Album Not Downloaded Completely")
Beispiel #14
0
    def __init__(self,directory,post):
        self.imgurClient = self.initImgur()

        imgurID = self.getId(post['postURL'])
        content = self.getLink(imgurID)

        if not os.path.exists(directory): os.makedirs(directory)

        if content['type'] == 'image':

            try:
                post['mediaURL'] = content['object'].mp4
            except AttributeError:
                post['mediaURL'] = content['object'].link

            post['postExt'] = getExtension(post['mediaURL'])
            
            title = nameCorrector(post['postTitle'])

            """Filenames are declared here"""

            print(post["postSubmitter"]+"_"+title+"_"+post['postId']+post['postExt'])

            fileDir = directory / (
                post["postSubmitter"]
                + "_" + title
                + "_" + post['postId'] 
                + post['postExt']
            )

            tempDir = directory / (
                post["postSubmitter"]
                + "_" + title 
                + "_" + post['postId'] 
                + ".tmp"
            )

            try:
                getFile(fileDir,tempDir,post['mediaURL'])
            except FileNameTooLong:
                fileDir = directory / post['postId'] + post['postExt']
                tempDir = directory / post['postId'] + '.tmp'
                getFile(fileDir,tempDir,post['mediaURL'])

        elif content['type'] == 'album':
            images = content['object'].images
            imagesLenght = len(images)
            howManyDownloaded = imagesLenght
            duplicates = 0

            title = nameCorrector(post['postTitle'])
            print(post["postSubmitter"]+"_"+title+"_"+post['postId'],end="\n\n")

            folderDir = directory / (
                post["postSubmitter"] + "_" + title + "_" + post['postId']
            )

            try:
                if not os.path.exists(folderDir):
                    os.makedirs(folderDir)
            except FileNotFoundError:
                folderDir = directory / post['postId']
                os.makedirs(folderDir)

            for i in range(imagesLenght):
                try:
                    imageURL = images[i]['mp4']
                except KeyError:
                    imageURL = images[i]['link']

                images[i]['Ext'] = getExtension(imageURL)

                fileName = (str(i+1)
                            + "_"
                            + nameCorrector(str(images[i]['title']))
                            + "_"
                            + images[i]['id'])

                """Filenames are declared here"""

                fileDir = folderDir / (fileName + images[i]['Ext'])
                tempDir = folderDir / (fileName + ".tmp")

                print("  ({}/{})".format(i+1,imagesLenght))
                print("  {}".format(fileName+images[i]['Ext']))

                try:
                    getFile(fileDir,tempDir,imageURL,indent=2)
                    print()
                except FileAlreadyExistsError:
                    print("  The file already exists" + " "*10,end="\n\n")
                    duplicates += 1
                    howManyDownloaded -= 1

                # IF FILE NAME IS TOO LONG, IT WONT REGISTER
                except FileNameTooLong:
                    fileName = (str(i+1) + "_" + images[i]['id'])
                    fileDir = folderDir / (fileName + images[i]['Ext'])
                    tempDir = folderDir / (fileName + ".tmp")
                    try:
                        getFile(fileDir,tempDir,imageURL,indent=2)
                    # IF STILL TOO LONG
                    except FileNameTooLong:
                        fileName = str(i+1)
                        fileDir = folderDir / (fileName + images[i]['Ext'])
                        tempDir = folderDir / (fileName + ".tmp")
                        getFile(fileDir,tempDir,imageURL,indent=2)

                except Exception as exception:
                    print("\n  Could not get the file")
                    print(
                        "  "
                        + "{class_name}: {info}".format(
                            class_name=exception.__class__.__name__,
                            info=str(exception)
                        )
                        + "\n"
                    )
                    howManyDownloaded -= 1

            if duplicates == imagesLenght:
                raise FileAlreadyExistsError
            elif howManyDownloaded + duplicates < imagesLenght:
                raise AlbumNotDownloadedCompletely(
                    "Album Not Downloaded Completely"
                )