Skip to content

Commit

Permalink
fixed #447, fixed #449, fixes livestream, yt music
Browse files Browse the repository at this point in the history
  • Loading branch information
MShawon committed Nov 4, 2022
1 parent 1bd54a7 commit ca16545
Show file tree
Hide file tree
Showing 5 changed files with 56 additions and 31 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,6 @@ Simple program to increase YouTube views written in Python. Works with live stre
# YouTube Music
Can generate views on YouTube Music too. In **urls.txt** put your music link like this `https://music.youtube.com/watch?v=xxxxx`. Script will automatically load YouTube Music when it sees link have `music.youtube.com`. **Search feature is not available for this.** So you need to empty the search.txt otherwise it will start searching videos in default YouTube.

For YouTube Music use version 1.6.2 or earlier until the bug is fixed in the latest releases.

# Fast VPS with Unlimited Traffic
*[PetroSky](https://petrosky.io/mshawon) is one of the various CloudHosting services with the fastest and most convenient cloud technology. Their servers are powered by the latest **AMD RYZEN/EPYC CPUs** with High-Performance **NVMe SSD Hard Drives** that will let your application run faster than ever. You can get 2 vCPU with 4 GB ECC RAM for as low as 11.99€/month which will work very well for YouTube-Viewer script for 2 threads. Visit [PetroSky](https://petrosky.io/mshawon) to get the fastest VPS with unlimited traffic at the lowest price. Use this code `mshawon25` to get **25% discount** on your purchase*
Expand Down Expand Up @@ -253,6 +252,7 @@ Simple program to increase YouTube views written in Python. Works with live stre
To get the most out of this script you should maintain these things.
* Don't use HEADLESS mode. Because no IP leak prevention, fingerprint defending, etc. can be done in headless mode.
* Youtube doesn't count views from the same IP after a certain time. Like, don't expect to get 100 views from 10 proxies. If you want more views, try to use a lot of premium proxies(free proxies are flagged by most websites). DO NOT use TOR proxies.
* It seems Rotating proxy gives the best result. But the IP MUST NOT change on each request. Set the sticky session or TTL to 5 to 15 minutes.
* Use both [urls.txt](https://github.com/MShawon/YouTube-Viewer#urls) and [search.txt](https://github.com/MShawon/YouTube-Viewer#search)
* And use as many [urls](https://github.com/MShawon/YouTube-Viewer#urls) and [keyword::::title](https://github.com/MShawon/YouTube-Viewer#search) as you can. Don't use just one video.
Expand Down
Binary file modified requirements.txt
Binary file not shown.
60 changes: 39 additions & 21 deletions youtube_viewer.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
log = logging.getLogger('werkzeug')
log.disabled = True

SCRIPT_VERSION = '1.7.5'
SCRIPT_VERSION = '1.7.6'

print(bcolors.OKGREEN + """
Expand Down Expand Up @@ -320,33 +320,42 @@ def youtube_normal(method, keyword, video_title, driver, output):
(By.ID, 'movie_player')))
except WebDriverException:
raise Exception(
"Slow internet speed or Stuck at recaptcha! Can't load YouTube...")
"Slow internet speed or Stuck at reCAPTCHA! Can't load YouTube...")

features(driver)

view_stat = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#count span'))).text
try:
view_stat = WebDriverWait(driver, 30).until(
EC.presence_of_element_located((By.CSS_SELECTOR, '#count span'))).text
if not view_stat:
raise WebDriverException
except WebDriverException:
view_stat = driver.find_element(
By.XPATH, '//*[@id="info"]/span[1]').text

return view_stat


def youtube_music(driver):
if 'coming-soon' in driver.current_url:
if 'coming-soon' in driver.title or 'not available' in driver.title:
raise Exception(
"YouTube Music is not available in your area!")
try:
WebDriverWait(driver, 10).until(EC.visibility_of_element_located(
(By.XPATH, '//*[@id="player-page"]')))
except WebDriverException:
raise Exception(
"Slow internet speed or Stuck at recaptcha! Can't load YouTube...")
"Slow internet speed or Stuck at reCAPTCHA! Can't load YouTube...")

bypass_popup(driver)

play_music(driver)

output = driver.find_element(
By.XPATH, '//ytmusic-player-bar//yt-formatted-string').text
view_stat = 'music'
return view_stat

return view_stat, output


def spoof_geolocation(proxy_type, proxy, driver):
Expand Down Expand Up @@ -412,8 +421,11 @@ def control_player(driver, output, position, proxy, youtube, collect_id=True):
except Exception:
pass

current_channel = driver.find_element(
By.CSS_SELECTOR, '#upload-info a').text
try:
current_channel = driver.find_element(
By.CSS_SELECTOR, '#upload-info a').text
except WebDriverException:
current_channel = 'Unknown'

error = 0
loop = int(video_len/4)
Expand Down Expand Up @@ -459,8 +471,14 @@ def control_player(driver, output, position, proxy, youtube, collect_id=True):
def youtube_live(proxy, position, driver, output):
error = 0
while True:
view_stat = driver.find_element(
By.CSS_SELECTOR, '#count span').text
try:
view_stat = driver.find_element(
By.CSS_SELECTOR, '#count span').text
if not view_stat:
raise WebDriverException
except WebDriverException:
view_stat = driver.find_element(
By.XPATH, '//*[@id="info"]/span[1]').text
if 'watching' in view_stat:
print(timestamp() + bcolors.OKBLUE + f"Worker {position} | " + bcolors.OKGREEN +
f"{proxy} | {output} | " + bcolors.OKCYAN + f"{view_stat} " + bcolors.ENDC)
Expand Down Expand Up @@ -504,7 +522,7 @@ def music_and_video(proxy, position, youtube, driver, output, view_stat):
output = play_next_video(driver, suggested)
except WebDriverException as e:
raise Exception(
f'Error suggested | {type(e).__name__} | {e.args[0]}')
f"Error suggested | {type(e).__name__} | {e.args[0] if e.args else ''}")

print(timestamp() + bcolors.OKBLUE +
f"Worker {position} | Found next suggested video : [{output}]" + bcolors.ENDC)
Expand Down Expand Up @@ -535,7 +553,7 @@ def channel_or_endscreen(proxy, position, youtube, driver, view_stat, current_ur
driver, current_channel)
except WebDriverException as e:
raise Exception(
f'Error channel | {type(e).__name__} | {e.args[0]}')
f"Error channel | {type(e).__name__} | {e.args[0] if e.args else ''}")

print(timestamp() + bcolors.OKBLUE +
f"Worker {position} | {log}" + bcolors.ENDC)
Expand All @@ -547,7 +565,7 @@ def channel_or_endscreen(proxy, position, youtube, driver, view_stat, current_ur
output = play_end_screen_video(driver)
except WebDriverException as e:
raise Exception(
f'Error end screen | {type(e).__name__} | {e.args[0]}')
f"Error end screen | {type(e).__name__} | {e.args[0] if e.args else ''}")

print(timestamp() + bcolors.OKBLUE +
f"Worker {position} | Video played from end screen : [{output}]" + bcolors.ENDC)
Expand Down Expand Up @@ -693,7 +711,7 @@ def main_viewer(proxy_type, proxy, position):
view_stat = youtube_normal(
method, keyword, video_title, driver, output)
else:
view_stat = youtube_music(driver)
view_stat, output = youtube_music(driver)

if 'watching' in view_stat:
youtube_live(proxy, position, driver, output)
Expand All @@ -714,13 +732,13 @@ def main_viewer(proxy_type, proxy, position):
status = quit_driver(driver=driver, data_dir=data_dir)

except Exception as e:
status = quit_driver(driver=driver, data_dir=data_dir)

print(timestamp() + bcolors.FAIL +
f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0]}" + bcolors.ENDC)
f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0] if e.args else ''}" + bcolors.ENDC)

create_html(
{"#f14c4c": f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0]}"})

status = quit_driver(driver=driver, data_dir=data_dir)
{"#f14c4c": f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0] if e.args else ''}"})

except RequestException:
print(timestamp() + bcolors.OKBLUE + f"Worker {position} | " +
Expand All @@ -734,10 +752,10 @@ def main_viewer(proxy_type, proxy, position):

except Exception as e:
print(timestamp() + bcolors.FAIL +
f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0]}" + bcolors.ENDC)
f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0] if e.args else ''}" + bcolors.ENDC)

create_html(
{"#f14c4c": f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0]}"})
{"#f14c4c": f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0] if e.args else ''}"})


def get_proxy_list():
Expand Down
6 changes: 6 additions & 0 deletions youtubeviewer/bypass.py
Original file line number Diff line number Diff line change
Expand Up @@ -109,3 +109,9 @@ def bypass_other_popup(driver):
By.XPATH, f"//*[@id='button' and @aria-label='{popup}']").click()
except WebDriverException:
pass

try:
driver.find_element(
By.XPATH, '//*[@id="dismiss-button"]/yt-button-shape/button').click()
except WebDriverException:
pass
19 changes: 10 additions & 9 deletions youtubeviewer/features.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,14 +110,15 @@ def random_command(driver):
driver.execute_script(
'document.querySelector("#movie_player").scrollIntoViewIfNeeded();')
elif command == 'share':
driver.find_element(
By.XPATH, "//button[@id='button' and @aria-label='Share']").click()
sleep(uniform(2, 5))
if randint(1, 2) == 1:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
(By.XPATH, "//*[@id='button' and @aria-label='Copy']"))).click()
driver.find_element(
By.XPATH, "//*[@id='close-button']/button[@aria-label='Cancel']").click()
if choices([1, 2], cum_weights=(0.9, 1.00), k=1)[0] == 2:
driver.find_element(
By.XPATH, "//button[@id='button' and @aria-label='Share']").click()
sleep(uniform(2, 5))
if randint(1, 2) == 1:
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
(By.XPATH, "//*[@id='button' and @aria-label='Copy']"))).click()
driver.find_element(
By.XPATH, "//*[@id='close-button']/button[@aria-label='Cancel']").click()
else:
driver.find_element(By.ID,
'movie_player').send_keys(command*randint(1, 5))
Expand Down Expand Up @@ -154,7 +155,7 @@ def play_next_video(driver, suggested):
'spellcheck="false" href="/watch?v={video_id}&t=0s" ' +
'dir="auto">https://www.youtube.com/watch?v={video_id}</a><br>'
var element = document.querySelector("#description > ytd-text-inline-expander > yt-formatted-string");
var element = document.querySelector("#description-inline-expander > yt-formatted-string");
element.insertAdjacentHTML( 'afterbegin', html );
'''
Expand Down

0 comments on commit ca16545

Please sign in to comment.