Advertisement
dhorsa01

Untitled

Dec 30th, 2015
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.71 KB | None | 0 0
  1.  
  2. @@ -0,0 +1,28 @@
  3. +#! /usr/bin/env python -u
  4. +# coding=utf-8
  5. +import json
  6. +
  7. +__author__ = 'xl'
  8. +
  9. +header_line = "#EXTM3U\n"
  10. +record_line = "#EXTINF:%d,%s\n%s\n"
  11. +
  12. +
  13. +def generate(input_file, output_file):
  14. + ret = header_line
  15. + with open(input_file, "r") as fp:
  16. + data = json.load(fp)
  17. +
  18. + for index, record in enumerate(data):
  19. + title = record['title'] if 'title' in record else ''
  20. + title = title[0] if type(title) is list else title
  21. + ret += record_line % (index, title, record['video_url'])
  22. +
  23. + with open(output_file, "wb") as fp:
  24. + fp.write(ret)
  25. +
  26. +
  27. +if __name__ == "__main__":
  28. + generate("data.json", "Iranian Channels.m3u")
  29. + generate("movies/movies.json", "Movies.m3u")
  30. +
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement