Я написал этот скрипт:
with open('data.json', 'r') as f:
data = json.load(f)
for obj in data:
video_player_url = obj.get('video_url')
ydl_opts = {}
with youtube_dl.YoutubeDL(ydl_opts) as ydl:
ydl.download([video_player_url])
print(video_player_url)
location = 'C:/Users/name/video/'obj.get('text')'.mp4'
info = {"text": obj.get('text'), "video_location": 'location', "tags": obj.get('tags')}
downloaded_file = open('downloaded_files','w+')
json.dump(info, downloaded_file)
Загрузка в порядке, но я хочу записать расположение загруженного файла в файл json.У меня есть ошибки:
При записи файла json я получаю:
{"text": "Title", "video_location": "C:/Users/name/video/video.mp4", "tags": ["", "tag", "", "tag2", "tag3"], "description": "great video"}{"text": "Title2", "video_location": "C:/Users/name/video/video2.mp4", "tags": ["", "tag", "", "tag2", "tag3"], "description": "great video2"}{"text": "Title3", "video_location": "C:/Users/name/video/video3.mp4", "tags": ["", "tag", "", "tag2", "tag3"], "description": "great video3"}
Но я хочу:
[
{"text": "Title", "video_location": "C:/Users/name/video/video.mp4", "tags": ["", "tag", "", "tag2", "tag3"], "description": "great video"}
{"text": "Title2", "video_location": "C:/Users/name/video/video2.mp4", "tags": ["", "tag", "", "tag2", "tag3"], "description": "great video2"}
{"text": "Title3", "video_location": "C:/Users/name/video/video3.mp4", "tags": ["", "tag", "", "tag2", "tag3"], "description": "great video3"}
]