Skip to content

Instantly share code, notes, and snippets.

@ravenclaw900
Last active August 12, 2020 15:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ravenclaw900/8d11789ff5c14dc7d482e5839ed86ae1 to your computer and use it in GitHub Desktop.
Save ravenclaw900/8d11789ff5c14dc7d482e5839ed86ae1 to your computer and use it in GitHub Desktop.
A Python script to convert a JWPlayer RSS file to a videojs-playlist file
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
import re
filename = input("What is the file name (no extension)? ")
old = open(filename + '.rss', 'r')
new = open(filename + '.js', 'w')
lc = sum(1 for line in old if line.strip())
new.write("var player = videojs('video');\n\n")
new.write("player.playlist([\n")
old = open(filename + '.rss', 'r')
for line in old:
if not line == '':
lc -= 1
if re.search(r"(?<=<title>)(.)*(?=<\/title>)", line):
new.write("\t{\n")
new.write("\t\tname: '" + re.search(r"(?<=<title>)(.)*(?=<\/title>)", line).group(0) + "',\n")
elif re.search(r"(?<=<jwplayer:source file=\")(.)*(?=\" />)", line):
new.write("\t\tsources:\n")
new.write("\t\t\t[\n")
new.write("\t\t\t\t{\n")
new.write("\t\t\t\t\tsrc: '" + re.search(r"(?<=<jwplayer:source file=\")(.)*(?=\" />)", line).group(0) + "',\n")
new.write("\t\t\t\t\ttype: 'video/mp4'\n")
new.write("\t\t\t\t}\n")
new.write("\t\t\t]\n")
if lc <= 0:
new.write("\t}\n")
else:
new.write("\t},\n")
new.write("], -1);\n\n")
new.write("player.playlistUi({playOnSelect: true});")
old.close()
new.close()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment