Youtube Playlist Download

Hi All,

I am just releasing a version of youtube playlist downloading tool and this tool depends on on youtube-d and pyqt.
Here is the source code and screen shoot .

Source


[Python]
#~ ///////////////////////////////////////////////////////////////////////////////
#~ //
#~ // Copyright (c) 2010-2011, Kurian OS
#~ // All rights reserved.
#~ //
#~ // Redistribution and use in source and binary forms, with or without
#~ // modification, are permitted provided that the following conditions
#~ // are met:
#~ //
#~ // Redistributions of source code must retain the above copyright
#~ // notice, this list of conditions and the following disclaimer.
#~ // Redistributions in binary form must reproduce the above copyright
#~ // notice, this list of conditions and the following disclaimer in the
#~ // documentation and/or other materials provided with the
#~ // distribution. Neither the name of Kurian Os nor the
#~ // names of its contributors may be used to endorse or promote
#~ // products derived from this software without specific prior written
#~ // permission.
#~ //
#~ // THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
#~ // “AS IS” AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
#~ // LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
#~ // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
#~ // COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
#~ // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
#~ // (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
#~ // SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
#~ // HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
#~ // STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
#~ // ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
#~ // OF THE POSSIBILITY OF SUCH DAMAGE.
#~ //
#~ ///////////////////////////////////////////////////////////////////////////////
__authors__ = [“kurian.os”]
__date__ = ‘$Date: Aug 7, 2011 12:00:00 PM$’.split()[1]
__copyright__ = ‘2011’
__license__ = “Copyright Kurian O.S”
__contact__ = “kurianos@gmail.com”
__status__ = “Release”

import os
import re
import sys
import time
import urllib
import urllib2
import commands
import subprocess

from PyQt4 import QtGui, QtCore, uic
YOU_Panel, YOU_Widget= uic.loadUiType(os.path.join(os.path.split(__file__)[0], “youtube.ui”))

class YOUTUBELISTVIEW(YOU_Widget,YOU_Panel):

def __init__(self,*args):
self.resourcePath = “%s/resource”%os.path.split(__file__)[0]
YOU_Widget.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)
self.setupUi(self)
self.setFocusPolicy(QtCore.Qt.StrongFocus)
self.setAttribute(QtCore.Qt.WA_QuitOnClose, True)
self.setWindowIcon(QtGui.QIcon(‘%s/video.png’%(self.resourcePath)))
self.connect(self.you_browse, QtCore.SIGNAL(‘clicked()’),self.loadDestinationfolder)
self.connect(self.you_get, QtCore.SIGNAL(‘clicked()’),self.fetchPlayList)
self.connect(self.you_down, QtCore.SIGNAL(‘clicked()’),self.listDownload)
self.show()

def loadDestinationfolder(self):
options = QtGui.QFileDialog.DontResolveSymlinks | QtGui.QFileDialog.ShowDirsOnly
fileName = QtGui.QFileDialog.getExistingDirectory(self, ‘*.*’, ‘ ‘, options)
self.you_dest.setText(fileName)

def fetchPlayList(self):
getPlayList=self.you_link.text()
getDestNation=self.you_browse.text()
if getPlayList == ” or getPlayList == ‘ ‘ or getPlayList == None or getDestNation == ” or getDestNation == ‘ ‘ or getDestNation == None:
QtGui.QMessageBox.critical(self, ‘Error!’, ‘Please enter a youtube playlist and destination folder path!’, QtGui.QMessageBox.Ok)
self.you_log.append(“Please enter a youtube playlist and destination folder path!”)
else:
self.openYouTubePlayList(str(getPlayList))

def openYouTubePlayList(self,playListURL):
getFile=urllib.urlopen(str(playListURL))
self.openYouTubeLink(playListURL)
try:
playListPages=[]
for eachLine in getFile:
if ‘pagerNotCurrent’ in eachLine:
playListCnt=eachLine.split(‘class=’)
playListCnt=playListCnt[0].strip()
playListPages.append(playListCnt[len(playListCnt)-2])
playListPages=self.removeDupList(playListPages)
for eachCnt in playListPages:
sendPlayListUrl=playListURL+’&page=%s’%eachCnt
self.openYouTubeLink(str(sendPlayListUrl))
except Exception,e:
self.you_log.append(str(e))

def openYouTubeLink(self,currentUrl):
getFile=urllib.urlopen(currentUrl)
orginalSourcePath=[]
for eachline in getFile:
try:
if ‘watch?v’ and “index=” in eachline:
if “href” in eachline:
youtube_video = eachline.split(” “)
youtube_video = filter(bool, youtube_video)
youtube_video=youtube_video[1][6:].split(“;”)[0]

if “title video-title” in eachline:
title = re.compile(r’(.*?)‘).search(eachline)
title = title.group(1)
if youtube_video:
item = QtGui.QListWidgetItem(title)
item.setIcon(QtGui.QIcon(‘%s/video.png’%(self.resourcePath)))
item.setData(QtCore.Qt.UserRole,QtCore.QVariant(youtube_video))
self.you_list.addItem(item)
youtube_video = None
except Exception,e:
self.you_log.append(str(e))

def listDownload(self):

if self.you_list.count() >= 1:
for i in range(self.you_list.count()):
get_data = self.you_list.item(i).data(QtCore.Qt.UserRole).toString()
get_title = str(self.you_list.item(i).text())
self.doYouTubeDownLoad(get_data,get_title)
else:
self.you_log.append(“No item found in list”)

def doYouTubeDownLoad(self,videoURL,filename):
videoURL = videoURL.split(“&”)[0]
downTemp=’http://www.youtube.com%s’%videoURL
destFolder = str(self.you_dest.text())
filename = filename.replace(” “,”_”)
filename = ‘%s/%s.flv’%(destFolder,filename)
dir = os.path.abspath( __file__ )
youtubeDL = os.path.dirname(dir) +’/youtube-dl.py’
commandPras=’python %s -o %s %s’%(youtubeDL,filename,downTemp)
output = self.execute(commandPras)

def removeDupList(self,seq, idfun=None):
if idfun is None:
def idfun(x): return x
seen = {}
result = []
for item in seq:
marker = idfun(item)
if marker in seen: continue
seen[marker] = 1
result.append(item)
return result

if __name__ == “__main__”:
from PyQt4 import QtGui, QtCore
app = QtGui.QApplication(sys.argv)
t = YOUTUBELISTVIEW(None)
t.show()
sys.exit(app.exec_())
[/Python]

  1. No comments yet.

  1. September 27th, 2011
    Trackback from : Tickets-News.de

Error thrown

Undefined constant "cs_print_smilies"