hls: Fix bug add_ts_file

This commit is contained in:
None 2025-03-20 11:23:17 +01:00
parent 48e433d2fb
commit 23b576e4b6
3 changed files with 42 additions and 92 deletions

View File

@ -1,4 +1,4 @@
name: Build or Publish
name: Build and Publish
on:
workflow_dispatch:
@ -17,7 +17,7 @@ on:
jobs:
publish:
if: (startsWith(github.ref_name, 'v') || github.event_name == 'workflow_dispatch') && github.event.inputs.publish_pypi == 'true'
if: startsWith(github.ref_name, 'v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_pypi == 'true')
runs-on: ubuntu-latest
steps:
@ -33,7 +33,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3.12'
- name: Install packaging dependencies
run: |
@ -50,10 +50,31 @@ jobs:
run: twine upload dist/*
build:
if: (startsWith(github.ref_name, 'v') || github.event_name == 'workflow_dispatch') && github.event.inputs.publish_pypi == 'false'
if: startsWith(github.ref_name, 'v') || (github.event_name == 'workflow_dispatch' && github.event.inputs.publish_pypi == 'false')
strategy:
matrix:
os: [windows-latest, ubuntu-latest, macos-latest]
include:
- os: windows-latest
artifact_name: StreamingCommunity_win
executable: StreamingCommunity_win.exe
separator: ';'
- os: macos-latest
artifact_name: StreamingCommunity_mac
executable: StreamingCommunity_mac
separator: ':'
- os: ubuntu-latest
artifact_name: StreamingCommunity_linux_latest
executable: StreamingCommunity_linux_latest
separator: ':'
- os: ubuntu-20.04
artifact_name: StreamingCommunity_linux_previous
executable: StreamingCommunity_linux_previous
separator: ':'
runs-on: ${{ matrix.os }}
steps:
@ -68,43 +89,19 @@ jobs:
run: |
$latestTag = git describe --tags --abbrev=0
echo "latest_tag=$latestTag" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append
- name: Set up Python
uses: actions/setup-python@v4
with:
python-version: '3.11'
python-version: '3.12'
- name: Install dependencies
run: |
python -m pip install --upgrade pip
python -m pip install -r requirements.txt
python -m pip install pyinstaller
- name: Build executable with PyInstaller (Windows)
if: matrix.os == 'windows-latest'
shell: pwsh
run: |
pyinstaller --onefile --hidden-import=pycryptodomex --hidden-import=ua_generator `
--hidden-import=qbittorrentapi --hidden-import=qbittorrent `
--hidden-import=bs4 --hidden-import=httpx --hidden-import=rich --hidden-import=tqdm `
--hidden-import=m3u8 --hidden-import=psutil --hidden-import=unidecode `
--hidden-import=jsbeautifier --hidden-import=jsbeautifier.core `
--hidden-import=jsbeautifier.javascript --hidden-import=jsbeautifier.javascript.beautifier `
--hidden-import=jsbeautifier.unpackers --hidden-import=jsbeautifier.unpackers.packer `
--hidden-import=jsbeautifier.unpackers.javascriptobfuscator `
--hidden-import=jsbeautifier.unpackers.myobfuscate `
--hidden-import=jsbeautifier.unpackers.urlencode `
--hidden-import=jsbeautifier.unpackers.meshim `
--hidden-import=editorconfig --hidden-import=editorconfig.handlers `
--hidden-import=six --hidden-import=pathvalidate `
--hidden-import=Cryptodome.Cipher --hidden-import=Cryptodome.Cipher.AES `
--hidden-import=Cryptodome.Util --hidden-import=Cryptodome.Util.Padding `
--hidden-import=Cryptodome.Random `
--hidden-import=telebot `
--additional-hooks-dir=pyinstaller/hooks `
--add-data "StreamingCommunity;StreamingCommunity" `
--name=StreamingCommunity_win --icon=".github/media/logo.ico" test_run.py
- name: Build executable with PyInstaller (Linux)
if: matrix.os == 'ubuntu-latest'
- name: Build executable with PyInstaller
run: |
pyinstaller --onefile --hidden-import=pycryptodomex --hidden-import=ua_generator \
--hidden-import=qbittorrentapi --hidden-import=qbittorrent \
@ -124,61 +121,19 @@ jobs:
--hidden-import=Cryptodome.Random \
--hidden-import=telebot \
--additional-hooks-dir=pyinstaller/hooks \
--add-data "StreamingCommunity:StreamingCommunity" \
--name=StreamingCommunity_linux test_run.py
--add-data "StreamingCommunity${{ matrix.separator }}StreamingCommunity" \
--name=${{ matrix.artifact_name }} --icon=".github/media/logo.ico" test_run.py
- name: Build executable with PyInstaller (macOS)
if: matrix.os == 'macos-latest'
run: |
pyinstaller --onefile --hidden-import=pycryptodomex --hidden-import=ua_generator \
--hidden-import=qbittorrentapi --hidden-import=qbittorrent \
--hidden-import=bs4 --hidden-import=httpx --hidden-import=rich --hidden-import=tqdm \
--hidden-import=m3u8 --hidden-import=psutil --hidden-import=unidecode \
--hidden-import=jsbeautifier --hidden-import=jsbeautifier.core \
--hidden-import=jsbeautifier.javascript --hidden-import=jsbeautifier.javascript.beautifier \
--hidden-import=jsbeautifier.unpackers --hidden-import=jsbeautifier.unpackers.packer \
--hidden-import=jsbeautifier.unpackers.javascriptobfuscator \
--hidden-import=jsbeautifier.unpackers.myobfuscate \
--hidden-import=jsbeautifier.unpackers.urlencode \
--hidden-import=jsbeautifier.unpackers.meshim \
--hidden-import=editorconfig --hidden-import=editorconfig.handlers \
--hidden-import=six --hidden-import=pathvalidate \
--hidden-import=Cryptodome.Cipher --hidden-import=Cryptodome.Cipher.AES \
--hidden-import=Cryptodome.Util --hidden-import=Cryptodome.Util.Padding \
--hidden-import=Cryptodome.Random \
--hidden-import=telebot \
--additional-hooks-dir=pyinstaller/hooks \
--add-data "StreamingCommunity:StreamingCommunity" \
--name=StreamingCommunity_mac test_run.py
- name: Upload executable (Windows)
if: matrix.os == 'windows-latest'
- name: Upload executable
uses: actions/upload-artifact@v4
with:
name: StreamingCommunity_win
path: dist/StreamingCommunity_win.exe
- name: Upload executable (Linux)
if: matrix.os == 'ubuntu-latest'
uses: actions/upload-artifact@v4
with:
name: StreamingCommunity_linux
path: dist/StreamingCommunity_linux
- name: Upload executable (macOS)
if: matrix.os == 'macos-latest'
uses: actions/upload-artifact@v4
with:
name: StreamingCommunity_mac
path: dist/StreamingCommunity_mac
name: ${{ matrix.artifact_name }}
path: dist/${{ matrix.executable }}
- name: Create or update release
uses: softprops/action-gh-release@v1
with:
tag_name: ${{ env.latest_tag }}
files: |
dist/StreamingCommunity_win.exe
dist/StreamingCommunity_linux
dist/StreamingCommunity_mac
files: dist/${{ matrix.executable }}
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

View File

@ -223,14 +223,12 @@ class M3U8_Segments:
try:
with self._get_http_client() as client:
start_time = time.time()
response = client.get(ts_url)
# Validate response and content
response.raise_for_status()
segment_content = response.content
content_size = len(segment_content)
duration = time.time() - start_time
# Decrypt if needed and verify decrypted content
if self.decryption is not None:
@ -243,7 +241,7 @@ class M3U8_Segments:
self.stop_event.set() # Trigger the stopping event for all threads
break # Stop the current task immediately
self.class_ts_estimator.update_progress_bar(content_size, duration, progress_bar)
self.class_ts_estimator.update_progress_bar(content_size, progress_bar)
self.queue.put((index, segment_content))
self.downloaded_segments.add(index)
progress_bar.update(1)

View File

@ -27,7 +27,6 @@ class M3U8_Ts_Estimator:
- total_segments (int): Length of total segments to download.
"""
self.ts_file_sizes = []
self.now_downloaded_size = 0
self.total_segments = total_segments
self.segments_instance = segments_instance
self.lock = threading.Lock()
@ -42,15 +41,13 @@ class M3U8_Ts_Estimator:
else:
logging.debug("USE_LARGE_BAR is False, speed capture thread not started")
def add_ts_file(self, size: int, size_download: int, duration: float):
def add_ts_file(self, size: int):
"""Add a file size to the list of file sizes."""
if size <= 0 or size_download <= 0 or duration <= 0:
logging.error(f"Invalid input values: size={size}, size_download={size_download}, duration={duration}")
if size <= 0:
logging.error(f"Invalid input values: size={size}")
return
self.ts_file_sizes.append(size)
self.now_downloaded_size += size_download
logging.debug(f"Current total downloaded size: {self.now_downloaded_size}")
def capture_speed(self, interval: float = 1.5):
"""Capture the internet speed periodically."""
@ -99,9 +96,9 @@ class M3U8_Ts_Estimator:
logging.error("An unexpected error occurred: %s", e)
return "Error"
def update_progress_bar(self, total_downloaded: int, duration: float, progress_counter: tqdm) -> None:
def update_progress_bar(self, total_downloaded: int, progress_counter: tqdm) -> None:
try:
self.add_ts_file(total_downloaded * self.total_segments, total_downloaded, duration)
self.add_ts_file(total_downloaded * self.total_segments)
file_total_size = self.calculate_total_size()
number_file_total_size = file_total_size.split(' ')[0]