This is my JSON response API, I want to search for the video id by name. I mean Get VideoID using Video Name. For example: I want to input 'film10' and Python returns '82da4b60ef' as a result. I am using API Response JSON; this is the JSON:
{
'results': [{
'accountId': 'XXXXXXXXXXXXXXXXXXXXXXXXXXX',
'id': '6ed909bd16',
'partition': None,
'externalId': None,
'metadata': None,
'name': 'NewSeptemberFile20220908',
'description': None,
'created': '2022-09-12T22:04:55.799 00:00',
'lastModified': '2022-09-12T22:06:10.838 00:00',
'lastIndexed': '2022-09-12T22:05:04.551 00:00',
'privacyMode': 'Private',
'userName': 'M M',
'isOwned': True,
'isBase': True,
'hasSourceVideoFile': True,
'state': 'Processed',
'moderationState': 'OK',
'reviewState': 'None',
'processingProgress': '100%',
'durationInSeconds': 58,
'thumbnailVideoId': '6ed909bd16',
'thumbnailId': '5f04af4d-e382-4387-9573-6d9e4bad3b68',
'searchMatches': [],
'indexingPreset': 'Default',
'streamingPreset': 'Default',
'sourceLanguage': 'en-GB',
'sourceLanguages': ['en-GB'],
'personModelId': '00000000-0000-0000-0000-000000000000'
}, {
'accountId': 'XXXXXXXXXXXXXXXXX',
'id': '34344818e8',
'partition': None,
'externalId': None,
'metadata': None,
'name': '3September',
'description': None,
'created': '2022-09-09T17:55:59.696 00:00',
'lastModified': '2022-09-09T17:57:51.057 00:00',
'lastIndexed': '2022-09-09T17:56:04.544 00:00',
'privacyMode': 'Private',
'userName': 'M M',
'isOwned': True,
'isBase': True,
'hasSourceVideoFile': True,
'state': 'Processed',
'moderationState': 'OK',
'reviewState': 'None',
'processingProgress': '100%',
'durationInSeconds': 58,
'thumbnailVideoId': '34344818e8',
'thumbnailId': 'baae7ed1-a791-4481-853c-1707b40b5e77',
'searchMatches': [],
'indexingPreset': 'Default',
'streamingPreset': 'Default',
'sourceLanguage': 'en-GB',
'sourceLanguages': ['en-GB'],
'personModelId': '00000000-0000-0000-0000-000000000000'
}, {
'accountId': 'XXXXXXXXXXXXXXXXXXXXXXXXX',
'id': '82da4b60ef',
'partition': None,
'externalId': None,
'metadata': None,
'name': 'film10',
'description': None,
'created': '2022-08-22T14:24:08.442 00:00',
'lastModified': '2022-09-08T23:13:16.416 00:00',
'lastIndexed': '2022-08-22T14:24:12.605 00:00',
'privacyMode': 'Private',
'userName': 'M M',
'isOwned': True,
'isBase': True,
'hasSourceVideoFile': True,
'state': 'Processed',
'moderationState': 'OK',
'reviewState': 'None',
'processingProgress': '100%',
'durationInSeconds': 58,
'thumbnailVideoId': '82da4b60ef',
'thumbnailId': '5a5f6a71-0302-46a6-93c8-beb918c00b14',
'searchMatches': [],
'indexingPreset': 'Default',
'streamingPreset': 'Default',
'sourceLanguage': 'en-GB',
'sourceLanguages': ['en-GB'],
'personModelId': '00000000-0000-0000-0000-000000000000'
}, {
'accountId': 'XXXXXXXXXXXXXXX',
'id': '7ea0c5e34a',
'partition': None,
'externalId': None,
'metadata': None,
'name': 'davide_quatela--people_in_frankfurt',
'description': None,
'created': '2022-09-07T21:31:52.818 00:00',
'lastModified': '2022-09-08T22:52:52.833 00:00',
'lastIndexed': '2022-09-07T21:31:57.328 00:00',
'privacyMode': 'Private',
'userName': 'M M',
'isOwned': True,
'isBase': True,
'hasSourceVideoFile': True,
'state': 'Processed',
'moderationState': 'OK',
'reviewState': 'None',
'processingProgress': '100%',
'durationInSeconds': 131,
'thumbnailVideoId': '7ea0c5e34a',
'thumbnailId': '3aba8f42-a3a7-4d77-92b0-8cabcc275a3b',
'searchMatches': [],
'indexingPreset': 'Default',
'streamingPreset': 'Default',
'sourceLanguage': 'en-US',
'sourceLanguages': ['en-US'],
'personModelId': '00000000-0000-0000-0000-000000000000'
}, {
'accountId': 'XXXXXXXXXXXXXXXXXX',
'id': '7c45ae7ffe',
'partition': None,
'externalId': None,
'metadata': None,
'name': 'Untitled project',
'description': None,
'created': '2022-08-17T17:36:23.72 00:00',
'lastModified': '2022-08-17T17:36:49.95 00:00',
'lastIndexed': '2022-08-17T17:36:49.95 00:00',
'privacyMode': 'Private',
'userName': 'M M',
'isOwned': True,
'isBase': False,
'hasSourceVideoFile': False,
'state': 'Processed',
'moderationState': 'OK',
'reviewState': 'None',
'processingProgress': '',
'durationInSeconds': 0,
'thumbnailVideoId': None,
'thumbnailId': '00000000-0000-0000-0000-000000000000',
'searchMatches': [],
'indexingPreset': None,
'streamingPreset': 'Default',
'sourceLanguage': 'en-US',
'sourceLanguages': ['en-US'],
'personModelId': '00000000-0000-0000-0000-000000000000'
}
],
'nextPage': {
'pageSize': 25,
'skip': 0,
'done': True
}
}
This is my code, I get the API data by the requests get method and it returns '200' that it does mean the code is working properly.
url = "https://api.video.ai/trial/Accounts//Videos/7ea0c5e34a/Index?language=af-ZA&reTranslate=false&includeStreamingUrls=true&includeSummarizedInsights=true&accessToken="
response = requests.get(url,headers=hdr )
### Response: 200 OK
print("If Response=200 Script run is OK : " , response.status_code)
CodePudding user response:
So the url does not open on my end. cannot fetch the json.
using the json provided by you -
for item in json_data['results']:
if item['name'] == 'film10':
print(item['id'])
gives
82da4b60ef
CodePudding user response:
You could try the following:
for result in response['results']:
if result['name'] == ('YOUR FILM NAME INPUT'):
return result['id']
As you can see the response has a list with the results called "results", so this code runs through it and check if the name equals the name you want to check.