@@ -426,8 +423,11 @@ function ArchivesPage() {
} = useSearchArchives();
let archiveOrders = [
- {value: 'date', text: 'Date'},
+ {value: 'published_datetime', text: 'Published Date', short: 'P.Date'},
+ {value: 'published_modified_datetime', text: 'Modified Date', short: 'M.Date'},
+ {value: 'download_datetime', text: 'Download Date', short: 'D.Date'},
{value: 'size', text: 'Size'},
+ {value: 'viewed', text: 'Recently Viewed', short: 'R.Viewed'},
];
if (searchStr) {
diff --git a/app/src/components/Common.js b/app/src/components/Common.js
index 4189411f..5d69e7e3 100644
--- a/app/src/components/Common.js
+++ b/app/src/components/Common.js
@@ -148,27 +148,26 @@ export function isoDatetimeToElapsedPopup(dt) {
return secondsToElapsedPopup(d.getTime() / 1000);
}
-export function secondsToDuration(video) {
- let duration = video.duration;
- let hours = Math.floor(duration / 3600);
- duration -= hours * 3600;
- let minutes = Math.floor(duration / 60);
- let seconds = duration - (minutes * 60);
+export function secondsToHMS(totalSeconds) {
+ let hours = Math.floor(totalSeconds / 3600);
+ totalSeconds -= hours * 3600;
+ let minutes = Math.floor(totalSeconds / 60);
+ let seconds = totalSeconds - (minutes * 60);
hours = String('00' + hours).slice(-2);
minutes = String('00' + minutes).slice(-2);
seconds = String('00' + seconds).slice(-2);
- return [hours, minutes, seconds];
+ return {hours, minutes, seconds};
}
-export function Duration({video}) {
- let [hours, minutes, seconds] = secondsToDuration(video);
+export function Duration({totalSeconds}) {
+ const {hours, minutes, seconds} = secondsToHMS(totalSeconds);
if (hours > 0) {
- return {hours}:{minutes}:{seconds}
- } else if (video.duration) {
- return {minutes}:{seconds}
+ return {hours}:{minutes}:{seconds}
+ } else if (totalSeconds) {
+ return {minutes}:{seconds}
} else {
return <>>
}
@@ -224,7 +223,7 @@ export function RequiredAsterisk() {
return *
}
-export let defaultVideoOrder = '-upload_date';
+export let defaultVideoOrder = '-published_datetime';
export let defaultSearchOrder = 'rank';
export const frequencyOptions = [{key: null, text: '', value: null}, {
@@ -1277,7 +1276,7 @@ export function SortButton({sorts = []}) {
>
}
diff --git a/app/src/components/Files.js b/app/src/components/Files.js
index 003a42c0..96577725 100644
--- a/app/src/components/Files.js
+++ b/app/src/components/Files.js
@@ -70,7 +70,6 @@ import {Headlines} from "./Headline";
function EbookCard({file}) {
const {s} = useContext(ThemeContext);
- let {data} = file;
const downloadUrl = `/download/${encodeMediaPath(file.primary_path)}`;
const isEpub = file['mimetype'].startsWith('application/epub');
@@ -83,12 +82,12 @@ function EbookCard({file}) {
- {cardTitleWrapper(data ? data.title : file.title)}
+ {cardTitleWrapper(file ? file.title : file.title)}
- {data.creator ? {data.creator} : null}
+ {file.author ? {file.author} : null}
{file.size && {humanFileSize(file.size)}
}
diff --git a/app/src/components/VideoPlayer.js b/app/src/components/VideoPlayer.js
index 4cf4f0bb..311f0d10 100644
--- a/app/src/components/VideoPlayer.js
+++ b/app/src/components/VideoPlayer.js
@@ -73,7 +73,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
const navigate = useNavigate();
const videoRef = React.useRef();
- useTitle(videoFile === null || videoFile === undefined ? null : videoFile.video.title);
+ useTitle(videoFile ? videoFile.title ? videoFile.title : videoFile.name : null);
let video;
if (videoFile) {
video = videoFile.video;
@@ -241,7 +241,7 @@ function VideoPage({videoFile, prevFile, nextFile, fetchVideo, ...props}) {
- {video.upload_date && {isoDatetimeToString(video.upload_date)}
}
+ {videoFile.published_datetime && {isoDatetimeToString(videoFile.published_datetime)}
}
{channel &&
{channel.name}
diff --git a/app/src/components/Videos.js b/app/src/components/Videos.js
index 8956dc6f..3e32fc0b 100644
--- a/app/src/components/Videos.js
+++ b/app/src/components/Videos.js
@@ -84,10 +84,11 @@ function VideosPage() {
useTitle(title);
let videoOrders = [
- {value: 'upload_date', text: 'Date'},
- {value: 'duration', text: 'Duration'},
+ {value: 'published_datetime', text: 'Published Date', short: 'P.Date'},
+ {value: 'length', text: 'Length'},
{value: 'size', text: 'Size'},
{value: 'view_count', text: 'Views'},
+ {value: 'viewed', text: 'Recently Viewed', short: 'R.Viewed'},
]
if (searchStr) {
@@ -291,7 +292,7 @@ export function VideoCard({file}) {
// Default to video FilePreview for lone video files.
let video_url;
- const upload_date = isoDatetimeToString(video.upload_date);
+ const published_datetime = isoDatetimeToString(file.published_datetime);
// A video may not have a channel.
const channel = video.channel ? video.channel : null;
let channel_url = null;
@@ -320,7 +321,7 @@ export function VideoCard({file}) {
const color = mimetypeColor(file.mimetype);
return
{poster}
-
+
@@ -332,7 +333,7 @@ export function VideoCard({file}) {
{channel &&
{channel.name}
}
- {upload_date}
+ {published_datetime}
diff --git a/modules/archive/__init__.py b/modules/archive/__init__.py
index 3f33e3a5..e54cccf4 100644
--- a/modules/archive/__init__.py
+++ b/modules/archive/__init__.py
@@ -61,8 +61,8 @@ class ArchiveDownloader(Downloader, ABC):
@optional_session
def already_downloaded(self, *urls: List[str], session: Session = None) -> List:
- archives = list(session.query(Archive).filter(Archive.url.in_(urls)))
- return archives
+ file_groups = list(session.query(FileGroup).filter(FileGroup.url.in_(urls), FileGroup.model == 'archive'))
+ return file_groups
async def do_singlefile(self, download: Download) -> bytes:
"""Create a Singlefile from the archive's URL."""
@@ -226,14 +226,12 @@ def model_archive(file_group: FileGroup, session: Session = None) -> Archive:
file_group.d_text = contents
file_group.data = {
'id': archive.id,
- 'archive_datetime': archive.archive_datetime,
'domain': archive.domain.domain if archive.domain else None,
'readability_json_path': archive.readability_json_path,
'readability_path': archive.readability_path,
'readability_txt_path': archive.readability_txt_path,
'screenshot_path': archive.screenshot_path,
'singlefile_path': archive.singlefile_path,
- 'url': archive.url,
}
return archive
diff --git a/modules/archive/conftest.py b/modules/archive/conftest.py
index d8965646..4065cd8f 100644
--- a/modules/archive/conftest.py
+++ b/modules/archive/conftest.py
@@ -40,8 +40,8 @@ def archive_factory(test_session, archive_directory, make_files_structure):
domain_dir = archive_directory / domain_dir
domain_dir.mkdir(exist_ok=True)
- archive_datetime = next(now)
- timestamp = archive_strftime(archive_datetime)
+ download_datetime = next(now)
+ timestamp = archive_strftime(download_datetime)
json_contents = {}
if title != 'NA':
@@ -76,7 +76,7 @@ def archive_factory(test_session, archive_directory, make_files_structure):
archive = Archive.from_paths(test_session, *files)
archive.url = url
archive.title = title
- archive.archive_datetime = archive.file_group.published_datetime = next(now)
+ archive.file_group.download_datetime = archive.file_group.published_datetime = next(now)
archive.file_group.modification_datetime = next(now)
archive.domain = domain
archive.validate()
diff --git a/modules/archive/lib.py b/modules/archive/lib.py
index 74c4b246..2e480d41 100644
--- a/modules/archive/lib.py
+++ b/modules/archive/lib.py
@@ -198,7 +198,7 @@ async def model_archive_result(url: str, singlefile: str, readability: dict, scr
with get_db_session(commit=True) as session:
archive = Archive.from_paths(session, *paths)
- archive.archive_datetime = now()
+ archive.file_group.download_datetime = now()
archive.url = url
archive.domain = get_or_create_domain(session, url)
session.flush()
@@ -378,6 +378,7 @@ def parse_article_html_metadata(html: Union[bytes, str], assume_utc: bool = True
def get_archive(session, archive_id: int) -> Archive:
"""Get an Archive."""
archive = Archive.find_by_id(archive_id, session=session)
+ archive.file_group.set_viewed()
return archive
@@ -439,20 +440,38 @@ def get_domains():
ARCHIVE_ORDERS = {
- 'date': (date := 'fg.published_datetime ASC, a.archive_datetime ASC'),
- '-date': (_date := 'fg.published_datetime DESC NULLS LAST, a.archive_datetime DESC NULLS LAST'),
+ 'published_datetime': (date := 'fg.published_datetime ASC, fg.download_datetime ASC'),
+ '-published_datetime': (_date := 'fg.published_datetime DESC NULLS LAST, fg.download_datetime DESC NULLS LAST'),
+ 'published_modified_datetime': f'fg.published_modified_datetime ASC NULLS LAST, {date}',
+ '-published_modified_datetime': f'fg.published_modified_datetime DESC, {_date}',
+ 'download_datetime': 'fg.download_datetime ASC',
+ '-download_datetime': 'fg.download_datetime DESC',
'rank': f'2 DESC, {_date}',
'-rank': f'2 ASC, {date}',
'size': 'fg.size ASC, LOWER(fg.primary_path) ASC',
'-size': 'fg.size DESC NULLS LAST, LOWER(fg.primary_path) DESC',
+ 'viewed': 'fg.viewed ASC',
+ '-viewed': 'fg.viewed DESC',
}
ORDER_GROUP_BYS = {
- 'date': 'fg.published_datetime, a.archive_datetime',
- '-date': 'fg.published_datetime, a.archive_datetime',
- 'rank': 'fg.published_datetime, a.archive_datetime',
- '-rank': 'fg.published_datetime, a.archive_datetime',
+ 'published_datetime': 'fg.published_datetime, fg.download_datetime',
+ '-published_datetime': 'fg.published_datetime, fg.download_datetime',
+ 'published_modified_datetime': 'fg.published_modified_datetime, fg.published_datetime, fg.download_datetime',
+ '-published_modified_datetime': 'fg.published_modified_datetime, fg.published_datetime, fg.download_datetime',
+ 'download_datetime': 'fg.download_datetime',
+ '-download_datetime': 'fg.download_datetime',
+ 'rank': 'fg.published_datetime, fg.download_datetime',
+ '-rank': 'fg.published_datetime, fg.download_datetime',
'size': 'fg.size, fg.published_datetime, fg.primary_path',
'-size': 'fg.size, fg.published_datetime, fg.primary_path',
+ 'viewed': 'fg.viewed',
+ '-viewed': 'fg.viewed',
+}
+NO_NULL_ORDERS = {
+ 'viewed': 'fg.viewed IS NOT NULL',
+ '-viewed': 'fg.viewed IS NOT NULL',
+ 'published_modified_datetime': 'fg.published_modified_datetime IS NOT NULL',
+ '-published_modified_datetime': 'fg.published_modified_datetime IS NOT NULL',
}
@@ -461,10 +480,10 @@ def search_archives(search_str: str, domain: str, limit: int, offset: int, order
-> Tuple[List[dict], int]:
# Always filter FileGroups to Archives.
wheres = []
- group_by = 'fg.published_datetime, a.archive_datetime, a.file_group_id'
+ group_by = 'fg.published_datetime, fg.download_datetime, a.file_group_id'
params = dict(search_str=search_str, offset=int(offset), limit=int(limit))
- order_by = ARCHIVE_ORDERS['-date']
+ order_by = ARCHIVE_ORDERS['-published_datetime']
select_columns = ''
if search_str:
@@ -480,7 +499,9 @@ def search_archives(search_str: str, domain: str, limit: int, offset: int, order
order_by = ARCHIVE_ORDERS[order]
group_by = f'{group_by}, {ORDER_GROUP_BYS[order]}'
except KeyError:
- raise InvalidOrderBy(f'Invalid order by: {order}')
+ raise InvalidOrderBy(f'Invalid order byy {order}')
+ if order in NO_NULL_ORDERS:
+ wheres.append(NO_NULL_ORDERS[order])
if tag_names:
# Filter all FileGroups by those that have been tagged with the provided tag names.
diff --git a/modules/archive/models.py b/modules/archive/models.py
index cb95960e..bd159b42 100644
--- a/modules/archive/models.py
+++ b/modules/archive/models.py
@@ -10,7 +10,6 @@ from sqlalchemy.orm.collections import InstrumentedList
from wrolpi import dates
from wrolpi.common import ModelHelper, Base, logger
-from wrolpi.dates import TZDateTime
from wrolpi.db import optional_session
from wrolpi.errors import UnknownArchive
from wrolpi.files.models import FileGroup
@@ -31,9 +30,6 @@ class Archive(Base, ModelHelper):
__tablename__ = 'archive'
id = Column(Integer, primary_key=True)
- archive_datetime = Column(TZDateTime)
- url = Column(String)
-
domain_id = Column(Integer, ForeignKey('domains.id'))
domain = relationship('Domain', primaryjoin='Archive.domain_id==Domain.id')
file_group_id = Column(BigInteger, ForeignKey('file_group.id', ondelete='CASCADE'), unique=True, nullable=False)
@@ -41,20 +37,20 @@ class Archive(Base, ModelHelper):
def __repr__(self):
if self.domain:
- return f'