diff --git a/ofscraper/commands/managers/db.py b/ofscraper/commands/managers/db.py index 7848a3c8..93792d62 100644 --- a/ofscraper/commands/managers/db.py +++ b/ofscraper/commands/managers/db.py @@ -1,5 +1,6 @@ import logging import time +import datetime import arrow from rich.table import Table from rich import box @@ -102,6 +103,11 @@ def filter_media(self) : medias=[media for media in medias if (media["size"] or 0 )<= settings.get_size_max()] if settings.get_size_min(): medias=[media for media in medias if (media["size"] or 0 )>= settings.get_size_min()] + #length + if settings.get_max_length(): + medias=[media for media in medias if self._convert_seconds(media)<= settings.get_max_length()] + if settings.get_min_length(): + medias=[media for media in medias if self._convert_seconds(media)>= settings.get_min_length()] # media type if all(element in settings.get_mediatypes() for element in ["Audios", "Videos", "Images"]): pass @@ -200,4 +206,10 @@ def print_media(self): #allow logs to print time.sleep(1.5) self.print_dictionary_table() - \ No newline at end of file + def _convert_seconds(self,dictionary): + if not dictionary.get("duration"): + return 0 + x= time.strptime(":".join(dictionary.get("duration").split(":")[-3:]),'%H:%M:%S') + curr_sec=datetime.timedelta(hours=x.tm_hour,minutes=x.tm_min,seconds=x.tm_sec).total_seconds() + day_sec=int(dictionary.get("duration").split(":")[0])*3600 + return curr_sec+day_sec diff --git a/ofscraper/db/operations_/media.py b/ofscraper/db/operations_/media.py index d8e4c677..0d4d7f8a 100644 --- a/ofscraper/db/operations_/media.py +++ b/ofscraper/db/operations_/media.py @@ -160,14 +160,14 @@ SELECT media_id,post_id,link,directory filename,size,api_type,media_type, -preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked +preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked,duration FROM medias where LOWER(api_type) in ('timeline','posts','post') and model_id=(?) """ getArchivedMedia = """ SELECT media_id,post_id,link,directory filename,size,api_type,media_type, -preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked +preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked,duration FROM medias where LOWER(api_type) in ('archived') and model_id=(?) """ @@ -175,7 +175,7 @@ SELECT media_id,post_id,link,directory filename,size,api_type,media_type, -preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked +preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked,duration FROM medias where LOWER(api_type) in ('pinned') and model_id=(?) """ @@ -183,28 +183,28 @@ SELECT media_id,post_id,link,directory filename,size,api_type,media_type, -preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked +preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocke,duration FROM medias where LOWER(api_type) in ('stories') and model_id=(?) """ getHighlightsMedia = """ SELECT media_id,post_id,link,directory filename,size,api_type,media_type, -preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked +preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked,duration FROM medias where LOWER(api_type) in ('highlights') and model_id=(?) """ getStreamsMedia = """ SELECT media_id,post_id,link,directory filename,size,api_type,media_type, -preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked +preview,linked,downloaded,created_at,posted_at,hash,model_id,unlocked,duration FROM medias where LOWER(api_type) in ('streams') and model_id=(?) """ getMessagesMedia = """ SELECT media_id, post_id, link, directory, filename, size, api_type, media_type, -preview, linked, downloaded, created_at, posted_at, hash, model_id, unlocked +preview, linked, downloaded, created_at, posted_at, hash, model_id, unlocked,duration FROM medias WHERE LOWER(api_type) IN ('message', 'messages') -- Use IN for multiple values AND model_id = ?; -- Prepared statement placeholder