diff --git a/script.py b/script.py index 6747ca3..ce6669f 100644 --- a/script.py +++ b/script.py @@ -11,7 +11,7 @@ import sys import time from pathlib import Path, PurePath -from src.downloader import Direct, Gfycat, Imgur +from src.downloader import Direct, Gfycat, Imgur, Self from src.parser import LinkDesigner from src.searcher import getPosts from src.tools import (GLOBAL, createLogFile, jsonFile, nameCorrector, @@ -451,7 +451,22 @@ def download(submissions): print(exception) FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]}) downloadedCount -= 1 - + + elif submissions[i]['postType'] == 'self': + print("SELF") + try: + Self(directory,submissions[i]) + + except FileAlreadyExistsError: + print("It already exists") + downloadedCount -= 1 + duplicates += 1 + + # except Exception as exception: + # print(exception) + # FAILED_FILE.add({int(i+1):[str(exception),submissions[i]]}) + # downloadedCount -= 1 + else: print("No match found, skipping...") downloadedCount -= 1 diff --git a/src/downloader.py b/src/downloader.py index 1883dec..706b7c7 100644 --- a/src/downloader.py +++ b/src/downloader.py @@ -1,3 +1,4 @@ +import io import os import sys import urllib.request @@ -16,7 +17,7 @@ except ModuleNotFoundError: install("imgurpython") from imgurpython import * - +VanillaPrint = print print = printToFile def dlProgress(count, blockSize, totalSize): @@ -233,8 +234,13 @@ class Gfycat: fileDir = directory / (title+"_"+POST['postId']+POST['postExt']) tempDir = directory / (title+"_"+POST['postId']+".tmp") + try: + getFile(fileDir,tempDir,POST['mediaURL']) + except FileNameTooLong: + fileDir = directory / (POST['postId']+POST['postExt']) + tempDir = directory / (POST['postId']+".tmp") - getFile(fileDir,tempDir,POST['mediaURL']) + getFile(fileDir,tempDir,POST['mediaURL']) def getLink(self, url, query='