mirror of
https://github.com/lrnselfreliance/wrolpi.git
synced 2026-10-26 02:48:38 -04:00
Using Channel name when reorganizing channel's files, fallback to info json uploader name (which may be outdated).
This commit is contained in:
parent
a9b2ec321e
commit
8a4f9201f6
3 changed files with 46 additions and 11 deletions
|
|
@ -841,9 +841,9 @@ def get_video_metadata(video) -> dict:
|
|||
"""Extract video metadata with fallback chain.
|
||||
|
||||
Fallback strategy:
|
||||
1. Primary: info_json + database fields (video.source_id, file_group.published_datetime)
|
||||
2. Secondary: parse_video_file_name() - ALL-OR-NOTHING, only if it provides channel AND date AND source_id
|
||||
3. Tertiary: video.channel.name for uploader only
|
||||
1. Primary: video.channel.name for uploader (when video belongs to a channel)
|
||||
2. Secondary: info_json + database fields (video.source_id, file_group.published_datetime)
|
||||
3. Tertiary: parse_video_file_name() - ALL-OR-NOTHING, only if it provides channel AND date AND source_id
|
||||
|
||||
Returns:
|
||||
dict with keys: upload_date (datetime|None), uploader (str), source_id (str), title (str)
|
||||
|
|
@ -856,7 +856,13 @@ def get_video_metadata(video) -> dict:
|
|||
if not upload_date and info_json.get('upload_date'):
|
||||
upload_date = dates.strpdate(info_json['upload_date'])
|
||||
|
||||
uploader = info_json.get('uploader') or info_json.get('channel') or ''
|
||||
# Prioritize WROLPi channel name when video belongs to a channel
|
||||
# This ensures reorganized files use the user's channel name, not the YouTube uploader name
|
||||
if video.channel and video.channel.name:
|
||||
uploader = video.channel.name
|
||||
else:
|
||||
uploader = info_json.get('uploader') or info_json.get('channel') or ''
|
||||
|
||||
source_id = video.source_id or info_json.get('id') or ''
|
||||
title = file_group.title or info_json.get('title') or info_json.get('fulltitle') or 'untitled'
|
||||
|
||||
|
|
@ -873,10 +879,6 @@ def get_video_metadata(video) -> dict:
|
|||
if not uploader:
|
||||
uploader = parsed_channel
|
||||
|
||||
# Final fallback: Channel.name for uploader only
|
||||
if not uploader and video.channel:
|
||||
uploader = video.channel.name or ''
|
||||
|
||||
return {
|
||||
'upload_date': upload_date,
|
||||
'uploader': uploader,
|
||||
|
|
|
|||
|
|
@ -355,3 +355,35 @@ def test_format_video_filename_without_upload_date(test_session, video_factory,
|
|||
# Template result: '{upload_year}/{uploader}_{upload_date}_{id}_{title}.mp4'
|
||||
# With empty year/date: '/__Test Video_Test Video.mp4' (has a slash for subdirectory)
|
||||
assert '/' in result # Confirms template was used (has subdirectory), not fallback
|
||||
|
||||
|
||||
def test_format_video_filename_uses_channel_name_over_info_json(test_session, video_factory, channel_factory,
|
||||
test_videos_downloader_config):
|
||||
"""When a video belongs to a channel, format_video_filename should use the WROLPi channel name,
|
||||
not the YouTube uploader name from info_json.
|
||||
|
||||
This ensures that when a user renames their channel, reorganized files use the new name.
|
||||
"""
|
||||
from modules.videos.lib import format_video_filename
|
||||
|
||||
# Create channel with WROLPi name
|
||||
channel = channel_factory(name='My Custom Channel')
|
||||
|
||||
# Create video in channel with different YouTube uploader name in info_json
|
||||
video = video_factory(
|
||||
channel_id=channel.id,
|
||||
title='My Video Title',
|
||||
with_video_file=True,
|
||||
with_info_json={
|
||||
'id': 'abc123',
|
||||
'uploader': 'Learning Self Reliance', # Different from channel name!
|
||||
'upload_date': '20240115',
|
||||
}
|
||||
)
|
||||
|
||||
template = '%(uploader)s_%(upload_date)s_%(id)s_%(title)s.%(ext)s'
|
||||
result = format_video_filename(video, template)
|
||||
|
||||
# Should use WROLPi channel name, NOT the YouTube uploader
|
||||
assert 'My Custom Channel' in result
|
||||
assert 'Learning Self Reliance' not in result
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue