Skip to content

Instantly share code, notes, and snippets.

@droogie
Forked from iluxonchik/jwplayer_downloader.py
Last active April 24, 2023 01:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save droogie/e5b9115983b81b72fc176da7bfe7fd35 to your computer and use it in GitHub Desktop.
Save droogie/e5b9115983b81b72fc176da7bfe7fd35 to your computer and use it in GitHub Desktop.
Download JWPlayer .ts files, merge them into a single file and then convert the file to .mp4
"""
Update URL/Filename, execute script and provide output filename as parameter
Requirements:
* Python 3.x
* "ffmpeg" command-line tool.
"""
import sys
import urllib.request
from os import system, remove
out_file_name = sys.argv[1]
# in this case the video files were padded with zeroes
url = 'https://XXX.net/attachments/7960231920314/dff65975fdc647ca87638a355a9344d6/original/Lesson+04/hls/hls_1080p_{0:05d}.ts'
file_name = 'hls_1080p_{0:05d}.ts'
file_names = []
i = 0
while True:
curr_file_name = file_name.format(i)
curr_url = url.format(i)
file_names += [curr_file_name]
print('Downloading {}'.format(curr_url))
try:
urllib.request.urlretrieve(curr_url, curr_file_name)
i = i+1
except:
file_names.pop()
break
print('All files downloaded')
print('Joining into a single .ts file...')
command = ''
for file_name in file_names:
command += '{} '.format(file_name)
command = 'cat ' + command + '> {}'.format(out_file_name + '.ts')
system(command)
system('ffmpeg -i {}.ts -acodec copy -vcodec copy {}.mp4'.format(out_file_name, out_file_name))
print('Clenaing up...')
for file_name in file_names:
remove(file_name)
remove('{}.ts'.format(out_file_name))
print('Done!')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment