-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
""" | |
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