1
0
Fork 0
mirror of synced 2024-07-01 04:20:54 +12:00

This allows to download gallerys/multiple images in posts (#174)

Co-authored-by: Ali Parlakçı <parlakciali@gmail.com>
This commit is contained in:
Creepler13 2021-02-25 10:26:25 +01:00 committed by GitHub
parent d731613f8a
commit e0a2d2eda0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 37 additions and 2 deletions

View file

@ -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()

View 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)

View file

@ -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
@ -238,7 +240,7 @@ def extractDetails(posts,SINGLE_POST=False):
else: else:
try: try:
for submission in posts: for submission in posts:
if postCount % 100 == 0: if postCount % 100 == 0:
sys.stdout.write("") sys.stdout.write("")
sys.stdout.flush() sys.stdout.flush()
@ -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