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 __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'])
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)
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'])
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'])
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")
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")
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")
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" )