예제 #1
0
def get_my_playlists_view(request):
    """
    获取认证账号的专辑playlist
    :param request:
    :return:
    """
    youku_access_token = youku_get_authenticate()
    youku_service = YoukuPlaylists(CLIENT_ID)
    playlists_dict = youku_service.find_playlists_by_me(youku_access_token)
    for playlist in playlists_dict['playlists']:
        YoukuPlaylist.objects.update_or_create(id=playlist['id'],
                                               defaults={
                                                   'name': playlist['name'],
                                                   'duration': playlist[
                                                       'duration'],
                                                   'link': playlist['link'],
                                                   'play_link': playlist[
                                                       'play_link'],
                                                   'view_count': playlist[
                                                       'view_count'],
                                                   'video_count': playlist[
                                                       'video_count'],}
                                               )
    return render_to_response('result.html', {'text': "获取认证用户的Playlist信息成功",
                                              'dict_items': playlists_dict})
예제 #2
0
def update_youku_online_info(youku_video_id):
    """
    将youku_video_id的本地youku对象的属性,在优酷上进行更新
    注意:无法对视频进行关于playlist的操作
    :param youku_video_id:
    :return:
    """
    youku = Youku.objects.get(youku_video_id=youku_video_id)

    service = YoukuVideos(CLIENT_ID)

    youku_access_token = youku_get_authenticate()

    updated_youku_video_id = service.update_video(
        access_token=youku_access_token,
        video_id=youku_video_id,
        title=youku.title,
        tags=youku.tags,
        category=youku.category,
        copyright_type=None,
        public_type=None,
        watch_password=None,
        description=youku.description,
        thumbnail_seq=None)
    return updated_youku_video_id
예제 #3
0
def get_youku_playlist():
    """
    获取认证用户的playlist
    :return:
    """
    service = YoukuPlaylists(CLIENT_ID)
    youku_access_token = youku_get_authenticate()
    # http://doc.open.youku.com/?docid=377
    # 视频ID用逗号来分割,每个专辑最多200个视频,限制单次操作视频的最大个数,默认20
    # video_ids=850,860,870,880
    playlist_json = service.find_playlists_by_me(
        access_token=youku_access_token,
        orderby='published', page=1, count=20)




# def upload_playlist_video(num, user):
#     upload_num = 0
#     # 如果该视频已下载,但是未上传到优酷,则上传
#     if video.is_upload == False:
#         # video对象还没有创建对应的youku对象怎么办?
#         youku_upload(video.youku.id)
#         # 在优酷上设置视频的playlist
#         set_youku_playlist_online_from_config_playlist(video_id)
#         upload_num = upload_num + 1
#         if upload_num <= num:
#             break
#     result_list.append({'download_num': download_num,
#                         'upload_num': upload_num,
#                         'text': text})
예제 #4
0
def set_youku_playlist_online(youku_video_id, playlist_id):
    """
    根据youku的youkuplaylist属性,在优酷网上将youku对象添加到该playlist中

    一个视频可以加入多个playlist,所以在youku中设置playlist后,如果不执行del_videos_from_playlist
    操作,视频仍然属于该playlist
    :param youku_id:
    :return:
    """

    service = YoukuPlaylists(CLIENT_ID)
    youku_access_token = youku_get_authenticate()
    # http://doc.open.youku.com/?docid=377
    # 视频ID用逗号来分割,每个专辑最多200个视频,限制单次操作视频的最大个数,默认20
    # video_ids=850,860,870,880
    # 返回的是专辑ID
    playlist_id = service.add_videos_to_playlist(
        access_token=youku_access_token,
        playlist_id=playlist_id,
        video_ids=youku_video_id)

    if playlist_id:
        return playlist_id
    else:
        return False
예제 #5
0
def get_youku_playlist():
    """
    获取认证用户的playlist
    :return:
    """
    service = YoukuPlaylists(CLIENT_ID)
    youku_access_token = youku_get_authenticate()
    # http://doc.open.youku.com/?docid=377
    # 视频ID用逗号来分割,每个专辑最多200个视频,限制单次操作视频的最大个数,默认20
    # video_ids=850,860,870,880
    playlist_json = service.find_playlists_by_me(
        access_token=youku_access_token, orderby='published', page=1, count=20)


# def upload_playlist_video(num, user):
#     upload_num = 0
#     # 如果该视频已下载,但是未上传到优酷,则上传
#     if video.is_upload == False:
#         # video对象还没有创建对应的youku对象怎么办?
#         youku_upload(video.youku.id)
#         # 在优酷上设置视频的playlist
#         set_youku_playlist_online_from_config_playlist(video_id)
#         upload_num = upload_num + 1
#         if upload_num <= num:
#             break
#     result_list.append({'download_num': download_num,
#                         'upload_num': upload_num,
#                         'text': text})
예제 #6
0
def set_youku_playlist_online(youku_video_id, playlist_id):
    """
    根据youku的youkuplaylist属性,在优酷网上将youku对象添加到该playlist中

    一个视频可以加入多个playlist,所以在youku中设置playlist后,如果不执行del_videos_from_playlist
    操作,视频仍然属于该playlist
    :param youku_id:
    :return:
    """

    service = YoukuPlaylists(CLIENT_ID)
    youku_access_token = youku_get_authenticate()
    # http://doc.open.youku.com/?docid=377
    # 视频ID用逗号来分割,每个专辑最多200个视频,限制单次操作视频的最大个数,默认20
    # video_ids=850,860,870,880
    # 返回的是专辑ID
    playlist_id = service.add_videos_to_playlist(
        access_token=youku_access_token,
        playlist_id=playlist_id,
        video_ids=youku_video_id)

    if playlist_id:
        return playlist_id
    else:
        return False
예제 #7
0
def get_my_playlists_view(request):
    """
    获取认证账号的专辑playlist
    :param request:
    :return:
    """
    youku_access_token = youku_get_authenticate()
    youku_service = YoukuPlaylists(CLIENT_ID)
    playlists_dict = youku_service.find_playlists_by_me(youku_access_token)
    for playlist in playlists_dict['playlists']:
        YoukuPlaylist.objects.update_or_create(id=playlist['id'],
                                               defaults={
                                                   'name': playlist['name'],
                                                   'duration': playlist[
                                                       'duration'],
                                                   'link': playlist['link'],
                                                   'play_link': playlist[
                                                       'play_link'],
                                                   'view_count': playlist[
                                                       'view_count'],
                                                   'video_count': playlist[
                                                       'video_count'], }
                                               )
    return render_to_response('result.html', {'text': "获取认证用户的Playlist信息成功",
                                              'dict_items': playlists_dict})
예제 #8
0
def delete_youku_video(youku_video_id):
    """
    在优酷网上删除youku_video_id的视频,成功的话将数据库youku.youku_video_id清零
    :param youku_video_id:
    :return:
    """
    service = YoukuVideos(CLIENT_ID)
    youku_access_token = youku_get_authenticate()
    delete_youku_video_id = service.destroy_video(
        access_token=youku_access_token, video_id=youku_video_id)

    if delete_youku_video_id == youku_video_id:
        # 在优酷网上成功删除视频后,在本地将youku.youku_video_id清空
        youku = Youku.objects.get(youku_video_id=youku_video_id)
        youku.youku_video_id = ''
        youku.save()
    return delete_youku_video_id
예제 #9
0
파일: youku.py 프로젝트: GoTop/AutoSystem
def delete_youku_video(youku_video_id):
    """
    在优酷网上删除youku_video_id的视频,成功的话将数据库youku.youku_video_id清零
    :param youku_video_id:
    :return:
    """
    service = YoukuVideos(CLIENT_ID)
    youku_access_token = youku_get_authenticate()
    delete_youku_video_id = service.destroy_video(
        access_token=youku_access_token,
        video_id=youku_video_id)

    if delete_youku_video_id == youku_video_id:
        # 在优酷网上成功删除视频后,在本地将youku.youku_video_id清空
        youku = Youku.objects.get(youku_video_id=youku_video_id)
        youku.youku_video_id = ''
        youku.save()
    return delete_youku_video_id
예제 #10
0
파일: youku.py 프로젝트: GoTop/AutoSystem
def update_youku_online_info(youku_video_id):
    """
    将youku_video_id的本地youku对象的属性,在优酷上进行更新
    注意:无法对视频进行关于playlist的操作
    :param youku_video_id:
    :return:
    """
    youku = Youku.objects.get(youku_video_id=youku_video_id)

    service = YoukuVideos(CLIENT_ID)

    youku_access_token = youku_get_authenticate()

    updated_youku_video_id = service.update_video(
        access_token=youku_access_token, video_id=youku_video_id,
        title=youku.title,
        tags=youku.tags, category=youku.category, copyright_type=None,
        public_type=None, watch_password=None,
        description=youku.description, thumbnail_seq=None)
    return updated_youku_video_id
예제 #11
0
def delete_video_from_playlist(youku_video_id, playlist_id):
    """
    在playlist_id的优酷playlist中删除youku_video_id视频
    :param youku_video_id:
    :param playlist_id:
    :return:
    """
    service = YoukuPlaylists(CLIENT_ID)
    youku_access_token = youku_get_authenticate()

    try:
        id = service.del_videos_from_playlist(access_token=youku_access_token,
                                              playlist_id=playlist_id,
                                              video_ids=youku_video_id)
    except:
        # 如果playlist_id中没有youku_video_id,会提示异常,忽略即可
        pass
        return False

    if id:
        return id
    else:
        return False
예제 #12
0
def delete_video_from_playlist(youku_video_id, playlist_id):
    """
    在playlist_id的优酷playlist中删除youku_video_id视频
    :param youku_video_id:
    :param playlist_id:
    :return:
    """
    service = YoukuPlaylists(CLIENT_ID)
    youku_access_token = youku_get_authenticate()

    try:
        id = service.del_videos_from_playlist(access_token=youku_access_token,
                                              playlist_id=playlist_id,
                                              video_ids=youku_video_id)
    except:
        # 如果playlist_id中没有youku_video_id,会提示异常,忽略即可
        pass
        return False

    if id:
        return id
    else:
        return False
예제 #13
0
def youku_upload(youku_id, max_retey=8):
    """
    将youku id的youku对象对应的合并有字幕的video视频的上传到优酷网

    :param youku_id:
    :return:
    """
    youku_access_token = youku_get_authenticate()

    youku = Youku.objects.get(pk=youku_id)

    # 如果没有在将字幕合并到视频中,则使用原版的视频
    if youku.video.subtitle_video_file == '' and youku.video.file.name:
        # 如果 subtitle_video_file 不存在
        video_file_path = youku.video.file.path
    elif youku.video.subtitle_video_file.name:
        # 如果 subtitle_video_file 存在
        video_file_path = youku.video.subtitle_video_file.path
    else:
        return False

    service = YoukuUpload(CLIENT_ID, youku_access_token, video_file_path)

    # 如果没有在vidoe对应的youku model中设置中文title,则使用video中的title
    if youku.title == '':
        title = youku.video.title
    else:
        title = youku.title

    # 上传的时候如果video.description为None,youku这个库会提示object of type 'NoneType' has
    # no len()
    if youku.description is None:
        description = ''
    else:
        description = youku.description

    if youku.tags == '':
        # 如果未设置tags,则将tags设置为category,因为tags是必选参数,不能为空
        if youku.category:
            youku.tags = youku.category
        else:
            youku.tags = youku.video.get_tags(10)

    # tags = youku.tags

    # 参数 http://cloud.youku.com/docs?id=110
    # tags:string 必选参数 视频标签,自定义标签不超过10个,单个标签最少2个字符,最多12个字符(6个汉字),多个标签之间用逗号(,)隔开
    # category:string 可选参数 视频分类,详细分类定义见 http://cloud.youku.com/docs?id=90
    video_info = {
        'title': title,
        'category': youku.category,
        'tags': youku.tags,
        'description': description
    }
    n = 0
    try:
        youku_video_id = service.upload(video_info)
    except:
        if n + 1 < max_retey:
            youku_video_id = service.upload(video_info)
        else:
            return False

    youku.youku_video_id = youku_video_id
    youku.save()

    logger = logging.getLogger(__name__)
    logger.info("上传视频到优酷,id为" + youku.video_id)

    return youku_video_id
예제 #14
0
파일: youku.py 프로젝트: GoTop/AutoSystem
def youku_upload(youku_id, max_retey=8):
    """
    将youku id的youku对象对应的合并有字幕的video视频的上传到优酷网

    :param youku_id:
    :return:
    """
    youku_access_token = youku_get_authenticate()

    youku = Youku.objects.get(pk=youku_id)

    # 如果没有在将字幕合并到视频中,则使用原版的视频
    if youku.video.subtitle_video_file == '' and youku.video.file.name:
        # 如果 subtitle_video_file 不存在
        video_file_path = youku.video.file.path
    elif youku.video.subtitle_video_file.name:
        # 如果 subtitle_video_file 存在
        video_file_path = youku.video.subtitle_video_file.path
    else:
        return False

    service = YoukuUpload(CLIENT_ID, youku_access_token, video_file_path)

    # 如果没有在vidoe对应的youku model中设置中文title,则使用video中的title
    if youku.title == '':
        title = youku.video.title
    else:
        title = youku.title

    # 上传的时候如果video.description为None,youku这个库会提示object of type 'NoneType' has
    # no len()
    if youku.description is None:
        description = ''
    else:
        description = youku.description

    if youku.tags == '':
        # 如果未设置tags,则将tags设置为category,因为tags是必选参数,不能为空
        if youku.category:
            youku.tags = youku.category
        else:
            youku.tags = youku.video.get_tags(10)

    # tags = youku.tags

    # 参数 http://cloud.youku.com/docs?id=110
    # tags:string 必选参数 视频标签,自定义标签不超过10个,单个标签最少2个字符,最多12个字符(6个汉字),多个标签之间用逗号(,)隔开
    # category:string 可选参数 视频分类,详细分类定义见 http://cloud.youku.com/docs?id=90
    video_info = {
        'title': title,
        'category': youku.category,
        'tags': youku.tags,
        'description': description
    }
    n = 0
    try:
        youku_video_id = service.upload(video_info)
    except:
        if n + 1 < max_retey:
            youku_video_id = service.upload(video_info)
        else:
            return False

    youku.youku_video_id = youku_video_id
    youku.save()

    logger = logging.getLogger(__name__)
    logger.info("上传视频到优酷,id为" + youku.video_id)

    return youku_video_id