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
# Class import
from Stream.util.headers import get_headers
from Stream.util.m3u8 import dw_m3u8
from Stream.util.util import convert_utf8_name
from Src.Util.Helper.headers import get_headers
from Src.Util.Helper.util import convert_utf8_name
from Src.Util.m3u8 import dw_m3u8
# General import
import requests, os, re, json

View File

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

View File

@ -1,10 +1,10 @@
# 3.12.23 -> 10.12.23
# Class import
from Stream.util.headers import get_headers
from Stream.util.console import console, msg
from Stream.util.m3u8 import dw_m3u8, join_audio_to_video
from Stream.util.util import convert_utf8_name
from Src.Util.Helper.headers import get_headers
from Src.Util.Helper.util import convert_utf8_name
from Src.Util.Helper.console import console, msg
from Src.Util.m3u8 import dw_m3u8
# General import
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'
__version__ = 'v0.7.1'
__version__ = 'v0.7.0'
__author__ = 'Ghost6446'
__description__ = 'A command-line program to download film'
__license__ = 'MIT License'

View File

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

View File

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

View File

@ -1,9 +1,8 @@
# 3.12.23
# Import
from Stream.util.console import console
from Src.Util.Helper.console import console
# [Function]
def msg_start():
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
# Import
import ffmpeg, subprocess
import ffmpeg
def convert_utf8_name(name):
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):
"""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_audio = ffmpeg.input(audio_path)
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 requests, re, os, ffmpeg, shutil, time
import requests, re, os, ffmpeg, shutil, time, sys
from tqdm.rich import tqdm
from concurrent.futures import ThreadPoolExecutor
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
# Class import
from Stream.util.console import console
from Stream.util.headers import get_headers
from Stream.util.util import there_is_audio, merge_ts_files
from Src.Util.Helper.console import console
from Src.Util.Helper.headers import get_headers
from Src.Util.Helper.util import there_is_audio, merge_ts_files
# Variable
os.makedirs("videos", exist_ok=True)
@ -66,10 +67,25 @@ class M3U8Downloader:
ts_url = m3u8_base_url + 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")
# 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):
response = requests.get(self.m3u8_url, headers={'user-agent': get_headers()})
@ -77,6 +93,13 @@ class M3U8Downloader:
m3u8_content = response.text
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
path_test_ts_file = os.path.join(self.temp_folder, "ts_test.ts")
if self.key and self.iv:
@ -88,6 +111,7 @@ class M3U8Downloader:
self.download_audio = True
console.log("[cyan]=> Make req to get video and audio file")
console.log("[cyan]=> Download audio")
os.remove(path_test_ts_file)
def decrypt_ts(self, encrypted_data):
@ -166,14 +190,15 @@ class M3U8Downloader:
)
console.log(f"[cyan]Clean ...")
except ffmpeg.Error as e:
print(f"Errore durante il salvataggio del file MP4: {e}")
finally:
console.log(f"[red]Error saving MP4: {e.stdout}")
sys.exit(0)
time.sleep(2)
os.remove(file_list_path)
shutil.rmtree("tmp", ignore_errors=True)
# [ function ]
# [ main function ]
def dw_m3u8(url, audio_url=None, key=None, output_filename="output.mp4"):
downloader = M3U8Downloader(url, audio_url, key, output_filename)

12
run.py
View File

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