首页 > 编程语言 > 详细

python 读取json,然后处理下载视频

时间:2020-12-23 16:54:16      阅读:28      评论:0      收藏:0      [点我收藏+]

import json
import requests
import os
url=‘‘;
func_list=‘/getCurriculum?page=1&limit=30&userId&majorname_id=‘
func_details=‘/getCurriculumDetail?id=108&userId‘

response=requests.get(url+func_list)
js=json.loads(response.text)
path="/usr/local/var/python/zj/PythonApplication1/PythonApplication1/videos/"
for tes in js[‘data‘]:
    upath=path+tes[‘name‘]
    url=""
    isExists=os.path.exists(upath)
    if not isExists:
        os.mkdir(upath)
    write=upath+‘/video.txt‘
    for tes1 in tes[‘video‘]:
         url+=tes1[‘title‘]+"|"+tes1[‘video_url‘]+"\r\n"
    with open(write, ‘w‘,encoding=‘utf-8‘) as f:
        f.write(url)


import os
import urllib.request
from urllib.parse import urlparse, parse_qs, parse_qsl
path="/usr/local/var/python/zj/PythonApplication1/PythonApplication1/videos/"

file_list_er=os.listdir(path)
def cbk(a,b,c):
    ‘‘‘回调函数
    @a:已经下载的数据块
    @b:数据块的大小
    @c:远程文件的大小
    ‘‘‘
    per=100.0*a*b/c
    if per>100:
        per=100
    print(‘%.2f%%‘ % per)

def geturl(filenames):
    with open(filenames, "r") as f:  # 打开文件
        results = f.read()  # 读取文件
        data = results.split(‘\n‘)

    return data

for tes in file_list_er:
    pa=path+tes+"/video.txt"
    dat2=geturl(pa)
    for ta in dat2:
        rea=ta.split(‘|‘)
        if len(rea)>1:
            if os.path.exists(path+tes+"/"+rea[0]+‘.mp4‘):
               continue 
            urllib.request.urlretrieve(rea[1],path+tes+"/"+rea[0]+‘.mp4‘,cbk) 

python 读取json,然后处理下载视频

原文:https://www.cnblogs.com/mengluo/p/14179091.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!