Guest User

Untitled

a guest
Nov 30th, 2022
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. (download.sh)
  2.  
  3. #!/bin/bash
  4. yt-dlp --skip-download --write-auto-sub --sub-lang en --sub-format json3 -o '%(upload_date)s__%(id)s__%(title)s.%(ext)s' $@
  5.  
  6. ---
  7.  
  8. (convert.py)
  9.  
  10. #!/usr/bin/python3
  11.  
  12. import sys
  13. import json
  14.  
  15. def main():
  16. for arg in sys.argv[1:]:
  17. with open(arg, 'r') as f:
  18. js = json.loads(f.read())
  19. with open(arg + '.txt', 'w') as f:
  20. last_time = None
  21. line_started = False
  22. for ev in js['events']:
  23. time_ms = ev['tStartMs']
  24. time_s, time_ms = divmod(time_ms, 1000)
  25. time_m, time_s = divmod(time_s, 60)
  26. time_h, time_m = divmod(time_m, 60)
  27. if 'segs' not in ev: continue
  28. for seg in ev['segs']:
  29. text = seg['utf8']
  30. if text == '\n':
  31. f.write('\n')
  32. line_started = False
  33. continue
  34. if not line_started:
  35. f.write(f'{time_h}:{time_m:02}:{time_s:02} ::')
  36. line_started = True
  37. f.write(' ' + text.strip())
  38. f.write('\n')
  39.  
  40. if __name__ == '__main__':
  41. main()
  42.  
  43. ---
  44.  
  45. $ ./download.sh https://www.youtube.com/channel/CHANNEL-ID-GOES-HERE/streams
  46.  
  47. $ ./convert.py *.json3
  48.  
  49. $ grep -n *.txt -A6 -B6 -iPe 'peony|penny|pennie' | less -i
Advertisement
Add Comment
Please, Sign In to add comment