Automated channel_id extraction

This commit is contained in:
tcely 2025-01-22 19:41:03 -05:00 committed by GitHub
parent 4a24fd1109
commit ba321945b6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -291,11 +291,24 @@ class ValidateSourceView(FormView):
url = reverse_lazy('sync:add-source')
fields_to_populate = self.prepopulate_fields.get(self.source_type)
fields = {}
value = self.key
use_channel_id = (
'youtube-channel' == self.source_type_str and
'@' == self.key[0]
)
if use_channel_id:
self.source_type_str = 'youtube-channel-id'
self.source_type = self.source_types.get(self.source_type_str, None)
self.key = youtube.get_channel_id(
Source.create_index_url(self.source_type, self.key, 'videos')
)
for field in fields_to_populate:
if field == 'source_type':
fields[field] = self.source_type
elif field in ('key', 'name', 'directory'):
elif field == 'key':
fields[field] = self.key
elif field in ('name', 'directory'):
fields[field] = value
return append_uri_params(url, fields)