Skip to content

Commit ca16545

Browse files
committed
fixed #447, fixed #449, fixes livestream, yt music
1 parent 1bd54a7 commit ca16545

File tree

5 files changed

+56
-31
lines changed

5 files changed

+56
-31
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,6 @@ Simple program to increase YouTube views written in Python. Works with live stre
160160
# YouTube Music
161161
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.
162162

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

165164
# Fast VPS with Unlimited Traffic
166165
*[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*
@@ -253,6 +252,7 @@ Simple program to increase YouTube views written in Python. Works with live stre
253252
To get the most out of this script you should maintain these things.
254253
* Don't use HEADLESS mode. Because no IP leak prevention, fingerprint defending, etc. can be done in headless mode.
255254
* 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.
255+
* 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.
256256
* Use both [urls.txt](https://github.com/MShawon/YouTube-Viewer#urls) and [search.txt](https://github.com/MShawon/YouTube-Viewer#search)
257257
* 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.
258258

requirements.txt

-12 Bytes
Binary file not shown.

youtube_viewer.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@
4646
log = logging.getLogger('werkzeug')
4747
log.disabled = True
4848

49-
SCRIPT_VERSION = '1.7.5'
49+
SCRIPT_VERSION = '1.7.6'
5050

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

325325
features(driver)
326326

327-
view_stat = WebDriverWait(driver, 30).until(
328-
EC.presence_of_element_located((By.CSS_SELECTOR, '#count span'))).text
327+
try:
328+
view_stat = WebDriverWait(driver, 30).until(
329+
EC.presence_of_element_located((By.CSS_SELECTOR, '#count span'))).text
330+
if not view_stat:
331+
raise WebDriverException
332+
except WebDriverException:
333+
view_stat = driver.find_element(
334+
By.XPATH, '//*[@id="info"]/span[1]').text
329335

330336
return view_stat
331337

332338

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

344350
bypass_popup(driver)
345351

346352
play_music(driver)
347353

354+
output = driver.find_element(
355+
By.XPATH, '//ytmusic-player-bar//yt-formatted-string').text
348356
view_stat = 'music'
349-
return view_stat
357+
358+
return view_stat, output
350359

351360

352361
def spoof_geolocation(proxy_type, proxy, driver):
@@ -412,8 +421,11 @@ def control_player(driver, output, position, proxy, youtube, collect_id=True):
412421
except Exception:
413422
pass
414423

415-
current_channel = driver.find_element(
416-
By.CSS_SELECTOR, '#upload-info a').text
424+
try:
425+
current_channel = driver.find_element(
426+
By.CSS_SELECTOR, '#upload-info a').text
427+
except WebDriverException:
428+
current_channel = 'Unknown'
417429

418430
error = 0
419431
loop = int(video_len/4)
@@ -459,8 +471,14 @@ def control_player(driver, output, position, proxy, youtube, collect_id=True):
459471
def youtube_live(proxy, position, driver, output):
460472
error = 0
461473
while True:
462-
view_stat = driver.find_element(
463-
By.CSS_SELECTOR, '#count span').text
474+
try:
475+
view_stat = driver.find_element(
476+
By.CSS_SELECTOR, '#count span').text
477+
if not view_stat:
478+
raise WebDriverException
479+
except WebDriverException:
480+
view_stat = driver.find_element(
481+
By.XPATH, '//*[@id="info"]/span[1]').text
464482
if 'watching' in view_stat:
465483
print(timestamp() + bcolors.OKBLUE + f"Worker {position} | " + bcolors.OKGREEN +
466484
f"{proxy} | {output} | " + bcolors.OKCYAN + f"{view_stat} " + bcolors.ENDC)
@@ -504,7 +522,7 @@ def music_and_video(proxy, position, youtube, driver, output, view_stat):
504522
output = play_next_video(driver, suggested)
505523
except WebDriverException as e:
506524
raise Exception(
507-
f'Error suggested | {type(e).__name__} | {e.args[0]}')
525+
f"Error suggested | {type(e).__name__} | {e.args[0] if e.args else ''}")
508526

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

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

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

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

716734
except Exception as e:
735+
status = quit_driver(driver=driver, data_dir=data_dir)
736+
717737
print(timestamp() + bcolors.FAIL +
718-
f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0]}" + bcolors.ENDC)
738+
f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0] if e.args else ''}" + bcolors.ENDC)
719739

720740
create_html(
721-
{"#f14c4c": f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0]}"})
722-
723-
status = quit_driver(driver=driver, data_dir=data_dir)
741+
{"#f14c4c": f"Worker {position} | Line : {e.__traceback__.tb_lineno} | {type(e).__name__} | {e.args[0] if e.args else ''}"})
724742

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

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

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

742760

743761
def get_proxy_list():

youtubeviewer/bypass.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,3 +109,9 @@ def bypass_other_popup(driver):
109109
By.XPATH, f"//*[@id='button' and @aria-label='{popup}']").click()
110110
except WebDriverException:
111111
pass
112+
113+
try:
114+
driver.find_element(
115+
By.XPATH, '//*[@id="dismiss-button"]/yt-button-shape/button').click()
116+
except WebDriverException:
117+
pass

youtubeviewer/features.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -110,14 +110,15 @@ def random_command(driver):
110110
driver.execute_script(
111111
'document.querySelector("#movie_player").scrollIntoViewIfNeeded();')
112112
elif command == 'share':
113-
driver.find_element(
114-
By.XPATH, "//button[@id='button' and @aria-label='Share']").click()
115-
sleep(uniform(2, 5))
116-
if randint(1, 2) == 1:
117-
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
118-
(By.XPATH, "//*[@id='button' and @aria-label='Copy']"))).click()
119-
driver.find_element(
120-
By.XPATH, "//*[@id='close-button']/button[@aria-label='Cancel']").click()
113+
if choices([1, 2], cum_weights=(0.9, 1.00), k=1)[0] == 2:
114+
driver.find_element(
115+
By.XPATH, "//button[@id='button' and @aria-label='Share']").click()
116+
sleep(uniform(2, 5))
117+
if randint(1, 2) == 1:
118+
WebDriverWait(driver, 10).until(EC.element_to_be_clickable(
119+
(By.XPATH, "//*[@id='button' and @aria-label='Copy']"))).click()
120+
driver.find_element(
121+
By.XPATH, "//*[@id='close-button']/button[@aria-label='Cancel']").click()
121122
else:
122123
driver.find_element(By.ID,
123124
'movie_player').send_keys(command*randint(1, 5))
@@ -154,7 +155,7 @@ def play_next_video(driver, suggested):
154155
'spellcheck="false" href="/watch?v={video_id}&t=0s" ' +
155156
'dir="auto">https://www.youtube.com/watch?v={video_id}</a><br>'
156157
157-
var element = document.querySelector("#description > ytd-text-inline-expander > yt-formatted-string");
158+
var element = document.querySelector("#description-inline-expander > yt-formatted-string");
158159
159160
element.insertAdjacentHTML( 'afterbegin', html );
160161
'''

0 commit comments

Comments
 (0)