Fix non-drm lectures not having proper file extension

This commit is contained in:
Puyodead1 2021-07-22 12:04:31 -04:00 committed by Puyodead1
parent 96578c2327
commit 400316e1b3
2 changed files with 17 additions and 29 deletions

2
.gitignore vendored
View File

@ -114,7 +114,6 @@ dmypy.json
.pyre/ .pyre/
*.mp4 *.mp4
keyfile.json keyfile.json
.env
test_data.json test_data.json
out_dir out_dir
working_dir working_dir
@ -123,3 +122,4 @@ manifest.mpd
saved saved
*.aria2 *.aria2
info.py info.py
.idea/

42
main.py
View File

@ -1,25 +1,24 @@
import os
import requests
import json
import glob
import argparse import argparse
import sys import glob
import re
import time
import asyncio
import json import json
import os
import re
import subprocess
import sys
import time
from html.parser import HTMLParser as compat_HTMLParser
import cloudscraper import cloudscraper
import m3u8 import m3u8
from tqdm import tqdm import requests
import yt_dlp
from dotenv import load_dotenv from dotenv import load_dotenv
from mpegdash.parser import MPEGDASHParser from requests.exceptions import ConnectionError as conn_error
from tqdm import tqdm
from sanitize import sanitize, slugify, SLUG_OK
from utils import extract_kid from utils import extract_kid
from vtt_to_srt import convert from vtt_to_srt import convert
from requests.exceptions import ConnectionError as conn_error
from html.parser import HTMLParser as compat_HTMLParser
from sanitize import sanitize, slugify, SLUG_OK
import subprocess
import yt_dlp
home_dir = os.getcwd() home_dir = os.getcwd()
download_dir = os.path.join(os.getcwd(), "out_dir") download_dir = os.path.join(os.getcwd(), "out_dir")
@ -1033,17 +1032,12 @@ def process_lecture(lecture, lecture_path, lecture_file_name, quality, access_to
if is_encrypted: if is_encrypted:
if len(lecture_sources) > 0: if len(lecture_sources) > 0:
# lecture_working_dir = os.path.join(working_dir,
# str(lecture.get("asset_id")))
if not os.path.isfile(lecture_path): if not os.path.isfile(lecture_path):
source = lecture_sources[-1] # last index is the best quality source = lecture_sources[-1] # last index is the best quality
if isinstance(quality, int): if isinstance(quality, int):
source = min( source = min(
lecture_sources, lecture_sources,
key=lambda x: abs(int(x.get("height")) - quality)) key=lambda x: abs(int(x.get("height")) - quality))
# if not os.path.exists(lecture_working_dir):
# os.mkdir(lecture_working_dir)
print(f" > Lecture '%s' has DRM, attempting to download" % print(f" > Lecture '%s' has DRM, attempting to download" %
lecture_title) lecture_title)
handle_segments(source.get("download_url"), handle_segments(source.get("download_url"),
@ -1064,10 +1058,6 @@ def process_lecture(lecture, lecture_path, lecture_file_name, quality, access_to
key=lambda x: int(x.get("height")), key=lambda x: int(x.get("height")),
reverse=True) reverse=True)
if sources: if sources:
# lecture_working_dir = os.path.join(working_dir,
# str(lecture.get("asset_id")))
# if not os.path.exists(lecture_working_dir):
# os.mkdir(lecture_working_dir)
if not os.path.isfile(lecture_path): if not os.path.isfile(lecture_path):
print( print(
" > Lecture doesn't have DRM, attempting to download..." " > Lecture doesn't have DRM, attempting to download..."
@ -1083,9 +1073,7 @@ def process_lecture(lecture, lecture_path, lecture_file_name, quality, access_to
url = source.get("download_url") url = source.get("download_url")
source_type = source.get("type") source_type = source.get("type")
if source_type == "hls": if source_type == "hls":
temp_filepath = lecture_path.replace(".mp4", "") temp_filepath = lecture_path.replace(".mp4", ".%(ext)s")
# retVal = FFMPEG(None, url, access_token,
# temp_filepath).download()
ret_code = subprocess.Popen([ ret_code = subprocess.Popen([
"yt-dlp", "--force-generic-extractor", "yt-dlp", "--force-generic-extractor",
"--concurrent-fragments", "--concurrent-fragments",