fix bug m3u8 url

This commit is contained in:
Ghost 2024-01-07 13:24:28 +01:00
parent beb015685f
commit 11a4120124
13 changed files with 468 additions and 459 deletions

View File

@ -1,9 +1,9 @@
# 3.12.23 -> 10.12.23 # 3.12.23 -> 10.12.23
# Class import # Class import
from Stream.util.headers import get_headers from Src.Util.Helper.headers import get_headers
from Stream.util.m3u8 import dw_m3u8 from Src.Util.Helper.util import convert_utf8_name
from Stream.util.util import convert_utf8_name from Src.Util.m3u8 import dw_m3u8
# General import # General import
import requests, os, re, json import requests, os, re, json

View File

@ -1,8 +1,8 @@
# 10.12.23 # 10.12.23
# Class import # Class import
from Stream.util.headers import get_headers from Src.Util.Helper.headers import get_headers
from Stream.util.console import console from Src.Util.Helper.console import console
# General import # General import
import requests, json, sys import requests, json, sys

View File

@ -1,10 +1,10 @@
# 3.12.23 -> 10.12.23 # 3.12.23 -> 10.12.23
# Class import # Class import
from Stream.util.headers import get_headers from Src.Util.Helper.headers import get_headers
from Stream.util.console import console, msg from Src.Util.Helper.util import convert_utf8_name
from Stream.util.m3u8 import dw_m3u8, join_audio_to_video from Src.Util.Helper.console import console, msg
from Stream.util.util import convert_utf8_name from Src.Util.m3u8 import dw_m3u8
# General import # General import
import requests, os, re, json import requests, os, re, json

View File

Before

Width:  |  Height:  |  Size: 6.1 KiB

After

Width:  |  Height:  |  Size: 6.1 KiB

View File

Before

Width:  |  Height:  |  Size: 7.1 MiB

After

Width:  |  Height:  |  Size: 7.1 MiB

View File

@ -1,5 +1,5 @@
__title__ = 'Streaming_community' __title__ = 'Streaming_community'
__version__ = 'v0.7.1' __version__ = 'v0.7.0'
__author__ = 'Ghost6446' __author__ = 'Ghost6446'
__description__ = 'A command-line program to download film' __description__ = 'A command-line program to download film'
__license__ = 'MIT License' __license__ = 'MIT License'

View File

@ -1,7 +1,7 @@
# 13.09.2023 # 13.09.2023
# General import # General import
from Stream.util.console import console from Src.Util.Helper.console import console
import os, requests, time import os, requests, time
# Variable # Variable

View File

@ -4,7 +4,6 @@
from random_user_agent.user_agent import UserAgent from random_user_agent.user_agent import UserAgent
from random_user_agent.params import SoftwareName, OperatingSystem from random_user_agent.params import SoftwareName, OperatingSystem
# [func]
def get_headers(): def get_headers():
software_names = [SoftwareName.CHROME.value] software_names = [SoftwareName.CHROME.value]
operating_systems = [OperatingSystem.WINDOWS.value, OperatingSystem.LINUX.value] operating_systems = [OperatingSystem.WINDOWS.value, OperatingSystem.LINUX.value]

View File

@ -1,9 +1,8 @@
# 3.12.23 # 3.12.23
# Import # Import
from Stream.util.console import console from Src.Util.Helper.console import console
# [Function]
def msg_start(): def msg_start():
msg = """ msg = """
@ -17,4 +16,4 @@ def msg_start():
|___/ |___/ |___/ |___/
""" """
console.log(f"[purple]{msg}") console.print(f"[purple]{msg}")

View File

@ -1,7 +1,7 @@
# 4.01.2023 # 4.01.2023
# Import # Import
import ffmpeg, subprocess import ffmpeg
def convert_utf8_name(name): def convert_utf8_name(name):
return str(name).encode('utf-8').decode('latin-1') return str(name).encode('utf-8').decode('latin-1')
@ -12,20 +12,6 @@ def there_is_audio(ts_file_path):
def merge_ts_files(video_path, audio_path, output_path): def merge_ts_files(video_path, audio_path, output_path):
"""command = [
'ffmpeg',
'-i', video_path,
'-i', audio_path,
'-c', 'copy',
'-map', '0',
'-map', '1',
'-y', output_path
]
subprocess.run(command)"""
input_video = ffmpeg.input(video_path) input_video = ffmpeg.input(video_path)
input_audio = ffmpeg.input(audio_path) input_audio = ffmpeg.input(audio_path)
ffmpeg.output(input_video, input_audio, output_path, format='mpegts', acodec='copy', vcodec='copy', loglevel='quiet').run() ffmpeg.output(input_video, input_audio, output_path, format='mpegts', acodec='copy', vcodec='copy', loglevel='quiet').run()

View File

@ -1,7 +1,7 @@
# 5.01.24 # 5.01.24 -> 7.01.24
# Import # Import
import requests, re, os, ffmpeg, shutil, time import requests, re, os, ffmpeg, shutil, time, sys
from tqdm.rich import tqdm from tqdm.rich import tqdm
from concurrent.futures import ThreadPoolExecutor from concurrent.futures import ThreadPoolExecutor
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
@ -9,9 +9,10 @@ from cryptography.hazmat.backends import default_backend
import moviepy.editor as mp import moviepy.editor as mp
# Class import # Class import
from Stream.util.console import console from Src.Util.Helper.console import console
from Stream.util.headers import get_headers from Src.Util.Helper.headers import get_headers
from Stream.util.util import there_is_audio, merge_ts_files from Src.Util.Helper.util import there_is_audio, merge_ts_files
# Variable # Variable
os.makedirs("videos", exist_ok=True) os.makedirs("videos", exist_ok=True)
@ -66,10 +67,25 @@ class M3U8Downloader:
ts_url = m3u8_base_url + ts_url ts_url = m3u8_base_url + ts_url
self.segments.append(ts_url) self.segments.append(ts_url)
if self.m3u8_audio != None: self.segments_audio.append(m3u8_audio_line[i+1])
if self.m3u8_audio != None:
self.segments_audio.append(m3u8_audio_line[i+1])
console.log(f"[cyan]Find: {len(self.segments)} ts file to download") console.log(f"[cyan]Find: {len(self.segments)} ts file to download")
# Check video ts segment
if len(self.segments) == 0:
console.log("[red]No ts files to download")
sys.exit(0)
# Check audio ts segment
if self.m3u8_audio != None:
console.log(f"[cyan]Find: {len(self.segments_audio)} ts audio file to download")
if len(self.segments_audio) == 0:
console.log("[red]No ts audio files to download")
sys.exit(0)
def download_m3u8(self): def download_m3u8(self):
response = requests.get(self.m3u8_url, headers={'user-agent': get_headers()}) response = requests.get(self.m3u8_url, headers={'user-agent': get_headers()})
@ -77,6 +93,13 @@ class M3U8Downloader:
m3u8_content = response.text m3u8_content = response.text
self.parse_m3u8(m3u8_content) self.parse_m3u8(m3u8_content)
else:
console.log("[red]Wrong m3u8 url")
sys.exit(0)
if self.m3u8_audio != None:
# Check there is audio in first ts file # Check there is audio in first ts file
path_test_ts_file = os.path.join(self.temp_folder, "ts_test.ts") path_test_ts_file = os.path.join(self.temp_folder, "ts_test.ts")
if self.key and self.iv: if self.key and self.iv:
@ -88,6 +111,7 @@ class M3U8Downloader:
self.download_audio = True self.download_audio = True
console.log("[cyan]=> Make req to get video and audio file") console.log("[cyan]=> Make req to get video and audio file")
console.log("[cyan]=> Download audio")
os.remove(path_test_ts_file) os.remove(path_test_ts_file)
def decrypt_ts(self, encrypted_data): def decrypt_ts(self, encrypted_data):
@ -166,14 +190,15 @@ class M3U8Downloader:
) )
console.log(f"[cyan]Clean ...") console.log(f"[cyan]Clean ...")
except ffmpeg.Error as e: except ffmpeg.Error as e:
print(f"Errore durante il salvataggio del file MP4: {e}") console.log(f"[red]Error saving MP4: {e.stdout}")
finally: sys.exit(0)
time.sleep(2) time.sleep(2)
os.remove(file_list_path) os.remove(file_list_path)
shutil.rmtree("tmp", ignore_errors=True) shutil.rmtree("tmp", ignore_errors=True)
# [ function ] # [ main function ]
def dw_m3u8(url, audio_url=None, key=None, output_filename="output.mp4"): def dw_m3u8(url, audio_url=None, key=None, output_filename="output.mp4"):
downloader = M3U8Downloader(url, audio_url, key, output_filename) downloader = M3U8Downloader(url, audio_url, key, output_filename)

12
run.py
View File

@ -1,12 +1,12 @@
# 10.12.23 # 10.12.23
# Class import # Class import
import Stream.api.page as Page import Src.Api.page as Page
from Stream.util.message import msg_start from Src.Api.film import main_dw_film as download_film
from Stream.upload.update import main_update from Src.Api.tv import main_dw_tv as download_tv
from Stream.util.console import console, msg from Src.Util.Helper.message import msg_start
from Stream.api.film import main_dw_film as download_film from Src.Util.Helper.console import console, msg
from Stream.api.tv import main_dw_tv as download_tv from Src.Upload.update import main_update
# General import # General import
import sys import sys