Scripting way to upload videos to peertube and youtube
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.

156 lines
4.2 KiB

  1. #!/usr/bin/python
  2. # coding: utf-8
  3. from ConfigParser import RawConfigParser, NoOptionError, NoSectionError
  4. from os.path import dirname, splitext, basename, isfile
  5. ### CATEGORIES ###
  6. YOUTUBE_CATEGORY = {
  7. "music": 10,
  8. "films": 1,
  9. "vehicles": 2,
  10. "sport": 17,
  11. "travels": 19,
  12. "gaming": 20,
  13. "people": 22,
  14. "comedy": 23,
  15. "entertainment": 24,
  16. "news": 25,
  17. "how to": 26,
  18. "education": 27,
  19. "activism": 29,
  20. "science & technology": 28,
  21. "science": 28,
  22. "technology": 28,
  23. "animals": 15
  24. }
  25. PEERTUBE_CATEGORY = {
  26. "music": 1,
  27. "films": 2,
  28. "vehicles": 3,
  29. "sport": 5,
  30. "travels": 6,
  31. "gaming": 7,
  32. "people": 8,
  33. "comedy": 9,
  34. "entertainment": 10,
  35. "news": 11,
  36. "how to": 12,
  37. "education": 13,
  38. "activism": 14,
  39. "science & technology": 15,
  40. "science": 15,
  41. "technology": 15,
  42. "animals": 16
  43. }
  44. ### LANGUAGES ###
  45. YOUTUBE_LANGUAGE = {
  46. "arabic": 'ar',
  47. "english": 'en',
  48. "french": 'fr',
  49. "german": 'de',
  50. "hindi": 'hi',
  51. "italian": 'it',
  52. "japanese": 'ja',
  53. "korean": 'ko',
  54. "mandarin": 'zh-CN',
  55. "portuguese": 'pt-PT',
  56. "punjabi": 'pa',
  57. "russian": 'ru',
  58. "spanish": 'es'
  59. }
  60. PEERTUBE_LANGUAGE = {
  61. "arabic": 5,
  62. "english": 1,
  63. "french": 13,
  64. "german": 11,
  65. "hindi": 4,
  66. "italian": 14,
  67. "japanese": 9,
  68. "korean": 12,
  69. "mandarin": 3,
  70. "portuguese": 6,
  71. "punjabi": 10,
  72. "russian": 8,
  73. "spanish": 2
  74. }
  75. ######################
  76. def getCategory(category, platform):
  77. if platform == "youtube":
  78. return YOUTUBE_CATEGORY[category.lower()]
  79. else:
  80. return PEERTUBE_CATEGORY[category.lower()]
  81. def getLanguage(language, platform):
  82. if platform == "youtube":
  83. return YOUTUBE_LANGUAGE[language.lower()]
  84. else:
  85. return PEERTUBE_LANGUAGE[language.lower()]
  86. # return the nfo as a RawConfigParser object
  87. def loadNFO(options):
  88. video_directory = dirname(options.get('--file')) + "/"
  89. if options.get('--nfo'):
  90. try:
  91. print "Using " + options.get('--nfo') + " as NFO, loading..."
  92. if isfile(options.get('--nfo')):
  93. nfo = RawConfigParser()
  94. nfo.read(options.get('--nfo'))
  95. return nfo
  96. else:
  97. exit("Given NFO file does not exist, please check your path.")
  98. except Exception as e:
  99. exit("Problem with NFO file: " + str(e))
  100. else:
  101. if options.get('--name'):
  102. nfo_file = video_directory + options.get('--name') + ".txt"
  103. print nfo_file
  104. if isfile(nfo_file):
  105. try:
  106. print "Using " + nfo_file + " as NFO, loading..."
  107. nfo = RawConfigParser()
  108. nfo.read(nfo_file)
  109. return nfo
  110. except Exception as e:
  111. exit("Problem with NFO file: " + str(e))
  112. # if --nfo and --name does not exist, use --file as default
  113. video_file = splitext(basename(options.get('--file')))[0]
  114. nfo_file = video_directory + video_file + ".txt"
  115. if isfile(nfo_file):
  116. try:
  117. print "Using " + nfo_file + " as NFO, loading..."
  118. nfo = RawConfigParser()
  119. nfo.read(nfo_file)
  120. return nfo
  121. except Exception as e:
  122. exit("Problem with nfo file: " + str(e))
  123. print "No suitable NFO found, skipping."
  124. return False
  125. def parseNFO(options):
  126. nfo = loadNFO(options)
  127. if nfo:
  128. # We need to check all options and replace it with the nfo value if not defined (None or False)
  129. for key, value in options.iteritems():
  130. key = key.replace("-", "")
  131. try:
  132. # get string options
  133. if value is None and nfo.get('video', key):
  134. options['--' + key] = nfo.get('video', key)
  135. # get boolean options
  136. elif value is False and nfo.getboolean('video', key):
  137. options['--' + key] = nfo.getboolean('video', key)
  138. except NoOptionError:
  139. continue
  140. except NoSectionError:
  141. exit("Given NFO file miss section [video], please check syntax of your NFO.")
  142. return options