예제 #1
0
import os
import urllib2
import commands
from Queue import Queue
from lib.ParseConfig import Config
from lib.log import logger_root
from lib.UrlMerge import URLMerge
from lib.mailtome import send_mail


# 本地部署API调用URL,需根据实际URL配置
api_get_prefix = 'http://xxx/videos/course'  # 下载列表API前缀

# 调用Config类,解析配置文件中的配置
config = Config()
course_id_list = config.get_course_id().split("|")  # 课程ID列表
prefixs = config.get_prefixs()  # mp4,gif,srt下载连接前缀,目前是七牛空间的
dirs = config.get_dirs()  # mp4,gif,srt各类文件下载后存放路径
api_get_url_list = []
for course_id in course_id_list:
    api_get_url_list.append(api_get_prefix + '/' + course_id + '/api')  # 当前课程的下载列表API链接

def init_queue(url_dicts):
    queue = Queue()
    for fk in url_dicts.keys():
        for dk in url_dicts[fk].keys():
            dir = dirs[fk + '_dir'] + '/' + dk + '/'  # 实际文件存放路径
            if not os.path.exists(dir):
                os.makedirs(dir)
            for url in url_dicts[fk][dk]:
예제 #2
0
# -*- coding: utf-8 -*-

import os
import urllib2
import commands
from Queue import Queue
from lib.ParseConfig import Config
from lib.log import logger_root
from lib.UrlMerge import URLMerge
from lib.mailtome import send_mail

# 本地部署API调用URL,需根据实际URL配置
api_get_prefix = 'http://xxx/videos'  # 下载列表API前缀

# 调用Config类,解析配置文件中的配置
config = Config()
school_id = config.get_school_id()  # 学校ID
prefixs = config.get_prefixs()  # mp4,gif,srt下载连接前缀,目前是七牛空间的
dirs = config.get_dirs()  # mp4,gif,srt各类文件下载后存放路径

api_get_url = api_get_prefix + '/' + school_id + '/api'  # 当前学校的下载列表API链接


def init_queue(url_dicts):
    queue = Queue()
    for fk in url_dicts.keys():
        for dk in url_dicts[fk].keys():
            dir = dirs[fk + '_dir'] + '/' + dk + '/'  # 实际文件存放路径
            if not os.path.exists(dir):
                os.makedirs(dir)
            for url in url_dicts[fk][dk]:
예제 #3
0
# -*- coding: utf-8 -*-

import os
import time
import urllib2
import threading
import traceback
from urllib2 import socket, URLError
from shutil import move

from lib.ParseConfig import Config
from lib.log import logger_root
from lib.Qetag import get_qetag


config = Config()
tmp_dir = config.get_dirs()['tmp_dir'] + '/'
queue_lock = threading.Lock()
error_list = set()
succeed_list = set()
download_list = set()  # 新增加,防止重复的下载项目而引起异常
exitFlag = False
err_exit = False


class timeout(Exception):  
    def __init__(self, message):
        self.message = message

class DownloadThread(threading.Thread):
    __queue = None