cliox.py 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. '''
  2. Copyright <2020> Alejandro "alkeon" Castilla <alkeon@autistici.org>
  3. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
  4. The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
  5. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
  6. '''
  7. import requests
  8. import sys
  9. links = []
  10. search_url = ""
  11. avoid_get_download_link = False
  12. selection_flag = ""
  13. def term_options():
  14. selection_flag = ""
  15. avoid_get_download_link = False
  16. list_videos = False
  17. if(len(sys.argv) == 3):
  18. if(sys.argv[1] == "-c"):
  19. search_url = sys.argv[2]
  20. selection_flag = "-c"
  21. avoid_get_download_link = True
  22. elif(sys.argv[1] == "-u"):
  23. search_url = sys.argv[2]
  24. selection_flag = "-u"
  25. avoid_get_download_link = True
  26. elif(sys.argv[1] == "-l"):
  27. search_url = sys.argv[2]
  28. list_videos = True
  29. else:
  30. search_url = sys.argv[1]
  31. return search_url, selection_flag, avoid_get_download_link, list_videos
  32. def print_array():
  33. i = 0
  34. while(i < len(links)):
  35. print(str(i) + ".- " + links[i])
  36. i += 1
  37. def get_link(line):
  38. first_quote = line.find("\"")
  39. second_quote = line.find("\"", first_quote + 1)
  40. url = line[first_quote + 1:second_quote]
  41. if(url not in links and url.find("#comments") == -1 and url.find("?autoplay=true") == -1):
  42. links.append(url)
  43. def search(search, selection_flag):
  44. base_url_programs = "https://www.ivoox.com/SEARCH_sw_1_1.html"
  45. base_url_users = "https://www.ivoox.com/SEARCH_sw_5_1.html"
  46. base_url_selected = "https://www.ivoox.com/SEARCH_sb.html"
  47. if(selection_flag == "-c"):
  48. base_url_selected = base_url_programs
  49. elif(selection_flag == "-u"):
  50. base_url_selected = base_url_users
  51. search = search.replace(" ", "-")
  52. url_search = base_url_selected.replace("SEARCH", search)
  53. p = requests.get(url_search)
  54. lines = p.text.splitlines()
  55. for line in lines:
  56. if(line.find("href=\"") != -1):
  57. if(line.find("audios-mp3") != -1):
  58. get_link(line)
  59. elif(line.find("_sq_") != -1):
  60. get_link(line)
  61. elif(line.find("_aj_") != -1):
  62. get_link(line)
  63. def get_download_link(url):
  64. base_url_download = "http://www.ivoox.com/listen_mn_ID_1.mp3?internal=HTML5"
  65. first_quote = url.find("_rf_")
  66. second_quote = url.find("_", first_quote + 5)
  67. id_url = url[first_quote + 4:second_quote]
  68. print(id_url)
  69. url_download = base_url_download.replace("ID", id_url)
  70. p = requests.get(url_download)
  71. print(p.url)
  72. def list_videos_from_channel(search_url):
  73. p = requests.get(search_url)
  74. lines = p.text.splitlines()
  75. for line in lines:
  76. if(line.find("href=\"") != -1):
  77. if(line.find("escuchar-audios") != -1):
  78. get_link(line)
  79. p = requests.get(links[0])
  80. lines = p.text.splitlines()
  81. for line in lines:
  82. if(line.find("href=\"") != -1):
  83. if(line.find("audios-mp3") != -1):
  84. get_link(line)
  85. if(sys.argv[1] == '-h' or sys.argv[1] == '--help'):
  86. print(" cliox \"keyword\" | Allows searching audios");
  87. print(" cliox -c \"channel\" | Allows searching channels ");
  88. print(" cliox -u \"user\" | Allows searching users ");
  89. print(" cliox -l \"channel/user url\" | Allows listing all videos from channel or user ");
  90. print(" cliox -h | Show help ");
  91. else:
  92. search_url, selection_flag, avoid_get_download_link, list_videos = term_options()
  93. print(search_url)
  94. if(not list_videos):
  95. search(search_url, selection_flag)
  96. print_array()
  97. if(not avoid_get_download_link):
  98. i = input("Choose a link\n")
  99. if(i != -1):
  100. get_download_link(links[int(i)])
  101. else:
  102. list_videos_from_channel(search_url)
  103. print_array()
  104. if(not avoid_get_download_link):
  105. i = input("Choose a link\n")
  106. if(i != -1):
  107. get_download_link(links[int(i)])