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
3 changed files with 37 additions and 2 deletions
|
@ -19,6 +19,7 @@ from src.downloaders.Direct import Direct
|
||||||
from src.downloaders.Erome import Erome
|
from src.downloaders.Erome import Erome
|
||||||
from src.downloaders.Gfycat import Gfycat
|
from src.downloaders.Gfycat import Gfycat
|
||||||
from src.downloaders.Imgur import Imgur
|
from src.downloaders.Imgur import Imgur
|
||||||
|
from src.downloaders.Gallery import Gallery
|
||||||
from src.downloaders.redgifs import Redgifs
|
from src.downloaders.redgifs import Redgifs
|
||||||
from src.downloaders.selfPost import SelfPost
|
from src.downloaders.selfPost import SelfPost
|
||||||
from src.downloaders.vreddit import VReddit
|
from src.downloaders.vreddit import VReddit
|
||||||
|
@ -88,7 +89,7 @@ def downloadPost(SUBMISSION,directory):
|
||||||
downloaders = {
|
downloaders = {
|
||||||
"imgur":Imgur,"gfycat":Gfycat,"erome":Erome,"direct":Direct,"self":SelfPost,
|
"imgur":Imgur,"gfycat":Gfycat,"erome":Erome,"direct":Direct,"self":SelfPost,
|
||||||
"redgifs":Redgifs, "gifdeliverynetwork": GifDeliveryNetwork,
|
"redgifs":Redgifs, "gifdeliverynetwork": GifDeliveryNetwork,
|
||||||
"v.redd.it": VReddit, "youtube": Youtube, "gallery": gallery
|
"v.redd.it": VReddit, "youtube": Youtube, "gallery": Gallery
|
||||||
}
|
}
|
||||||
|
|
||||||
print()
|
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",
|
"%Y-%m-%d_%H-%M",
|
||||||
time.localtime(submission.created_utc)
|
time.localtime(submission.created_utc)
|
||||||
))}
|
))}
|
||||||
|
if 'gallery' in submission.url:
|
||||||
|
details['CONTENTURL'] = genLinksifGallery(submission.media_metadata)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
@ -260,6 +262,8 @@ def extractDetails(posts,SINGLE_POST=False):
|
||||||
"%Y-%m-%d_%H-%M",
|
"%Y-%m-%d_%H-%M",
|
||||||
time.localtime(submission.created_utc)
|
time.localtime(submission.created_utc)
|
||||||
))}
|
))}
|
||||||
|
if 'gallery' in submission.url:
|
||||||
|
details['CONTENTURL'] = genLinksifGallery(submission.media_metadata)
|
||||||
except AttributeError:
|
except AttributeError:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
|
@ -288,6 +292,9 @@ def extractDetails(posts,SINGLE_POST=False):
|
||||||
|
|
||||||
def matchWithDownloader(submission):
|
def matchWithDownloader(submission):
|
||||||
|
|
||||||
|
if 'gallery' in submission.url:
|
||||||
|
return{'TYPE':'gallery'}
|
||||||
|
|
||||||
directLink = extractDirectLink(submission.url)
|
directLink = extractDirectLink(submission.url)
|
||||||
if directLink:
|
if directLink:
|
||||||
return {'TYPE': 'direct',
|
return {'TYPE': 'direct',
|
||||||
|
@ -357,3 +364,9 @@ def extractDirectLink(URL):
|
||||||
return URL
|
return URL
|
||||||
else:
|
else:
|
||||||
return None
|
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