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.

118 lines
3.4 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. ######################
  45. def getCategory(category, type):
  46. if type == "youtube":
  47. return YOUTUBE_CATEGORY[category.lower()]
  48. else:
  49. return PEERTUBE_CATEGORY[category.lower()]
  50. # return the nfo as a RawConfigParser object
  51. def loadNFO(options):
  52. video_directory = dirname(options.get('--file')) +"/"
  53. if options.get('--nfo'):
  54. try:
  55. print "Using " + options.get('--nfo') + " as NFO, loading..."
  56. if isfile(options.get('--nfo')):
  57. nfo = RawConfigParser()
  58. nfo.read(options.get('--nfo'))
  59. return nfo
  60. else:
  61. exit("Given NFO file does not exist, please check your path.")
  62. except Exception as e:
  63. exit("Problem with NFO file: " + str(e))
  64. else:
  65. if options.get('--name'):
  66. nfo_file = video_directory + options.get('--name') + ".txt"
  67. print nfo_file
  68. if isfile(nfo_file):
  69. try:
  70. print "Using " + nfo_file + " as NFO, loading..."
  71. nfo = RawConfigParser()
  72. nfo.read(nfo_file)
  73. return nfo
  74. except Exception as e:
  75. exit("Problem with NFO file: " + str(e))
  76. # if --nfo and --name does not exist, use --file as default
  77. video_file = splitext(basename(options.get('--file')))[0]
  78. nfo_file = video_directory + video_file + ".txt"
  79. if isfile(nfo_file):
  80. try:
  81. print "Using " + nfo_file + " as NFO, loading..."
  82. nfo = RawConfigParser()
  83. nfo.read(nfo_file)
  84. return nfo
  85. except Exception as e:
  86. exit("Problem with nfo file: " + str(e))
  87. print "No suitable NFO found, skipping."
  88. return False
  89. def parseNFO(options):
  90. nfo = loadNFO(options)
  91. if nfo:
  92. # We need to check all options and replace it with the nfo value if not defined (None or False)
  93. for key, value in options.iteritems():
  94. key = key.replace("-", "")
  95. try:
  96. # get string options
  97. if value is None and nfo.get('video', key):
  98. options['--' + key] = nfo.get('video', key)
  99. # get boolean options
  100. elif value is False and nfo.getboolean('video', key):
  101. options['--' + key] = nfo.getboolean('video', key)
  102. except NoOptionError:
  103. continue
  104. except NoSectionError:
  105. exit("Given NFO file miss section [video], please check syntax of your NFO.")
  106. return options