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
):
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)