Skip to content

Commit

Permalink
Automatically convert to new filepath
Browse files Browse the repository at this point in the history
If you're using the legacy filepath but want to use the new filepath, the script will automatically handle it for you.

Posts > Images > img.jpg >> Posts > Paid > Images > img.jpg

Image folder will automatically be removed IF there's nothing left in there.
  • Loading branch information
SecretShell committed May 12, 2020
1 parent 99747a7 commit 989cca2
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 5 deletions.
Empty file added extras/OFSorter/__init__.py
Empty file.
21 changes: 21 additions & 0 deletions extras/OFSorter/ofsorter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import os
import json
from itertools import chain
import shutil


def sorter(user_directory, api_type, location, metadata):
legacy_directory = os.path.join(user_directory, api_type, location)
if not os.path.isdir(legacy_directory):
return
legacy_files = os.listdir(legacy_directory)
metadata_directory = os.path.join(
user_directory, "Metadata", api_type+".json")
results = list(chain(*metadata["valid"]))
for result in results:
legacy_filepath = os.path.join(legacy_directory, result["filename"])
filepath = os.path.join(result["directory"], result["filename"])
if result["filename"] in legacy_files:
shutil.move(legacy_filepath, filepath)
if not os.listdir(legacy_directory):
os.removedirs(legacy_directory)
Empty file added extras/__init__.py
Empty file.
7 changes: 3 additions & 4 deletions modules/onlyfans.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import math
from urllib.parse import urlparse
from itertools import groupby
# import extras.OFSorter.ofsorter as ofsorter
import extras.OFSorter.ofsorter as ofsorter

log_download = setup_logger('downloads', 'downloads.log')

Expand Down Expand Up @@ -476,6 +476,8 @@ def process_mass_messages(message, limit):
if results["invalid"]:
results["invalid"] = [list(g) for k, g in groupby(
results["invalid"], key=lambda x: x["post_id"])]
if sort_free_paid_posts:
ofsorter.sorter(user_directory, api_type, location[0], results)
metadata_set.append(results)
media_set.append(results)

Expand All @@ -485,9 +487,6 @@ def process_mass_messages(message, limit):
os.makedirs(metadata_directory, exist_ok=True)
archive_directory = metadata_directory+api_type
export_archive(metadata_set, archive_directory)
# if sort_free_paid_posts:
# ofsorter.sorter(user_directory)
# print
return [media_set, directory]


Expand Down
2 changes: 1 addition & 1 deletion requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ beautifulsoup4
urllib3
win32-setctime
lxml
pysocks
pysocks

0 comments on commit 989cca2

Please sign in to comment.