|
|
@@ -55,8 +55,16 @@ def update_tables ( |
|
|
|
|
|
|
|
|
for datum in api_data: |
|
|
for datum in api_data: |
|
|
tag_names: list[str] = datum['tags'].split () |
|
|
tag_names: list[str] = datum['tags'].split () |
|
|
|
|
|
user: User | None = None |
|
|
|
|
|
if datum['userId']: |
|
|
|
|
|
user = User.where('code', str (datum['userId'])).first () |
|
|
|
|
|
if user is None: |
|
|
|
|
|
user = User () |
|
|
|
|
|
user.code = str (datum['userId']) |
|
|
|
|
|
user.save () |
|
|
video = Video () |
|
|
video = Video () |
|
|
video.code = datum['contentId'] |
|
|
video.code = datum['contentId'] |
|
|
|
|
|
video.user_id = user.id if user else None |
|
|
video.title = datum['title'] |
|
|
video.title = datum['title'] |
|
|
video.description = datum['description'] or '' |
|
|
video.description = datum['description'] or '' |
|
|
video.uploaded_at = datetime.fromisoformat (datum['startTime']) |
|
|
video.uploaded_at = datetime.fromisoformat (datum['startTime']) |
|
|
@@ -199,6 +207,7 @@ def search_nico_by_tags ( |
|
|
'targets': 'tagsExact', |
|
|
'targets': 'tagsExact', |
|
|
'_sort': '-viewCounter', |
|
|
'_sort': '-viewCounter', |
|
|
'fields': ('contentId,' |
|
|
'fields': ('contentId,' |
|
|
|
|
|
'userId,' |
|
|
'title,' |
|
|
'title,' |
|
|
'tags,' |
|
|
'tags,' |
|
|
'description,' |
|
|
'description,' |
|
|
@@ -220,6 +229,7 @@ def search_nico_by_tags ( |
|
|
video_data = fetch_video_data (video.code)['data'] |
|
|
video_data = fetch_video_data (video.code)['data'] |
|
|
result_data.append ({ |
|
|
result_data.append ({ |
|
|
'contentId': video.code, |
|
|
'contentId': video.code, |
|
|
|
|
|
'userId': video_data['video']['userId'], |
|
|
'title': video_data['video']['title'], |
|
|
'title': video_data['video']['title'], |
|
|
'tags': ' '.join (map (lambda t: t['name'], |
|
|
'tags': ' '.join (map (lambda t: t['name'], |
|
|
video_data['tag']['items'])), |
|
|
video_data['tag']['items'])), |
|
|
@@ -243,6 +253,7 @@ class VideoSearchParam (TypedDict): |
|
|
|
|
|
|
|
|
class VideoResult (TypedDict): |
|
|
class VideoResult (TypedDict): |
|
|
contentId: str |
|
|
contentId: str |
|
|
|
|
|
userId: int | None |
|
|
title: str |
|
|
title: str |
|
|
tags: str |
|
|
tags: str |
|
|
description: str | None |
|
|
description: str | None |
|
|
|