Esempio n. 1
0
def rename(youtube, ids_to_titles, on_rename=None):
    '''
    on_rename: function with signature on_rename(video_id, old_title, new_title)
    '''

    if on_rename is None:
        on_rename = lambda *args, **kwargs: None

    ids = ids_to_titles.keys()
    items = video_list_response_items(youtube, ids)
    missing = _missing_videos(items, ids)
    if missing: report_missing_videos(missing)
    existing = filter(lambda item: item['id'] not in missing, items)

    for item in existing:
        video_id = item['id']
        snippet = item["snippet"]
        old_title = snippet['title']
        new_title = ids_to_titles[video_id]
        snippet['title'] = new_title

        try:
            _update(youtube,
                    part='snippet',
                    body=dict(snippet=snippet, id=video_id))
        except:
            report_video_failed_to_rename(video_id)
            continue

        on_rename(video_id, old_title, new_title)
Esempio n. 2
0
def rename(youtube, ids_to_titles, on_rename=None):
    '''
    on_rename: function with signature on_rename(video_id, old_title, new_title)
    '''

    if on_rename is None:
        on_rename = lambda *args, **kwargs: None
        
    ids = ids_to_titles.keys()
    items = video_list_response_items(youtube, ids)
    missing = _missing_videos(items, ids)
    if missing: report_missing_videos(missing)
    existing = filter(lambda item: item['id'] not in missing, items)

    for item in existing:
        video_id = item['id']
        snippet = item["snippet"]
        old_title = snippet['title']
        new_title = ids_to_titles[video_id]
        snippet['title'] = new_title

        try:
            _update(youtube, 
                    part='snippet',
                    body=dict(snippet=snippet, id=video_id))
        except:
            report_video_failed_to_rename(video_id)
            continue
    
        on_rename(video_id, old_title, new_title)
Esempio n. 3
0
def rename_in_playlist(youtube, playlistId, old_title_to_new):
    def _id_to_new_title_mapping(id_to_old, old_to_new):
        result = dict()
        for id_ in id_to_old.keys():
            old = id_to_old[id_]
            new = old_to_new.get(old)
            if new is None: continue
            result[id_] = new
        return result

    id_to_old = id_to_title_mapping_from_playlist(youtube, playlistId)
    id_to_new = _id_to_new_title_mapping(id_to_old, old_title_to_new)

    missing_videos = old_title_to_new.keys() - set(id_to_old.values())
    if missing_videos:
        report_missing_videos(missing_videos)

    rename(youtube, id_to_new, on_rename=support_undo())
Esempio n. 4
0
def rename_in_playlist(youtube, playlistId, old_title_to_new):
    def _id_to_new_title_mapping(id_to_old, old_to_new):
        result = dict()
        for id_ in id_to_old.keys():
            old = id_to_old[id_]
            new = old_to_new.get(old)
            if new is None: continue
            result[id_] = new
        return result

    id_to_old = id_to_title_mapping_from_playlist(youtube, playlistId)
    id_to_new = _id_to_new_title_mapping(id_to_old, old_title_to_new)

    missing_videos = old_title_to_new.keys() - set(id_to_old.values())
    if missing_videos:
        report_missing_videos(missing_videos)
    
    rename(youtube, id_to_new, on_rename=support_undo())