This allows to download gallerys/multiple images in posts (#174)
Co-authored-by: Ali Parlakçı <parlakciali@gmail.com>
This commit is contained in:
parent
d731613f8a
commit
e0a2d2eda0
|
@ -19,6 +19,7 @@ from src.downloaders.Direct import Direct
|
|||
from src.downloaders.Erome import Erome
|
||||
from src.downloaders.Gfycat import Gfycat
|
||||
from src.downloaders.Imgur import Imgur
|
||||
from src.downloaders.Gallery import Gallery
|
||||
from src.downloaders.redgifs import Redgifs
|
||||
from src.downloaders.selfPost import SelfPost
|
||||
from src.downloaders.vreddit import VReddit
|
||||
|
@ -88,7 +89,7 @@ def downloadPost(SUBMISSION,directory):
|
|||
downloaders = {
|
||||
"imgur":Imgur,"gfycat":Gfycat,"erome":Erome,"direct":Direct,"self":SelfPost,
|
||||
"redgifs":Redgifs, "gifdeliverynetwork": GifDeliveryNetwork,
|
||||
"v.redd.it": VReddit, "youtube": Youtube, "gallery": gallery
|
||||
"v.redd.it": VReddit, "youtube": Youtube, "gallery": Gallery
|
||||
}
|
||||
|
||||
print()
|
||||
|
|
21
src/downloaders/Gallery.py
Normal file
21
src/downloaders/Gallery.py
Normal file
|
@ -0,0 +1,21 @@
|
|||
import os
|
||||
|
||||
from src.downloaders.downloaderUtils import getFile, getExtension
|
||||
|
||||
from src.errors import FileNameTooLong
|
||||
from src.utils import GLOBAL
|
||||
from src.utils import printToFile as print
|
||||
|
||||
class Gallery:
|
||||
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)
|
|
@ -224,6 +224,8 @@ def extractDetails(posts,SINGLE_POST=False):
|
|||
"%Y-%m-%d_%H-%M",
|
||||
time.localtime(submission.created_utc)
|
||||
))}
|
||||
if 'gallery' in submission.url:
|
||||
details['CONTENTURL'] = genLinksifGallery(submission.media_metadata)
|
||||
except AttributeError:
|
||||
pass
|
||||
|
||||
|
@ -238,7 +240,7 @@ def extractDetails(posts,SINGLE_POST=False):
|
|||
else:
|
||||
try:
|
||||
for submission in posts:
|
||||
|
||||
|
||||
if postCount % 100 == 0:
|
||||
sys.stdout.write("• ")
|
||||
sys.stdout.flush()
|
||||
|
@ -260,6 +262,8 @@ def extractDetails(posts,SINGLE_POST=False):
|
|||
"%Y-%m-%d_%H-%M",
|
||||
time.localtime(submission.created_utc)
|
||||
))}
|
||||
if 'gallery' in submission.url:
|
||||
details['CONTENTURL'] = genLinksifGallery(submission.media_metadata)
|
||||
except AttributeError:
|
||||
continue
|
||||
|
||||
|
@ -288,6 +292,9 @@ def extractDetails(posts,SINGLE_POST=False):
|
|||
|
||||
def matchWithDownloader(submission):
|
||||
|
||||
if 'gallery' in submission.url:
|
||||
return{'TYPE':'gallery'}
|
||||
|
||||
directLink = extractDirectLink(submission.url)
|
||||
if directLink:
|
||||
return {'TYPE': 'direct',
|
||||
|
@ -357,3 +364,9 @@ def extractDirectLink(URL):
|
|||
return URL
|
||||
else:
|
||||
return None
|
||||
|
||||
def genLinksifGallery(metadata):
|
||||
galleryImgUrls = list()
|
||||
for key in metadata:
|
||||
galleryImgUrls.append(metadata[key]['s']['u'].split('?')[0].replace('preview','i'))
|
||||
return galleryImgUrls
|
Loading…
Reference in a new issue