Example #1
0
#!/usr/bin/env python3
from mackee import main
from brightcove.utils import SimpleProgressDisplay, SimpleTimer

show_progress = SimpleProgressDisplay(steps=100, add_info='videos processed')

num_drm_videos = 0


#===========================================
# function to check if a video has DRM
#===========================================
def count_drm(video: dict):
    global num_drm_videos
    if video.get('drm_disabled') == False:
        num_drm_videos += 1
    show_progress()


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    with SimpleTimer():
        main(count_drm)
        show_progress(force_display=True)
        print(f'\nDRM enabled videos: {num_drm_videos}')
Example #2
0
    else:
        eprint(
            f'No video dimensions found for video ID {video_id} (delivery type: {delivery_type}).'
        )
        return

    if response.status_code in get_cms().success_responses:
        renditions = response.json()
        for rendition in renditions:
            if rendition.get('media_type') == 'video' or rendition.get(
                    'audio_only') == False:
                source_w = rendition.get('frame_width')
                source_h = rendition.get('frame_height')
                break

        if source_h and source_w:
            x, y = aspect_ratio(source_w, source_h)
            print(video_id, x, y, sep=', ')
        else:
            eprint(f'No video renditions found for video ID {video_id}.')

    else:
        eprint(f'Could not get renditions for video ID {video_id}.')


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(find_aspect_ratios)
show_progress = SimpleProgressDisplay(steps=100, add_info='videos processed')


#===========================================
# callback to add up video durations
#===========================================
def find_average_duration(video: dict):
    """
    This will add the duration of the video to the total.
    """
    global num_videos
    global total_duration

    if duration := video.get('duration'):
        with data_lock:
            num_videos += 1
            total_duration += (duration / 1000)
            show_progress()


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(find_average_duration)
    show_progress(force_display=True)
    if num_videos > 0:
        print(
            f'Average duration for {num_videos} videos with duration information is {ts.from_seconds(total_duration/num_videos)} (HH:MM:SS).'
        )
Example #4
0
data_lock = Lock()
show_progress = SimpleProgressDisplay(steps=100, add_info='videos processed')


#===========================================
# callback to delete digital masters
#===========================================
def delete_masters(video: dict):
    """
    If video has a master this will delete the master.
    """
    if video.get('has_digital_master'):
        shared: dict = video.get('sharing')
        if shared and shared.get('by_external_acct'):
            return
        video_id = video.get('id')
        print(
            f'Deleting master for video ID {video_id}: {get_cms().DeleteDigitalMaster(video_id=video_id).status_code}'
        )

    with data_lock:
        show_progress()


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(delete_masters)
    show_progress(force_display=True)
Example #5
0
#===========================================
def update_content_type(video: dict):
    """
    Updates content type for a video.
    """
    # get video ID and specify content type
    video_id = video.get('id')
    content_type = 'my-type-here'

    # make API call
    response = get_audience().SetContentType(video_id=video_id,
                                             content_type=content_type)

    # check if we have a success response
    if response.status_code in [200, 202]:
        print(
            f'Updated content type for video ID {video_id} with status {response.status_code}.'
        )
    else:
        print(
            f'Error code {response.status_code} updating content type for video ID {video_id}:'
        )
        print(response.text)


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(update_content_type)
Example #6
0
	"""
	Adds creator of the video to the dictionary.
	"""

	creator = get_cms().GetCreatedBy(video)

	with data_lock:
		created_by_dict[creator] += 1
		show_progress()

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
	s = time.perf_counter()
	main(get_created_by_report)
	show_progress(force_display=True)

	row_list = [ ['user_id','number_videos'] ]
	for x,y in created_by_dict.items():
		row_list.append([x,y])

	#write list to file
	try:
		list_to_csv(row_list, get_args().o)
	except (OSError, CSVError) as e:
		eprint(f'\n{e}')

	elapsed = time.perf_counter() - s
	eprint(f"\n{__file__} executed in {TimeString.from_seconds(elapsed)}.")
	return 0

#===========================================
# callback getting storage sizes
#===========================================
def find_storage_size(video: dict) -> None:
	"""
	adds video ID, delivery type and master storage size to report list
	"""
	row = [ video.get('id'), video.get('delivery_type'), get_master_storage(video) ]

	# add a new row to the CSV data and increase counter
	with data_lock:
		row_list.append(row)
		show_progress()

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
	s = time.perf_counter()
	main(find_storage_size)
	show_progress(force_display=True)

	#write list to file
	list_to_csv(row_list, get_args().o)

	elapsed = time.perf_counter() - s
	eprint(f"\n{__file__} executed in {TimeString.from_seconds(elapsed)}.")
Example #8
0
#!/usr/bin/env python3
from mackee import main


#===========================================
# example callback function
#===========================================
def example_function(video: dict):
    """
	This will print out the video ID and the name of the video.
	"""
    print(video.get('id'), video.get('name'))


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(example_function)
Example #9
0
def enable_offline(video: dict):
    """
	If video is not enabled for offline playback this will enable it.
	"""
    # does video have DRM?
    if video.get('offline_enabled') == False:
        # get the video ID
        video_id = video.get('id')
        # create the JSON body
        json_body = {'offline_enabled': True}
        # make the PATCH call
        r = get_cms().UpdateVideo(video_id=video_id, json_body=json_body)
        # check if all went well
        if r.status_code in [200, 202]:
            print(
                f'Enabled Offline Playback for video ID {video_id} with status {r.status_code}.'
            )
        # otherwise report the error
        else:
            print(
                f'Error code {r.status_code} enabling Offline Playback for video ID {video_id}:'
            )
            print(r.text)


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(enable_offline)
Example #10
0
def disable_geo(video: dict):
	"""
	If geo restrictions are enabled this will disable them.
	"""
	global videos_processed
	# does video have Geo restrictions?
	if video.get('geo'):
		# get the video ID
		video_id = str(video.get('id'))
		# create the JSON body
		json_body = { 'geo': None }
		# make the PATCH call
		r = get_cms().UpdateVideo(video_id=video_id, json_body=json_body)
		# check if all went well
		if r.status_code not in [200,202]:
			eprint(f'Error code {r.status_code} disabling Geo for video ID {video_id}:')
			eprint(r.text)

	with counter_lock:
		videos_processed += 1

	if videos_processed%100==0:
		show_progress(videos_processed)

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
	main(disable_geo)
	show_progress(videos_processed)
Example #11
0
def disable_offline(video: dict):
    """
	If video is enabled for offline payback this will disable it.
	"""
    # is video offline enabled?
    if video.get('offline_enabled'):
        # get the video ID
        video_id = video.get('id')
        # create the JSON body
        json_body = {'offline_enabled': False}
        # make the PATCH call
        r = get_cms().UpdateVideo(video_id=video_id, json_body=json_body)
        # check if all went well
        if r.status_code in [200, 202]:
            print(
                f'Disabled Offline Playback for video ID {video_id} with status {r.status_code}.'
            )
        # otherwise report the error
        else:
            print(
                f'Error code {r.status_code} disabling Offline Playback for video ID {video_id}:'
            )
            print(r.text)


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(disable_offline)
Example #12
0
#!/usr/bin/env python3
from mackee import main

#===========================================
# callback to find videos into the account
#===========================================
def find_shared(video: dict):
	"""
	This prints videos which have been shared from an external account.
	"""
	shared = video.get('sharing')
	if shared and shared.get('by_external_acct'):
		print(f'{video.get("id")}, {shared}')

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
	main(find_shared)
Example #13
0
        # go through all tracks
        for track in tts:
            #check if it's a default track
            if track.get('default'):
                # change the setting
                track['default'] = False
                # set the flag so we know we found one
                got_hit = True

        # check if we found and changed at least one
        if got_hit:
            # get the video ID
            video_id = video.get('id')
            # create the JSON body
            json_body = { 'text_tracks': tts }
            # make the PATCH call
            r = get_cms().UpdateVideo(video_id=video_id, json_body=json_body)
            # check if all went well
            if r.status_code in [200,202]:
                print(f'Disabled default track(s) for video ID {video_id} with status {r.status_code}.')
            # otherwise report the error
            else:
                print(f'Error code {r.status_code} disabling default track(s) for video ID {video_id}:')
                print(r.text)

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(disable_tt)
Example #14
0
#!/usr/bin/env python3
from mackee import main


#===========================================
# callback to find videos with text tracks
#===========================================
def find_non_tt(video: dict):
    """
	This prints video IDs which have no text tracks.
	"""
    if not video.get('text_tracks'):
        print(video.get('id'))


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(find_non_tt)
#!/usr/bin/env python3
from mackee import main, get_cms


#===========================================
# callback to activate a video
#===========================================
def activate_video(video: dict):
    """
	If video is inactive this will activate it.
	"""
    if video.get('state') == 'INACTIVE':
        video_id = video.get('id')
        json = {'state': 'ACTIVE'}
        print(
            f'Activating video ID {video_id}: {get_cms().UpdateVideo(video_id=video_id, json_body=json).status_code}'
        )


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(activate_video)
    if tts := video.get('text_tracks'):
        # go through all tracks
        for track in tts:
            # change the setting
            track['label'] = track['srclang']

        # get the video ID
        video_id = video.get('id')
        # create the JSON body
        json_body = {'text_tracks': tts}
        # make the PATCH call
        r = get_cms().UpdateVideo(video_id=video_id, json_body=json_body)
        # check if all went well
        if r.status_code in [200, 202]:
            print(
                f'Updated track labels for video ID {video_id} with status {r.status_code}.'
            )
        # otherwise report the error
        else:
            print(
                f'Error code {r.status_code} updating track labels for video ID {video_id}:'
            )
            print(r.text)


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(update_tt_label)
Example #17
0
    """
	If video has DRM enabled this will disable DRM.
	"""
    # does video have DRM?
    is_drm_disabled = video.get('drm_disabled')
    if is_drm_disabled == False:
        # get the video ID
        video_id = video.get('id')
        # create the JSON body
        json_body = {'drm_disabled': True}
        # make the PATCH call
        r = get_cms().UpdateVideo(video_id=video_id, json_body=json_body)
        # check if all went well
        if r.status_code in [200, 202]:
            print(
                f'Disabled DRM for video ID {video_id} with status {r.status_code}.'
            )
        # otherwise report the error
        else:
            print(
                f'Error code {r.status_code} disabling DRM for video ID {video_id}:'
            )
            print(r.text)


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(disable_drm)
Example #18
0
def enable_drm(video: dict):
    """
	If a video is not enabled for DRM this will enable DRM.
	"""
    # does video have DRM?
    if video.get('drm_disabled') == True:
        # get the video ID
        video_id = video.get('id')
        # create the JSON body
        json_body = {'drm_disabled': False}
        # make the PATCH call
        r = get_cms().UpdateVideo(video_id=video_id, json_body=json_body)
        # check if all went well
        if r.status_code in [200, 202]:
            print(
                f'Enabled DRM for video ID {video_id} with status {r.status_code}.'
            )
        # otherwise report the error
        else:
            print(
                f'Error code {r.status_code} enabling DRM for video ID {video_id}:'
            )
            print(r.text)


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(enable_drm)
            source_h = rendition.get('frame_height')
            if source_h and source_w:
                results[rendition.get('size')] = [
                    source_w, source_h,
                    rendition.get('size'), 'MP4' if
                    rendition.get('video_container') == 'MP4' else 'HLS/DASH'
                ]

    if delivery_type == 'dynamic_origin':
        response = get_cms().GetVideoSources(video_id=video_id)
        if response.status_code in get_cms().success_responses:
            for rendition in response.json():
                if rendition.get('container') == 'MP4':
                    source_w = rendition.get('width')
                    source_h = rendition.get('height')
                    if source_h and source_w:
                        results[rendition.get('size')] = [
                            source_w, source_h,
                            rendition.get('size'), 'MP4'
                        ]

    for _, values in results.items():
        print(video_id, *values, sep=', ')


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(report_renditions)
Example #20
0
def create_report(video: dict) -> None:
    """
    Function to add a row of information about a video object to the report.

    Args:
        video (dict): video object obtained from the CMS API.
    """
    with data_lock:
        tag_list.extend(item for item in video.get('tags', [])
                        if item not in tag_list)
        show_progress()


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    # generate the report
    s = perf_counter()
    main(create_report)
    show_progress(force_display=True)

    # write report to CSV file
    try:
        list_to_csv(tag_list, get_args().o)
    except (OSError, CSVError) as e:
        eprint(f'\n{e}')

    elapsed = perf_counter() - s
    eprint(f"\n{__file__} executed in {TimeString.from_seconds(elapsed)}.")
Example #21
0
#!/usr/bin/env python3
from mackee import main


#===========================================
# callback to find videos with text tracks
#===========================================
def find_tt(video: dict):
    """
	This will find and list videos which have text tracks.
	"""
    if tts := video.get('text_tracks'):
        print(f'{video.get("id")}, "{video.get("name")}"')
        for track in tts:
            print(track.get('srclang'))


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(find_tt)
Example #22
0
#!/usr/bin/env python3
from mackee import main


#===========================================
# callback to find 360 videos
#===========================================
def find_360(video: dict):
    """
	Finds videos which are 360/VR enabled.
	"""
    if video.get('projection') == 'equirectangular':
        print(f'{video.get("id")}, "{video.get("name")}"')


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(find_360)
Example #23
0
    source_url: str = ''
    source_w, source_h = 0, 0

    # get sources for the video and try to find the biggest MP4 or FLV video
    source_list = get_cms().GetVideoSources(video_id=video_id).json()
    for source in source_list:
        if source.get('container') == 'MP4' or source.get('codec') == 'ON2':
            w, h = source.get('width', 0), source.get('height', 0)
            # checking w/h to avoid error by audio only renditions
            if w > source_w and h > source_h:
                url: str = source.get('src', '')
                if url.startswith('http'):
                    source_w, source_h = w, h
                    source_url = url
    # if a source was found use it as source for replacing the source
    if source_url:
        print(
            f'{video_id}: retranscoding using highest resolution MP4/FLV ({source_w}x{source_h}) -> {get_di().SubmitIngest(video_id=video_id, source_url=source_url, profile_id=ingest_profile,capture_images=capture_images, priority_queue=priority).status_code}'
        )
    else:
        print(
            f'{video_id}: can not be retranscoded (no master or MP4/FLV video rendition)'
        )


#===================================================
# only run code if it's not imported
#===================================================
if __name__ == '__main__':
    main(retranscode)
Example #24
0
#!/usr/bin/env python3
from mackee import main


#===========================================
# callback to find legacy delivery videos
#===========================================
def find_legacy(video: dict):
    """
	Finds videos which are on Legacy Delivery.
	"""
    if video.get('delivery_type') == 'static_origin':
        print(f'{video.get("id")}, "{video.get("name")}"')


#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(find_legacy)
	"""
	video_id = str(video.get('id'))
	source_url, source_w, source_h = None, 0, 0

	# get sources for the video and try to find the biggest MP4 video
	sourceList = get_cms().GetVideoSources(video_id=video_id).json()
	for source in sourceList:
		sourceType = source.get('container')
		if sourceType and sourceType=='MP4':
			w, h = source.get('width'), source.get('height')
			if h and w and w>source_w:
				source_w, source_h, source_url = w, h, source.get('src')

	# if a source was found download it, using the video ID as filename
	if source_url:
		print(f'{video_id}: highest resolution MP4 source is {source_w}x{source_h}. Downloading...')

		r = requests.get(source_url, stream=True)
		with open(f'{video_id}.mp4', 'wb') as out:
			total_length = int(r.headers.get('content-length'))
			for ch in progress.bar(r.iter_content(chunk_size = 2097152), expected_size=(total_length/2097152) + 1):
				if ch:
					out.write(ch)
					out.flush()

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
	main(download_video)
Example #26
0
#!/usr/bin/env python3
from mackee import main

#===========================================
# callback to report images for the video
#===========================================
def find_images(video: dict):
	"""
	Find URLs for poster and thumbnail images.
	"""
	if images := video.get('images'):
		poster = images.get('poster')
		thumb  = images.get('thumbnail')

		line = str(video.get('id'))+','
		line += (str(poster.get('src'))+',') if poster else ','
		line += (str(thumb.get('src'))) if thumb else ''

		print(line)

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
	main(find_images)
Example #27
0
#!/usr/bin/env python3
from mackee import main, get_cms

#===========================================
# callback to deactivate a video
#===========================================
def deactivate_video(video: dict):
	"""
	If a vide is active this will deactiavte it.
	"""
	if video.get('state')=='ACTIVE':
		video_id = video.get('id')
		json = { 'state': 'INACTIVE' }
		print(f'Deactivating video ID {video_id}: {get_cms().UpdateVideo(video_id=video_id, json_body=json).status_code}')

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
	main(deactivate_video)
Example #28
0
counter_lock = Lock()
show_progress = SimpleProgressDisplay(steps=100, add_info='videos processed')

#===========================================
# callback to enable Geo restrictions
#===========================================
def enable_geo(video: dict):
    """
    If no geo restrictions are enabled this will add some.
    """
    if not video.get('geo'):
        # get the video ID
        video_id = str(video.get('id'))
        # create the JSON body
        json_body = { 'geo' : { 'restricted' : True, 'exclude_countries' : False, 'countries' : ['ca'] } }
        # make the PATCH call
        r = get_cms().UpdateVideo(video_id=video_id, json_body=json_body)
        # check if all went well
        if r.status_code not in [200,202]:
            eprint(f'Error code {r.status_code} disabling Geo for video ID {video_id}:')
            eprint(r.text)
    with counter_lock:
        show_progress()

#===========================================
# only run code if it's not imported
#===========================================
if __name__ == '__main__':
    main(enable_geo)
    show_progress(force_display=True)