Skip to content

Instantly share code, notes, and snippets.

@Evolution0
Last active October 27, 2016 12:04
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Evolution0/5fd0d4c2dd98eb53eee96d2466662e69 to your computer and use it in GitHub Desktop.
Save Evolution0/5fd0d4c2dd98eb53eee96d2466662e69 to your computer and use it in GitHub Desktop.
Credits to: @pantuts for the original script "youParse.py"original took about 6 seconds to grab all 100 urls, this version requires less than 2 generally.
# Name: asyncParse.py
# Version: 1.0
# Author: Evolution0
# Email: xxanthonykanexx@gmail.com
# Description: Parse URLs in Youtube User's Playlist (Video Playlist not Favorites)
# Use python 3.5 and later
# Agreement: You can use, modify, or redistribute this tool under
# the terms of GNU General Public License (GPLv3).
# This tool is for educational purposes only. Any damage you make will not affect the author.
# Usage: python asyncParse.py youtubeURLhere
import aiohttp
import asyncio
import re
import sys
async def fetch(session, url):
with aiohttp.Timeout(10):
async with session.get(url) as response:
return await response.text()
if len(sys.argv) < 2 or len(sys.argv) > 2:
print('USAGE: python asyncParse.py YOUTUBEurl')
exit(1)
else:
url = sys.argv[1]
if 'http' not in url:
url = 'http://' + url
if __name__ == '__main__':
loop = asyncio.get_event_loop()
with aiohttp.ClientSession(loop=loop) as session:
html = loop.run_until_complete(fetch(session, url))
final_url = []
if 'list=' in url:
eq = url.rfind('=') + 1
c_pl = url[eq:]
else:
print('Incorrect Playlist.')
exit(1)
tmp_mat = re.compile(r'watch\?v=\S+?list=' + c_pl)
mat = re.findall(tmp_mat, html)
if mat:
for pl in mat:
y_pl = str(pl)
if '&' in y_pl:
y_pl_amp = y_pl.index('&')
final_url.append('http://www.youtube.com/' + y_pl[:y_pl_amp])
all_url = list(set(final_url))
for item in all_url:
print(item)
else:
print('No videos found.')
exit(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment