Ejemplo n.º 1
0
def upload_movie(recv_dic,conn):
    # 电影是已经纯在的 直接上他
    file_name = common.get_session() + recv_dic['movie_name']
    file_size = recv_dic['file_size']

    path = os.path.join(setttings.UPLOAD_MOVIE_PATH,file_name)

    movie_obj = models.Movie(name=file_name,
                 path=path,
                 is_free=recv_dic['is_free'],
                 file_md5=recv_dic['file_md5'],
                 is_delete=0,
                 upload_time=common.get_time(),
                 user_id=recv_dic['user_id'])

    # 写文键
    recv_size= 0
    with open(path,'wb')as f:
        while recv_size<file_size:
            data = conn.recv(1024)
            f.write(data)
            recv_size += len(data)
        print('下载成功')


    send_dic = {"flag":True,'msg':'上传成功'}

    movie_obj.save()
    common.send_msg(send_dic,conn)
Ejemplo n.º 2
0
def upload_movie_interface(back_doc,conn):
    # 获取用户传过来的字典的相关信息
    movie_md5 = back_doc.get('movie_md5')
    movie_size = back_doc.get('movie_size')
    is_free = back_doc.get('is_free')
    movie_name = back_doc.get('movie_name')

    # 先获取电影的名字,加密过后的
    movie_new_name = common.get_session_md5(movie_name)+movie_name
    # 获取电影的存放地址
    movie_path  = os.path.join(settings.DOWNLOAD_PATH,movie_new_name)

    recv_data = 0
    # 接收电影数据
    with open(movie_path,'wb') as fw:
        while recv_data < movie_size:
            data = conn.recv(1024)
            fw.write(data)
            recv_data += len(data)


    # 持久化存储到数据库
    movie_obj = models.Movie(movie_name = movie_new_name,
                             is_free = 1 if is_free=='Y'or is_free =='y' else 0,
                             is_delete = 0,
                             file_md5 = movie_md5,
                             path = movie_path,
                             upload_time = datetime.datetime.now(),
                             user_id = back_doc.get('user_id'))
    movie_obj.save()

    # 向客户端返回信息
    send_dic = {'flag':True,'msg':'电影上传成功'}
    common.send_msg(send_dic,conn)
Ejemplo n.º 3
0
def upload_movie_interface(user_dic, conn):
    movie_name = user_dic.get("movie_name")
    movie_path = os.path.join(settings.DOWNLOAD_MOVIES_PATH, movie_name)
    movie_size = user_dic.get("movie_size")
    recv_len = 0
    with open(movie_path, "wb") as f:
        while recv_len < movie_size:
            recv_data = conn.recv(1024)
            f.write(recv_data)
            recv_len += len(recv_data)

    movie_obj = models.Movie(
        movie_name=movie_name,
        is_free=user_dic.get("is_vip"),
        is_delete=0,
        file_md5=user_dic.get("movie_md5"),
        path=movie_path,
        upload_time=datetime.datetime.now(),
        user_id=user_dic.get("user_id"),
    )
    movie_obj.instert_sql()

    send_dic = {
        "flag": True,
        "msg": "上传成功",
    }
    common.send_msg(send_dic, conn)
Ejemplo n.º 4
0
def upload_movie_interface(client_back_dic, conn):
    print('炮王来交货啦!')

    # 确保电影名称是唯一的  随机字符串 + 电影名称
    movie_name = common.get_random_code() + client_back_dic.get('movie_name')  # .mp4

    movie_size = client_back_dic.get('file_size')

    movie_path = os.path.join(
        settings.DOWNLOAD_PATH, movie_name
    )

    # 1.接受上传的电影
    data_recv = 0
    with open(movie_path, 'wb') as f:
        while data_recv < movie_size:
            data = conn.recv(1024)
            f.write(data)
            data_recv += len(data)

    # 2.把电影数据保存到mysql中
    movie_obj = models.Movie(
        name=movie_name, file_md5=client_back_dic.get('file_md5'),
        is_free=client_back_dic.get('is_free'), is_delete=0,
        path=movie_path, user_id=client_back_dic.get('user_id'),
        upload_time=common.get_time()
    )
    movie_obj.save()

    send_dic = {
        'flag': True, 'msg': f'{client_back_dic.get("movie_name")}电影上传成功!'
    }

    common.send_data(send_dic, conn)
Ejemplo n.º 5
0
def upload_movie_interface(back_dic,conn):
    movie_name = back_dic.get('movie_name')
    movie_size = back_dic.get('movie_size')
    movie_md5 = back_dic.get('movie_md5')
    is_free = back_dic.get('is_free')
    movie_path = os.path.join(settings.MOVIE_FILE_PATH,movie_name)
    num = 0
    with open(movie_path,'wb') as f:
        while num<movie_size:
            data = conn.recv(1024)
            f.write(data)
            num += len(data)
    movie_obj = models.Movie(
        movie_name=movie_name,
        movie_size=movie_size,
        movie_path=movie_path,
        is_free=is_free,
        u_id=back_dic.get('u_id'),
        file_md5=movie_md5,
        upload_time=datetime.datetime.now(),
        is_delete=0
    )
    movie_obj.orm_insert()
    send_dic = {'flag':True,'msg':'上传成功'}
    common.send_data(send_dic,conn)
Ejemplo n.º 6
0
def upload_movie(message, conn):
    file_size = message['file_size']
    file_name = message['file_name']
    create_time = message['create_time']
    file_md5 = message['file_md5']
    is_free = message['is_free']
    is_delete = message['is_delete']
    file_path = os.path.join(settings.BASE_MOVIES_TRUE_DIR, file_name)
    start_size = 0
    with open(file_path, 'wb') as f:
        while start_size < file_size:
            data = conn.recv(1024)
            f.write(data)
            start_size += len(data)
        f.flush()

    movie = models.Movie(
        name=file_name,
        path=file_path,
        is_free=is_free,
        is_delete=is_delete,
        create_time=create_time,
        user_id=message['user_id'],
        file_md5=file_md5,
    )
    movie.save()
    send_dic = {'flag': True, 'msg': '%s上传成功' % file_name}
    common.send_message(send_dic, conn)
def upload_movie(user_dic, conn):
    recv_size = 0
    print('----->', user_dic['file_name'])
    path = os.path.join(setting.BASE_MOVIE_LIST, user_dic['file_name'])
    with open(path, 'wb') as f:
        while recv_size < user_dic['file_size']:
            recv_data = conn.recv(1024)
            f.write(recv_data)
            recv_size += len(recv_data)
            # print('recvsize:%s filesize:%s' % (recv_size, user_dic['file_size']))
    print('%s :上传成功' % user_dic['file_name'])
    movie = models.Movie(user_dic['file_name'], path, user_dic['is_free'],
                         user_dic['name'])
    movie.save()
    back_dic = {'flag': True, 'msg': '上传成功'}
    return back_dic
Ejemplo n.º 8
0
def upload_movie(user_dic, conn):
    recv_size = 0
    print('----->', user_dic['file_name'])
    file_name = common.get_time() + user_dic['file_name']
    path = os.path.join(setting.BASE_MOVIE_LIST, file_name)
    with open(path, 'wb') as f:
        while recv_size < user_dic['file_size']:
            recv_data = conn.recv(1024)
            f.write(recv_data)
            recv_size += len(recv_data)
            # print('recvsize:%s filesize:%s' % (recv_size, user_dic['file_size']))
    print('%s :上传成功' % file_name)
    movie = models.Movie(name=file_name,
                         path=path,
                         is_free=user_dic['is_free'],
                         user_id=user_dic['user_id'],
                         file_md5=user_dic['file_md5'])
    movie.save()
    back_dic = {'flag': True, 'msg': '上传成功'}
    return back_dic
Ejemplo n.º 9
0
def upload_movie(user_dic, conn):
    recv_size = 0
    file_name = common.get_session(
        user_dic['file_name']) + user_dic['file_name']
    path = os.path.join(settings.BASE_MOVIE_LIST, file_name)
    with open(path, 'wb') as f:
        while recv_size < user_dic['file_size']:
            data = conn.recv(1024)
            f.write(data)
            recv_size += len(data)
    movie = models.Movie(name=file_name,
                         path=path,
                         user_id=user_dic['user_id'],
                         file_size=user_dic['file_size'],
                         file_md5=user_dic['file_md5'],
                         is_free=user_dic['is_free'])
    movie.save()
    back_dic = {
        'flag': True,
        'msg': 'movie:%s upload successfully' % (user_dic['file_name'])
    }
    common.send_back(back_dic, conn)
Ejemplo n.º 10
0
def upload_movie(back_dic, conn):
    file_name = common.get_session(
        back_dic.get('file_name')) + back_dic.get('file_name')
    file_size = back_dic.get('file_size')
    file_md5 = back_dic.get('file_md5')
    is_free = back_dic.get('is_free')
    file_path = os.path.join(settings.MOVIE_DIR, file_name)
    recv_size = 0
    with open(file_path, 'wb') as f:
        while recv_size < file_size:
            recv_data = conn.recv(1024)
            f.write(recv_data)
            recv_size += len(recv_data)
    movie_obj = models.Movie(name=file_name,
                             path=file_path,
                             is_free=is_free,
                             is_delete=0,
                             file_md5=file_md5,
                             upload_time=common.get_now_time(),
                             user_id=back_dic.get('user_id'))
    movie_obj.insert()
    send_dic = {'flag': True, 'msg': '上传成功'}
    common.send_msg(send_dic, conn)