A tool which can be used to search and play YouTube music!
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.
 
 

26 lines
808 B

  1. #!/usr/bin/python3
  2. from youtube_search import YoutubeSearch
  3. import sys, getopt
  4. def main(argv):
  5. inputfile = ''
  6. outputfile = ''
  7. try:
  8. opts, args = getopt.getopt(argv,"hi:o:",["ifile=","ofile="])
  9. except getopt.GetoptError:
  10. print ('spotitube.py -i <Search Keyword>')
  11. sys.exit(2)
  12. for opt, arg in opts:
  13. if opt == '-h':
  14. print ('test.py -i <inputfile> -o <outputfile>')
  15. sys.exit()
  16. elif opt in ("-i", "--ifile"):
  17. inputfile = arg
  18. elif opt in ("-o", "--ifile"):
  19. numberfile = arg
  20. results = YoutubeSearch(inputfile, max_results=int(numberfile)).to_dict()
  21. ans = 'https://youtu.be/' + results[int(numberfile)-1]['url_suffix'][9:]
  22. print(ans)
  23. if __name__ == "__main__":
  24. main(sys.argv[1:])