mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-11-25 01:16:18 -05:00
User can select from/to years when searching files. Indexing doc and docx files.
This commit is contained in:
parent
758ff8e810
commit
00fe799b8f
40 changed files with 880 additions and 159 deletions
|
|
@ -13,7 +13,7 @@ from wrolpi.common import get_media_directory, walk, logger
|
|||
from wrolpi.dates import now, timedelta_to_timestamp, seconds_to_timestamp
|
||||
from wrolpi.db import optional_session, get_db_session
|
||||
from wrolpi.events import Events
|
||||
from wrolpi.vars import PROJECT_DIR
|
||||
from wrolpi.vars import PROJECT_DIR, IS_RPI5
|
||||
|
||||
logger = logger.getChild(__name__)
|
||||
|
||||
|
|
@ -224,16 +224,42 @@ def get_import_status(session: Session = None) -> List[MapFile]:
|
|||
return map_paths
|
||||
|
||||
|
||||
# Bps calculated using many tests on a well-cooled RPi4.
|
||||
# Calculated using many tests on a well-cooled RPi4 (4GB).
|
||||
RPI4_PBF_BYTES_PER_SECOND = 61879
|
||||
RPI4_A = 7.17509261732342e-14
|
||||
RPI4_B = 6.6590760410412e-5
|
||||
RPI4_C = 10283
|
||||
# Calculated using many tests on a well-cooled RPi5 (8GB).
|
||||
RPI5_PBF_BYTES_PER_SECOND = 136003
|
||||
RPI5_A = 1.6681382703586e-15
|
||||
RPI5_B = 2.35907824676145e-6
|
||||
RPI5_C = 53.727
|
||||
|
||||
|
||||
def seconds_to_import_rpi4(size_in_bytes: int) -> int:
|
||||
if size_in_bytes > 1_000_000_000:
|
||||
# Use exponential curve for large files.
|
||||
a = RPI4_A * size_in_bytes ** 2
|
||||
b = RPI4_B * size_in_bytes
|
||||
return int(a - b + RPI4_C)
|
||||
# Use simpler equation for small files.
|
||||
return max(int(size_in_bytes // RPI4_PBF_BYTES_PER_SECOND), 0)
|
||||
|
||||
|
||||
def seconds_to_import_rpi5(size_in_bytes: int) -> int:
|
||||
if size_in_bytes > 5_000_000_000:
|
||||
# Use exponential curve for large files.
|
||||
a = RPI5_A * size_in_bytes ** 2
|
||||
b = RPI5_B * size_in_bytes
|
||||
return int(a - b + RPI5_C)
|
||||
# Use simpler equation for small files.
|
||||
return max(int(size_in_bytes // RPI5_PBF_BYTES_PER_SECOND), 0)
|
||||
|
||||
|
||||
def seconds_to_import(size_in_bytes: int) -> int:
|
||||
"""Attempt to predict how long it will take an RPi4 to import a given PBF file."""
|
||||
if size_in_bytes > 1_000_000_000:
|
||||
# Use exponential curve for large files. These magic numbers are from testing many imports on an RPi 4.
|
||||
a = 7.17509261732342e-14 * size_in_bytes ** 2
|
||||
b = 6.6590760410412e-5 * size_in_bytes
|
||||
c = 10283
|
||||
return int(a - b + c)
|
||||
return max(int(size_in_bytes // RPI4_PBF_BYTES_PER_SECOND), 0)
|
||||
if IS_RPI5:
|
||||
return seconds_to_import_rpi5(size_in_bytes)
|
||||
|
||||
# Default to RPi4, because it's the most conservative estimate.
|
||||
return seconds_to_import_rpi4(size_in_bytes)
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
import unittest.mock
|
||||
from unittest import mock
|
||||
|
||||
import pytest
|
||||
|
|
@ -82,3 +83,21 @@ async def test_run_import_command(test_directory, mock_create_subprocess_shell):
|
|||
])
|
||||
def test_seconds_to_import_rpi4(size, expected):
|
||||
assert lib.seconds_to_import(size) == expected
|
||||
|
||||
|
||||
@pytest.mark.parametrize('size,expected', [
|
||||
(0, 0),
|
||||
(-1, 0),
|
||||
(17737381, 130),
|
||||
(63434267, 466),
|
||||
(87745484, 645),
|
||||
(116318111, 855),
|
||||
(136372996, 1002),
|
||||
(1936075318, 14235),
|
||||
(2676094489, 19676),
|
||||
(3392375001, 24943),
|
||||
(11346305075, 188040),
|
||||
])
|
||||
def test_seconds_to_import_rpi5(size, expected):
|
||||
with unittest.mock.patch('modules.map.lib.IS_RPI5', True):
|
||||
assert lib.seconds_to_import(size) == expected
|
||||
|
|
|
|||
|
|
@ -207,8 +207,8 @@ async def search_channels_by_name(name: str, limit: int = 5, session: Session =
|
|||
name_no_spaces = ''.join(name.split(' '))
|
||||
stmt = session.query(Channel) \
|
||||
.filter(or_(
|
||||
Channel.name.ilike(f'%{name}%'),
|
||||
Channel.name.ilike(f'%{name_no_spaces}%'),
|
||||
Channel.name.ilike(f'%{name}%'),
|
||||
Channel.name.ilike(f'%{name_no_spaces}%'),
|
||||
)) \
|
||||
.order_by(asc(Channel.name)) \
|
||||
.limit(limit)
|
||||
|
|
|
|||
|
|
@ -77,7 +77,6 @@ class ChannelDownloader(Downloader, ABC):
|
|||
@staticmethod
|
||||
def is_a_playlist(info: dict):
|
||||
# A playlist may have an id different from its channel.
|
||||
logger.debug(f'is_a_playlist {info["id"]=} {info.get("channel_id")=}')
|
||||
return info['id'] != info.get('channel_id')
|
||||
|
||||
async def do_download(self, download: Download) -> DownloadResult:
|
||||
|
|
|
|||
|
|
@ -1,5 +1,4 @@
|
|||
import asyncio
|
||||
import json
|
||||
import random
|
||||
from datetime import timedelta
|
||||
from typing import Tuple, Optional, List, Dict
|
||||
|
|
@ -218,6 +217,7 @@ async def get_missing_videos_comments(limit: int = VIDEO_COMMENTS_FETCH_COUNT):
|
|||
with get_db_session(commit=True) as session_:
|
||||
for video_ in session_.query(Video).join(FileGroup).filter_by(url=video_url).all():
|
||||
video_.comments_failed = True
|
||||
download_manager.add_to_skip_list(video_url)
|
||||
|
||||
for url in video_urls:
|
||||
# Sleep to catch cancel.
|
||||
|
|
@ -240,6 +240,7 @@ async def get_missing_videos_comments(limit: int = VIDEO_COMMENTS_FETCH_COUNT):
|
|||
continue
|
||||
|
||||
tries = 5
|
||||
info = None
|
||||
while tries > 0:
|
||||
try:
|
||||
tries -= 1
|
||||
|
|
@ -248,10 +249,23 @@ async def get_missing_videos_comments(limit: int = VIDEO_COMMENTS_FETCH_COUNT):
|
|||
if info and isinstance(info.get('comments'), list):
|
||||
break
|
||||
except Exception as e:
|
||||
logger.error(f'Got error when attempting to download comments: {url=}', exc_info=e)
|
||||
else:
|
||||
if 'no longer available' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video does not exist: {url=}', exc_info=e)
|
||||
break
|
||||
if 'Comments are turned off' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because comments are disabled: {url=}', exc_info=e)
|
||||
break
|
||||
if 'Private video' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video is private: {url=}', exc_info=e)
|
||||
break
|
||||
if 'Video unavailable' in str(e):
|
||||
logger.error(f'Giving up on downloading comments because video is unavailable: {url=}', exc_info=e)
|
||||
break
|
||||
logger.error(f'Got error when attempting to download video comments: {url=}', exc_info=e)
|
||||
await asyncio.sleep(random.randint(1, 5))
|
||||
|
||||
if not info or not isinstance(info.get('comments'), list):
|
||||
logger.error(f'Never got comments for video: {url=}')
|
||||
download_manager.add_to_skip_list(url)
|
||||
add_video_to_skip_list(url)
|
||||
continue
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue