#import oss2
import  pandas  as pd
def download():
    df = pd.read_csv('/data2/data3/top3.csv')
    data = df.values.tolist()

    for i in  data :
        id = i[0]
        object_uri = i[3]
        print(object_uri)
        file_path, file_type = os.path.splitext(object_uri)
        local_filename = str(id) + file_type

        print(local_filename)
        cmd = "/data2/data3/rov/ossutil cp  oss://art-pubbucket/{}  /data2/data3/attention_LSTM_train/{}".format(object_uri,local_filename)
        m3u8tomp4_cmd = "ffmpeg -i  https://rescdn.yishihui.com/{} -vcodec copy -acodec copy -absf aac_adtstoasc /data2/data3/attention_LSTM_train/{}".format(object_uri,local_filename)
        if    file_type == ".mp4":
            os.system(cmd)
        if file_type == '.m3u8'
            os.system(m3u8tomp4_cmd)

def process():
    file_path='/data2/data3/attention_LSTM_train'
    video_name=[]
    for name in os.listdir(file_path):
        try:
            name_split=name.split('.')
            if name_split[1]=='mp4':
                with open('/root/video_tag/data/TsnExtractor.list','a')as nf:
                    nf.write(os.path.join(file_path+'/'+name))
                    nf.write('\n')
        except:
            pass
download()
process()




# # -*- coding: utf-8 -*-
# import oss2
# import  os
#
# # 阿里云主账号AccessKey拥有所有API的访问权限，风险很高。强烈建议您创建并使用RAM账号进行API访问或日常运维，请登录RAM控制台创建RAM账号。
# objet_name = "longvideo/transcode/video/vpc/20210611/10701970KpI498nAktSSfYLUnZ.m3u8"
# auth = oss2.Auth('LTAI4GHwyxgwTEfRwLWdgM5i', '5APqF5KdDC4ZDmPQ3xKrS2HsYSlO2B')
# prefix = objet_name[0:-5]
# bucket = oss2.Bucket(auth, 'oss-cn-hangzhou.aliyuncs.com', 'art-pubbucket')
# local_path = "/data/oss_video/"
# ts_list = []
# file_object = os.path.basename(objet_name)
# file_name = os.path.basename(file_object[:-5])
#
# for obj in oss2.ObjectIterator(bucket, prefix=prefix):
#     file_object = obj.key
#     cmd = "ossutil  cp oss://art-pubbucket/{}  /data/oss_video/{}".format(file_object, file_name)
#     # os.system(cmd)
#     ts_list.append(file_name)
#     ts_list.sort()
#
# ffmpeg -i https://rescdn.yishihui.com/longvideo/transcode/video/vpc/20210611/10701970KpI498nAktSSfYLUnZ.m3u8 -vcodec copy -acodec copy -absf aac_adtstoasc /data/123.mp4