swargaraj / udemy-py

🎓 Udemy downloader with DRM support.
https://t.me/+ixTitVxk4CIxNGVl
MIT License
19 stars 8 forks source link

add options for custom quality video, convert vtt to srt #10

Open epitaphoveruse0h opened 4 days ago

epitaphoveruse0h commented 4 days ago

please add more options for: --quality to choose video 720p, 1080p, .... --caption-srt to convert from .vtt to srt

@swargaraj This repo so cool!

swargaraj commented 4 days ago

Thank you! I'm glad you like the repo!

Regarding your suggestions, I wanted to let you know that the SRT conversion will be added as the --srt flag in the next pull request.

As for the video quality options, I currently cannot add specific quality selections (like 720p or 1080p) because Udemy uses varying resolutions for their videos. Tracking and implementing these resolutions accurately can be a bit tricky due to the way their content is delivered.

I appreciate your understanding, and I’m always open to further suggestions!

epitaphoveruse0h commented 4 days ago

Thank your response! I found func download_and_merge_m3u8 on process_m3u8.py

for pl in playlists:
    resolution = pl.stream_info.resolution

    print(resolution) # I added

    if resolution and (resolution[0] * resolution[1] > max_resolution[0] * max_resolution[1]):
         highest_quality_playlist = pl
         max_resolution = resolution

When i was print(resolution) the results:

(640, 360)
(768, 432)
(1024, 576)
(1280, 720)
(1920, 1080)

So I thought has changed:

if resolution and (resolution[0] == 1280 and resolution[1] == 720 ):
   highest_quality_playlist = pl
   max_resolution = resolution

Open my course folder, the audio and video working!

This simple solution I had changed.

With Udemy, the basic video minimum is 720p

I think you can add args accept add options

-q 720 -> 1280x720
-q 1080 -> 1920x1080 ( default )

When add -q 720 the program will be find 1280x720 resolution in pl.stream_info.resolution. If not set, this is a max_resolution of courses

That's just my personal opinion; you can consider it and make adjustments to the project as you see fit.

swargaraj commented 4 days ago

This is correct for the M3U8 (HLS) files, but most of the lectures are in MPD (Dash) format. In case of Dash files, the program downloads and passes the .mpd manifest to n_m3u8_dl CLI which does has a argument for selecting video.

When i was trying to implement the quality feature with a sample mpd file, i received the resolution like these:

18:31:51.218 INFO : Vid 960x540 | 1203 Kbps | V1200 | avc1.64001f | 7 Segments | ~00m56s
18:31:51.218 INFO : Vid 640x360 | 603 Kbps | V600 | avc1.64001e | 7 Segments | ~00m56s
18:31:51.218 INFO : Vid 640x360 | 303 Kbps | V300 | avc1.64001e | 7 Segments | ~00m56s

These resolutions are different from the standard ones and could not be mapped properly.

Another thing is, say you passed the quality 1080p to download and one of the lecture is not 1080p, then the script/n_m3u8_dl will simply skip downloading that, rather than downloading the best available lecture. Because of this, there will be a need for an additional check for every lecture to check if the provided quality exists.

outtycast commented 1 hour ago

can use ffmpeg to convert subtitles

subprocess.run(['ffmpeg', '-i', vvt_filename, '-loglevel', 'quiet', '-hide_banner', '-nostats', '-y', srt_filename])