Fix error "'NoneType' object is not iterable" (issue #214) and "InvalidSchema: No connection adapters were found" (issue #198) (#215)

* Fix error "'NoneType' object is not iterable"

* Fixed downloading galleries
This commit is contained in:
Stas Kornienko
2021-03-27 12:20:29 +03:00
committed by GitHub
parent 30fe10e689
commit ec23430027
2 changed files with 14 additions and 19 deletions

View File

@@ -12,25 +12,19 @@ from src.errors import FileNotFoundError, FileAlreadyExistsError, AlbumNotDownlo
class Gallery:
def __init__(self, directory, post):
link = post['CONTENTURL']
self.rawData = self.getData(link)
self.directory = directory
self.post = post
links = post['CONTENTURL']
images = {}
count = 0
for model in self.rawData['posts']['models']:
try:
for item in self.rawData['posts']['models'][model]['media']['gallery']['items']:
try:
images[count] = {'id': item['mediaId'], 'url': self.rawData['posts'][
'models'][model]['media']['mediaMetadata'][item['mediaId']]['s']['u']}
count = count + 1
except BaseException:
continue
except BaseException:
continue
for link in links:
path = urllib.parse.urlparse(link).path
base = os.path.basename(path)
name = os.path.splitext(base)[0]
images[count] = {'id': name, 'url': link}
count = count + 1
self.directory = directory
self.post = post
self.downloadAlbum(images, count)

View File

@@ -368,6 +368,7 @@ def extractDirectLink(URL):
def genLinksifGallery(metadata):
galleryImgUrls = list()
for key in metadata:
galleryImgUrls.append(metadata[key]['s']['u'].split('?')[0].replace('preview','i'))
if metadata is not None:
for key in metadata:
galleryImgUrls.append(metadata[key]['s']['u'].split('?')[0].replace('preview','i'))
return galleryImgUrls