Skip to content

Commit

Permalink
add length
Browse files Browse the repository at this point in the history
  • Loading branch information
datawhores committed Aug 27, 2024
1 parent f50eb68 commit 73444f5
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
14 changes: 13 additions & 1 deletion ofscraper/commands/managers/db.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import logging
import time
import datetime
import arrow
from rich.table import Table
from rich import box
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -200,4 +206,10 @@ def print_media(self):
#allow logs to print
time.sleep(1.5)
self.print_dictionary_table()

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
14 changes: 7 additions & 7 deletions ofscraper/db/operations_/media.py
Original file line number Diff line number Diff line change
Expand Up @@ -160,51 +160,51 @@
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=(?)
"""

getPinnedMedia = """
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=(?)
"""

getStoriesMedia = """
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
Expand Down

0 comments on commit 73444f5

Please sign in to comment.