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:
@@ -12,25 +12,19 @@ from src.errors import FileNotFoundError, FileAlreadyExistsError, AlbumNotDownlo
|
|||||||
class Gallery:
|
class Gallery:
|
||||||
def __init__(self, directory, post):
|
def __init__(self, directory, post):
|
||||||
|
|
||||||
link = post['CONTENTURL']
|
links = post['CONTENTURL']
|
||||||
self.rawData = self.getData(link)
|
|
||||||
|
|
||||||
self.directory = directory
|
|
||||||
self.post = post
|
|
||||||
|
|
||||||
images = {}
|
images = {}
|
||||||
count = 0
|
count = 0
|
||||||
for model in self.rawData['posts']['models']:
|
for link in links:
|
||||||
try:
|
path = urllib.parse.urlparse(link).path
|
||||||
for item in self.rawData['posts']['models'][model]['media']['gallery']['items']:
|
base = os.path.basename(path)
|
||||||
try:
|
name = os.path.splitext(base)[0]
|
||||||
images[count] = {'id': item['mediaId'], 'url': self.rawData['posts'][
|
images[count] = {'id': name, 'url': link}
|
||||||
'models'][model]['media']['mediaMetadata'][item['mediaId']]['s']['u']}
|
count = count + 1
|
||||||
count = count + 1
|
|
||||||
except BaseException:
|
self.directory = directory
|
||||||
continue
|
self.post = post
|
||||||
except BaseException:
|
|
||||||
continue
|
|
||||||
|
|
||||||
self.downloadAlbum(images, count)
|
self.downloadAlbum(images, count)
|
||||||
|
|
||||||
|
|||||||
@@ -368,6 +368,7 @@ def extractDirectLink(URL):
|
|||||||
|
|
||||||
def genLinksifGallery(metadata):
|
def genLinksifGallery(metadata):
|
||||||
galleryImgUrls = list()
|
galleryImgUrls = list()
|
||||||
for key in metadata:
|
if metadata is not None:
|
||||||
galleryImgUrls.append(metadata[key]['s']['u'].split('?')[0].replace('preview','i'))
|
for key in metadata:
|
||||||
|
galleryImgUrls.append(metadata[key]['s']['u'].split('?')[0].replace('preview','i'))
|
||||||
return galleryImgUrls
|
return galleryImgUrls
|
||||||
|
|||||||
Reference in New Issue
Block a user