Esempio n. 1
0
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()
Esempio n. 2
0
def find_aspect_ratios(video: dict) -> None:
    """
    This will print out the aspectratio of a video.
    """
    video_id = video.get('id')
    delivery_type = video.get('delivery_type')
    source_w, source_h, response = None, None, None

    if delivery_type == 'static_origin':
        response = get_cms().GetRenditionList(video_id=video_id)
    elif delivery_type == 'dynamic_origin':
        response = get_cms().GetDynamicRenditions(video_id=video_id)
    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}.')
Esempio n. 3
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)
        account_id, client_id, client_secret, _ = load_account_info(
            args.config)
    except Exception as e:
        print(e)
        sys.exit(2)

# if account ID was provided override the one from config
account_id = args.account or account_id

# create a CMS API instance
cms = CMS(oauth=OAuth(
    account_id=account_id, client_id=client_id, client_secret=client_secret))

row_list = [[
    'id', 'account_id', 'name', 'created_at', 'updated_at', 'video_count'
]]

response = cms.GetFolders()

if response.status_code == 200:
    folders = response.json()
    for folder in folders:
        row = [folder.get(field) for field in row_list[0]]
        row_list.append(row)

#write list to file
try:
    list_to_csv(row_list, args.out)
except Exception as e:
    eprint(f'{e}')
Esempio n. 5
0
# if we have an xls/csv
if args.xls:
    try:
        video_list = videos_from_file(
            args.xls, column_name=args.column if args.column else 'video_id')
    except Exception as e:
        print(e)

# otherwise just use the options from the config file
elif opts:
    video_list = opts.get('video_ids')

# either no list or "all" was found -> bail
if not video_list or video_list[0] == 'all':
    eprint('Error: invalid or missing list of videos in config file.')

# delete 'em
else:
    videos_processed = 0
    row_list = [['operation', 'video_id', 'result']]
    with concurrent.futures.ThreadPoolExecutor(max_workers=5) as executor:
        future_to_video_id = {
            executor.submit(delete_video, video_id): video_id
            for video_id in video_list
        }
        for future in concurrent.futures.as_completed(future_to_video_id):
            video = future_to_video_id[future]
            try:
                data = future.result()
            except Exception as exc:
Esempio n. 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)}.")
Esempio n. 7
0
# if list is empty try to get it from xls or config JSON
if not acc_ids:
    # if we have an xls/csv
    if args.xls:
        try:
            acc_ids = videos_from_file(args.xls, column_name='account_id')
        except Exception as e:
            print(e)
            sys.exit(2)

    # otherwise just use the options from the config file
    elif opts:
        acc_ids = opts.get('target_account_ids', [])

if acc_ids:
    print('account_id, display_name, name')
    for acc_id in acc_ids:

        response = ingest_profiles.GetDefaultProfile(account_id=acc_id)
        if response.status_code == 200:
            dpid = response.json().get('default_profile_id')

            response = ingest_profiles.GetIngestProfile(account_id=acc_id,
                                                        profile_id=dpid)
            if response.status_code == 200:
                display_name = response.json().get('display_name')
                name = response.json().get('name')
                print(f'{acc_id}, {display_name}, {name}')
else:
    eprint('No account IDs provided.')
args = parser.parse_args()

if not all([args.f, args.t]):
    print('Need from and to account IDs')
    sys.exit(2)

# get account info from config file if not hardcoded
try:
    account_id, client_id, client_secret, _ = load_account_info(args.i)
except (OSError, JSONDecodeError) as e:
    print(e)
    sys.exit(2)

# if account ID was provided override the one from config
account_id = args.f or account_id

# create a CMS API instance
cms = CMS(oauth=OAuth(account_id=account_id,client_id=client_id, client_secret=client_secret))

# make API call
response = cms.GetCustomFields()

# copy all fields from one account to the other
if response.status_code == 200:
    custom_fields : dict = response.json()
    for field in custom_fields:
        r = cms.CreateCustomField(account_id=args.t, json_body=field)
        print(field.get('id'), r.status_code, sep=', ')
else:
    eprint(f'Error while trying to get custom fields: {response.status_code}')
Esempio n. 9
0
while keep_running:
    search_query = '' if not page_key else f'page_key={page_key}'
    response = social.ListStatusForVideos(search_query=search_query)

    if response.status_code == 200:
        body = response.json()
        hits_to_process = body.get('total_hits')
        page_key = body.get('page_key')
        if not page_key:
            keep_running = False
        videos = body.get('videos')
        if videos:
            for video in videos:
                row = [video.get(field) for field in row_list[0]]
                row_list.append(row)

                videos_processed += 1
                if videos_processed % 100 == 0:
                    show_progress(videos_processed, hits_to_process)
    else:
        keep_running = False

show_progress(videos_processed, hits_to_process)

#write list to file
try:
    list_to_csv(row_list, report_name)
except Exception as e:
    eprint(f'\n{e}')
def get_rendition_sizes(video: dict) -> dict:
    """
    Function to get the sizes of all rendtions for a video.

    Returns a dict with the relevant sizes if available, 0 for sizes if video has no renditions or -1 in case of an error.
    """
    sizes = {
        'hls_renditions_size': 0,
        'mp4_renditions_size': 0,
        'audio_renditions_size': 0,
        'flv_renditions_size': 0,
    }

    if is_shared_by(video):
        return sizes

    rendition_types = {
        'MP4': 'mp4_renditions_size',
        'M2TS': 'hls_renditions_size',
        'FLV': 'flv_renditions_size',
        'audio': 'audio_renditions_size',
        'video': 'hls_renditions_size',
    }

    response = None
    delivery_type = video.get('delivery_type')
    video_id = video.get('id')

    try:
        if delivery_type == 'static_origin':
            response = get_cms().GetRenditionList(video_id=video_id)
        elif delivery_type == 'dynamic_origin':
            response = get_cms().GetDynamicRenditions(video_id=video_id)
        else:
            return sizes
    except RequestException:
        return {key: -1 for key in sizes}

    if response and response.ok:
        renditions = response.json()
        for rendition in renditions:
            size = rendition.get('size', 0)
            video_container = rendition.get('video_container')
            media_type = rendition.get('media_type')
            try:
                # legacy rendition types
                if video_container:
                    sizes[rendition_types[video_container]] += size
                # dyd rendition types
                elif media_type:
                    sizes[rendition_types[media_type]] += size
            # something I haven't seen before?
            except KeyError:
                eprint(
                    f'WARNING: unexpected container/media type for video ID {video_id}: "{video_container}"/"{media_type}"'
                )
                eprint('Please report the above message to MacKenzie Glanzer.')

        # if it's Dynamic Delivery we need to get MP4 sizes from the sources endpoint
        if delivery_type == 'dynamic_origin' and sizes[
                'mp4_renditions_size'] == 0:
            try:
                response = get_cms().GetVideoSources(video_id=video_id)
            except RequestException:
                sizes['mp4_renditions_size'] = -1
            else:
                if response.status_code in get_cms().success_responses:
                    sizes['mp4_renditions_size'] += sum(
                        set(
                            rendition.get('size', 0)
                            for rendition in response.json()
                            if rendition.get('container') == 'MP4'))
    return sizes