吾爱破解 - 52pojie.cn

 找回密码
 注册[Register]

QQ登录

只需一步,快速开始

查看: 6161|回复: 40
收起左侧

[Python 转载] 【更新】omofun v1.1 动漫下载

  [复制链接]
话痨司机啊 发表于 2022-8-19 10:57
本帖最后由 话痨司机啊 于 2022-8-24 09:02 编辑

改一下url就行
成品地址:【双击运行】 omofun 动漫下载器(成品) - 『编程语言区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn
弹幕下载移步此处:omofun 字幕下载 - 『编程语言区』 - 吾爱破解 - LCG - LSG |安卓破解|病毒分析|www.52pojie.cn

[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
import requests
import re
from loguru import logger
from lxml import etree
from python_idm import download
from pathlib import Path
from H_m3u8DL import m3u8download
 
logger.add('omofun_log.log')
 
@logger.catch
def requests_functions(url):
    res = requests.get(url)
    return res.text
 
@logger.catch
def regular_functions(string,text):
    return re.findall(string,text)[0]
 
def title_filter(title: str):
    """
    转为Windows合法文件名
    """
    lst = ['\r','\n', '\\', '/', ':', '*', '?', '"', '<', '>', '|']
    for key in lst:
        title = title.replace(key,'-')
    if len(title) > 60:
        title = title[:60]
    return title.strip()
 
def get_mp4_url(url):
    text = requests_functions(url)
    et = etree.HTML(text)
    title = et.xpath('//title/text()')[0]
    string = r'(?i)player_aaaa=(.*?)</script><script'
    player_aaaa_text = regular_functions(string,text)
    player_aaaa_json = eval(player_aaaa_text)
    ids = player_aaaa_json.get('id')
    _url = player_aaaa_json.get('url')
    if 'omofun' in _url:
        php_url = f'https://omofun.tv/addons/dp/player/index.php?key=0&id={ids}&from=omo&url={_url}'
    else:
        php_url = f'https://omofun.tv/addons/dp/player/index.php?key=0&id={ids}&from=mp4&url={_url}'
    text = requests_functions(php_url)
    string = r'(?i)window.location.href=(.*?);</script>'
    target_result = regular_functions(string,text)
    target_url = "https://omofun.tv" + eval(target_result)
    text = requests_functions(target_url)
    string = r'(?ms)var config.{3}\{(.*?)\}'
    target_result = regular_functions(string,text)
    _mp4_json = '{' + target_result.replace('\n','').replace(' ','') + '}}}'
    mp4_url = eval(_mp4_json).get('url')
    return mp4_url,title
 
def downloads(url):
    mp4_url,title = get_mp4_url(url)
    logger.info(f'{title},下载地址:{mp4_url}')
    title = title_filter(title) + '.mp4'
    if 'mp4' in mp4_url.split('.')[-1]:
        title = Path('.').joinpath(title)
        download(url=mp4_url,thread_count=24,save_name=title)
    elif 'm3u8' in mp4_url.split('.')[-1]:
        m3u8download(mp4_url,title=title,work_dir='./video_download')
     
if __name__ == "__main__":
    with open(Path('.').joinpath('omofun_address.txt'),'r',encoding='utf8') as f:
        urls = f.readlines()
    for url in urls:
        downloads(url)




[Python] 纯文本查看 复制代码
01
02
03
04
05
06
07
08
09
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
from concurrent.futures import ThreadPoolExecutor, as_completed
import requests
from itertools import tee
from alive_progress import alive_bar
 
def pairwise(iterable):
    '''转换'''
    # pairwise('ABCDEFG') --> AB BC CD DE EF FG
    a, b = tee(iterable)
    next(b, None)
    return zip(a, b)
 
def calc_divisional_range(res,threads_count):
    '''分区下载'''
    capacity = int(res.headers['Content-Length'])
    remainder = int(capacity%threads_count)
    singular = int((capacity - remainder)/threads_count)
    url_range = list(pairwise((range(0,capacity - remainder,singular))))
    url_range[-1] = (url_range[-1][0],capacity-1)
    return url_range
 
def range_download(url,save_name, s_pos, e_pos,proxies=None):
    '''下载函数'''
    headers = {"Range": f"bytes={s_pos}-{e_pos}"}
    res = requests.get(url, headers=headers, stream=True,proxies=proxies)
    with open(save_name, "rb+") as f:
        f.seek(s_pos)
        for chunk in res.iter_content(chunk_size=64*1024):
            if chunk:
                f.write(chunk)
 
def download(url,thread_count,save_name=None,proxies=None):
    '''多线程调用下载'''
    # url,thread_count = 'http://yue.cmvideo.cn:8080/depository_yqv/asset/zhengshi/5102/598/709/5102598709/media/5102598709_5010999563_56.mp4',16
    if save_name is None:
        save_name = url.split('/')[-1]
    print(save_name,'下载中……')
    res = requests.head(url,proxies=proxies)
    divisional_ranges = calc_divisional_range(res,thread_count)
    with open(save_name, "wb") as f:
        pass
    with ThreadPoolExecutor(max_workers=thread_count) as p,alive_bar(len(divisional_ranges)+1) as bar:
        futures = []
        for s_pos, e_pos in divisional_ranges:
            # print(s_pos, e_pos)
            futures.append(p.submit(range_download,url,save_name, s_pos, e_pos,proxies=proxies))
        # 等待所有任务执行完毕
        for f in as_completed(futures):
            if f.done():
                bar()
    print(save_name,'下载完成!')
 
if __name__ == '__main__':
    url = input('输入下载链接:')
    thread_count = 16
    download(url,thread_count)

免费评分

参与人数 1吾爱币 +2 收起 理由
sk8820 + 2 谢谢@Thanks!

查看全部评分

发帖前要善用论坛搜索功能,那里可能会有你要找的答案或者已经有人发布过相同内容了,请勿重复发帖。

wuge4 发表于 2022-8-19 13:44
这个动漫网站有的弹幕文件吗?
Sealsclerk 发表于 2022-8-19 12:37
谢谢,终于能下载了,还有能下载弹幕的方法吗
只送两个头 发表于 2022-8-19 11:04
Supermexyh 发表于 2022-8-19 11:14
这个动漫网站最近很火,楼主可以下载它的弹幕文件吗
iawyxkdn8 发表于 2022-8-19 11:18
谢谢老铁分享!!
雪莱鸟 发表于 2022-8-19 11:33
好像看到另外一个站点也是用了这种网站框架,求网站框架地址
宝石小赫 发表于 2022-8-19 11:34
正好需要,感谢啦
hengwang1989 发表于 2022-8-19 12:14
感谢分享,谢谢
丨miss丶星星 发表于 2022-8-19 12:43
我先拿走,以后再用
kuailedeniuniu 发表于 2022-8-19 13:09
感谢分享!
您需要登录后才可以回帖 登录 | 注册[Register]

本版积分规则

返回列表

RSS订阅|小黑屋|处罚记录|联系我们|吾爱破解 - LCG - LSG ( 京ICP备16042023号 | 京公网安备 11010502030087号 )

GMT+8, 2025-5-23 06:31

Powered by Discuz!

Copyright © 2001-2020, Tencent Cloud.

快速回复 返回顶部 返回列表