aboutsummaryrefslogtreecommitdiff
path: root/main.py
diff options
context:
space:
mode:
Diffstat (limited to 'main.py')
-rw-r--r--main.py44
1 files changed, 34 insertions, 10 deletions
diff --git a/main.py b/main.py
index 036aab3..2f34b3a 100644
--- a/main.py
+++ b/main.py
@@ -7,8 +7,8 @@ import praw
from nextcloud import NextCloud
from praw.models.util import stream_generator
+from gallery_dl.job import DownloadJob
-from importer.downloader import Downloader
from importer.uploader import upload_file, create_folders
levels = {
@@ -55,6 +55,33 @@ parser.add_argument('-l', '--log-level',
choices=levels.keys(),
help=f'it will set log level.')
+
+def get_list_of_files(dirName):
+ # create a list of file and sub directories
+ # names in the given directory
+ listOfFile = os.listdir(dirName)
+ allFiles = list()
+ # Iterate over all the entries
+ for entry in listOfFile:
+ # Create full path
+ fullPath = os.path.join(dirName, entry)
+ # If entry is a directory then get the list of files in this directory
+ if os.path.isdir(fullPath):
+ allFiles = allFiles + get_list_of_files(fullPath)
+ else:
+ allFiles.append(fullPath)
+
+ return allFiles
+
+
+def download(url) -> [str]:
+ d = DownloadJob(url=url)
+ d.run()
+ basedir = d.pathfmt.basedirectory
+ files = get_list_of_files(basedir)
+ return files
+
+
if __name__ == "__main__":
args = parser.parse_args()
@@ -81,15 +108,12 @@ if __name__ == "__main__":
try:
url = post.url
create_folders(f"{args.nextcloud_path}/{post.subreddit}/", nxc)
- d = Downloader(url=url, reddit=reddit)
- with d.provider() as provider:
- provider.download()
- logging.info(f"{post.id} from {post.subreddit} downloaded")
- for path in provider.paths:
- if "-mobile" in path: # Remove mobile version
- continue
- upload_file(path, f"{args.nextcloud_path}/{post.subreddit}/{path}", nxc)
- logging.info(f"{path} uploaded")
+ logging.info(f"{post.id} from {post.subreddit} downloaded")
+ for path in download(url):
+ filename = os.path.basename(path)
+ upload_file(path, f"{args.nextcloud_path}/{post.subreddit}/{filename}", nxc)
+ os.unlink(path)
+ logging.info(f"{path} uploaded")
except Exception as e:
logging.error(e)