diff --git a/HLSDownloader.exe b/HLSDownloader.exe new file mode 100644 index 0000000..3edebfe --- /dev/null +++ b/HLSDownloader.exe Binary files differ diff --git a/main_windows.py b/main_windows.py index f286610..3503163 100644 --- a/main_windows.py +++ b/main_windows.py @@ -147,7 +147,7 @@ name_prefix += folder_name.rstrip() + "/" # Remove illegal characters for Windows filenames - name_prefix = re.sub(r'[<>:"\\|?*]', '_', name_prefix) + name_prefix = re.sub(r'[<>:"\\|?*\xa0]', '_', name_prefix) if args.lesson_name_filter is not None: lesson_data['data']['activities'] = [l for l in lesson_data['data']['activities'] if @@ -190,7 +190,7 @@ name_prefix += "-" + lesson['title'].rstrip() # Remove illegal characters for Windows filenames - name_prefix = re.sub(r'[<>:"\\|?*]', '_', name_prefix) + name_prefix = re.sub(r'[<>:"\\|?*\xa0]', '_', name_prefix) if 'live' not in lesson_video_data['data']: print(f"v3 protocol detection failed, falling back to v1") @@ -252,7 +252,7 @@ name_prefix += "-" + lesson['title'].rstrip() # Remove illegal characters for Windows filenames - name_prefix = re.sub(r'[<>:"\\|?*]', '_', name_prefix) + name_prefix = re.sub(r'[<>:"\\|?*\xa0]', '_', name_prefix) if 'presentations' not in lesson_data['data']: print(f"v3 protocol detection failed, falling back to v1") diff --git a/ppt_processing.py b/ppt_processing.py index 747bbe4..d2ad2bc 100644 --- a/ppt_processing.py +++ b/ppt_processing.py @@ -13,7 +13,7 @@ name_prefix += "-" + ppt_raw_data['data']['presentation']['title'].rstrip() # Remove illegal characters for Windows filenames - name_prefix = re.sub(r'[<>:"\\|?*]', '_', name_prefix) + name_prefix = re.sub(r'[<>:"\\|?*\xa0]', '_', name_prefix) # If PDF is present, skip if os.path.exists(f"{DOWNLOAD_FOLDER}/{name_prefix}.pdf"): diff --git a/scrap_example.txt b/scrap_example.txt index dd58816..656ad98 100644 --- a/scrap_example.txt +++ b/scrap_example.txt @@ -160,7 +160,7 @@ # "user": { # "identityId": "21640720", # "avatar": "http://qn-sx.yuketang.cn/tougao_pic_AFzVVZcN5p9.png", -# "name": "董业恺", +# "name": "[REDACTED]", # "number": "2022010426" # }, # "activityId": "7970721", diff --git a/video_processing.py b/video_processing.py index 5efbb2c..5d9f89c 100644 --- a/video_processing.py +++ b/video_processing.py @@ -16,11 +16,43 @@ print(f"Downloading {name_prefix} - {order}") - video_download_command = (f".\\ffmpeg -i '{url}' -c copy -n '{CACHE_FOLDER}/{name_prefix}-{order}.mp4'" - f" -hide_banner -loglevel error -stats") + # video_download_command = (f".\\ffmpeg -i '{url}' -c copy -n '{CACHE_FOLDER}/{name_prefix}-{order}.mp4'" + # f" -hide_banner -loglevel error -stats") + + video_download_command = (f".\\HLSDownloader -u '{url}' -o '{CACHE_FOLDER}/{name_prefix}-{order}.mp4'" + f" -w 32 -workers 32 ") result = subprocess.run(['powershell', '-Command', video_download_command], text=True) + # Check if HLSDownloader succeeded + if result.returncode != 0: + print(f"HLSDownloader failed for {name_prefix} - {order}. Attempting fallback with reduced workers.") + + # Second attempt with HLSDownloader using 8 workers + video_download_command_mid = (f".\\HLSDownloader -u '{url}' -o '{CACHE_FOLDER}/{name_prefix}-{order}.mp4' " + f"-w 8 -workers 8") + + mid_result = subprocess.run(['powershell', '-Command', video_download_command_mid], text=True) + + # Check if the second attempt succeeded + if mid_result.returncode != 0: + print(f"Reduced workers HLSDownloader failed for {name_prefix} - {order}. Attempting fallback with ffmpeg.") + + # Fallback to ffmpeg + ffmpeg_command = (f".\\ffmpeg -i '{url}' -c copy -n '{CACHE_FOLDER}/{name_prefix}-{order}.mp4' " + f"-hide_banner -loglevel error -stats") + + fallback_result = subprocess.run(['powershell', '-Command', ffmpeg_command], text=True) + + if fallback_result.returncode == 0: + print(f"Successfully downloaded {name_prefix} - {order} using ffmpeg.") + else: + print(f"Failed to download {name_prefix} - {order} using both methods.") + else: + print(f"Successfully downloaded {name_prefix} - {order} using HLSDownloader with reduced workers.") + else: + print(f"Successfully downloaded {name_prefix} - {order} using HLSDownloader.") + return result @@ -94,6 +126,6 @@ f"-i '{CACHE_FOLDER}/concat.txt' " f"-c:v hevc_nvenc -cq 28 -surfaces 64 -bufsize 12800k -r 7.5 -rc-lookahead 63 " f"-c:a aac -ac 1 -rematrix_maxval 1.0 -b:a 64k '{DOWNLOAD_FOLDER}/{name_prefix}.mp4' -n " - f"-hide_banner -loglevel warning -stats") + f"-hide_banner -loglevel error -stats") subprocess.run(['powershell', '-Command', video_concatenating_command], text=True) \ No newline at end of file