You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

76 lines
2.2 KiB

  1. #!/usr/bin/env python3
  2. import datetime
  3. import io
  4. import json
  5. import textwrap
  6. atom_template = textwrap.dedent("""\
  7. <?xml version="1.0" encoding="utf-8"?>
  8. <feed xmlns="http://www.w3.org/2005/Atom">
  9. <link rel="self" href="http://rg3.github.io/youtube-dl/update/releases.atom" />
  10. <title>youtube-dl releases</title>
  11. <id>https://yt-dl.org/feed/youtube-dl-updates-feed</id>
  12. <updated>@TIMESTAMP@</updated>
  13. @ENTRIES@
  14. </feed>""")
  15. entry_template = textwrap.dedent("""
  16. <entry>
  17. <id>https://yt-dl.org/feed/youtube-dl-updates-feed/youtube-dl-@VERSION@</id>
  18. <title>New version @VERSION@</title>
  19. <link href="http://rg3.github.io/youtube-dl" />
  20. <content type="xhtml">
  21. <div xmlns="http://www.w3.org/1999/xhtml">
  22. Downloads available at <a href="https://yt-dl.org/downloads/@VERSION@/">https://yt-dl.org/downloads/@VERSION@/</a>
  23. </div>
  24. </content>
  25. <author>
  26. <name>The youtube-dl maintainers</name>
  27. </author>
  28. <updated>@TIMESTAMP@</updated>
  29. </entry>
  30. """)
  31. now = datetime.datetime.now()
  32. now_iso = now.isoformat() + 'Z'
  33. atom_template = atom_template.replace('@TIMESTAMP@', now_iso)
  34. versions_info = json.load(open('update/versions.json'))
  35. versions = list(versions_info['versions'].keys())
  36. versions.sort()
  37. entries = []
  38. for v in versions:
  39. fields = v.split('.')
  40. year, month, day = map(int, fields[:3])
  41. faked = 0
  42. patchlevel = 0
  43. while True:
  44. try:
  45. datetime.date(year, month, day)
  46. except ValueError:
  47. day -= 1
  48. faked += 1
  49. assert day > 0
  50. continue
  51. break
  52. if len(fields) >= 4:
  53. try:
  54. patchlevel = int(fields[3])
  55. except ValueError:
  56. patchlevel = 1
  57. timestamp = '%04d-%02d-%02dT00:%02d:%02dZ' % (year, month, day, faked, patchlevel)
  58. entry = entry_template.replace('@TIMESTAMP@', timestamp)
  59. entry = entry.replace('@VERSION@', v)
  60. entries.append(entry)
  61. entries_str = textwrap.indent(''.join(entries), '\t')
  62. atom_template = atom_template.replace('@ENTRIES@', entries_str)
  63. with io.open('update/releases.atom', 'w', encoding='utf-8') as atom_file:
  64. atom_file.write(atom_template)