Welcome, guest | Sign In | My Account | Store | Cart
#!/usr/bin/python3

# Name: youParse.py
# Author: pantuts
# Email: pantuts@gmail.com
# Description: Parse URLs in Youtube User's Playlist (Video Playlist not Favorites)
# Use python3 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: python3 youParse.py youtubeURLhere

import re
import urllib.request
import sys

def crawl(url):
    sTUBE = ''
    cPL = ''
    tmp = 0
    amp = 0
    if 'PL' in url:
        tmp = url.index('L') + 1
        cPL = url[tmp:]
        if '&' in url:
            amp = url.index('&')
            cPL = url[tmp:amp]
            
    else:
        print('Incorrect Playlist.\nSample playlist at the end of url: PL1894B2B763FBC580')
        exit(1)
    
    try:
        yTUBE = urllib.request.urlopen(url).read()
        sTUBE = str(yTUBE)
    except urllib.error.URLError as e:
        print(e.reason)
    
    mat = re.findall(r'watch\S+list=PL+' + cPL, sTUBE)
    
    if mat:
        if mat[0] == mat[1]:
            mat.remove(mat[0]) #if there is duplicate, remove
            
        # print('Videos in Playlist: ' + str(len(mat)))
        for PL in mat:
            yPL = str(PL)
            if '&' in yPL:
                yPL_amp = yPL.index('&')
            print('[+] http://www.youtube.com/' + yPL[:yPL_amp])
    else:
        print('No videos found.')
        exit(1)
        
if len(sys.argv) < 2 or len(sys.argv) > 2:
    print('USAGE: python3 youParse.py YOUTUBEurl')
    exit(1)
    
else:
    url = sys.argv[1]
    if 'http' not in url:
        url = 'http://' + url
    print('Extracting...')
    crawl(url)

Diff to Previous Revision

--- revision 8 2012-10-15 16:42:43
+++ revision 9 2012-10-17 05:25:56
@@ -34,7 +34,7 @@
         yTUBE = urllib.request.urlopen(url).read()
         sTUBE = str(yTUBE)
     except urllib.error.URLError as e:
-        print(e)
+        print(e.reason)
     
     mat = re.findall(r'watch\S+list=PL+' + cPL, sTUBE)
     

History