A bot written in Python3 that mirrors YouTube channels to PeerTube channels as videos are released in a YouTube channel.
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.

95 lines
2.5KB

  1. import toml
  2. def read_conf(conf_file):
  3. conf_file = open(conf_file)
  4. conf = conf_file.read()
  5. conf = toml.loads(conf)
  6. conf_file.close()
  7. return conf
  8. def convert_timestamp(timestamp):
  9. timestamp = timestamp.split('T')
  10. date = timestamp[0].split('-')
  11. time = timestamp[1].split('+')
  12. time = time[0].split(':')
  13. timestamp = int(date[0] + date[1] + date[2] + time[0] + time[1] + time[2])
  14. return timestamp
  15. def set_pt_lang(yt_lang, conf_lang):
  16. YOUTUBE_LANGUAGE = {
  17. "arabic": 'ar',
  18. "english": 'en',
  19. "french": 'fr',
  20. "german": 'de',
  21. "hindi": 'hi',
  22. "italian": 'it',
  23. "japanese": 'ja',
  24. "korean": 'ko',
  25. "mandarin": 'zh-CN',
  26. "portuguese": 'pt-PT',
  27. "punjabi": 'pa',
  28. "russian": 'ru',
  29. "spanish": 'es'
  30. }
  31. PEERTUBE_LANGUAGE = {
  32. "arabic": "ar",
  33. "english": "en",
  34. "french": "fr",
  35. "german": "de",
  36. "hindi": "hi",
  37. "italian": "it",
  38. "japanese": "ja",
  39. "korean": "ko",
  40. "mandarin": "zh",
  41. "portuguese": "pt",
  42. "punjabi": "pa",
  43. "russian": "ru",
  44. "spanish": "es"
  45. }
  46. # if youtube provides a language value
  47. if yt_lang != None:
  48. # if the language value is a value and not a key
  49. if len((yt_lang).split("-")[0]) < 3:
  50. key_list = list(YOUTUBE_LANGUAGE.keys())
  51. val_list =list(YOUTUBE_LANGUAGE.values())
  52. yt_lang = key_list[val_list.index(yt_lang)]
  53. else:
  54. pass
  55. # now set the language to the peertube value using the key
  56. try:
  57. lang = PEERTUBE_LANGUAGE[yt_lang]
  58. except:
  59. # in the event that no key exists for the youtube language, use the conf value
  60. if len(conf_lang) > 2:
  61. conf_lang = PEERTUBE_LANGUAGE[conf_lang]
  62. lang = conf_lang
  63. else:
  64. if len(conf_lang) > 2:
  65. conf_lang = PEERTUBE_LANGUAGE[conf_lang]
  66. lang = conf_lang
  67. return lang
  68. def set_pt_category(category_str):
  69. print(category_str)
  70. PEERTUBE_CATEGORY = {
  71. "music": 1,
  72. "films": 2,
  73. "vehicles": 3,
  74. "sport": 5,
  75. "travels": 6,
  76. "gaming": 7,
  77. "people": 8,
  78. "comedy": 9,
  79. "entertainment": 10,
  80. "news": 11,
  81. "how to": 12,
  82. "education": 13,
  83. "activism": 14,
  84. "science & technology": 15,
  85. "science": 15,
  86. "technology": 15,
  87. "animals": 16
  88. }
  89. category = str(PEERTUBE_CATEGORY[category_str])
  90. return category