{"id":534,"date":"2011-08-07T12:13:08","date_gmt":"2011-08-07T12:13:08","guid":{"rendered":"http:\/\/www.kurianos.com\/wordpress\/?p=534"},"modified":"2011-09-16T10:35:09","modified_gmt":"2011-09-16T10:35:09","slug":"youtube-playlist-download","status":"publish","type":"post","link":"https:\/\/www.kurianos.com\/wordpress\/?p=534","title":{"rendered":"Youtube Playlist Download"},"content":{"rendered":"<p>Hi All,<\/p>\n<p>I am just releasing a version of youtube playlist downloading tool and this tool depends on on youtube-d and pyqt.<br \/>\nHere is the source code and screen shoot .<\/p>\n<p><a href=\"http:\/\/www.kurianos.com\/python\/youtube_list.zip\">Source <\/a><\/p>\n<p>ngg_shortcode_0_placeholder<br \/>\n[Python]<br \/>\n#~ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\n#~ \/\/<br \/>\n#~ \/\/ Copyright (c) 2010-2011, Kurian OS<br \/>\n#~ \/\/ All rights reserved.<br \/>\n#~ \/\/<br \/>\n#~ \/\/ Redistribution and use in source and binary forms, with or without<br \/>\n#~ \/\/ modification, are permitted provided that the following conditions<br \/>\n#~ \/\/ are met:<br \/>\n#~ \/\/<br \/>\n#~ \/\/ Redistributions of source code must retain the above copyright<br \/>\n#~ \/\/ notice, this list of conditions and the following disclaimer.<br \/>\n#~ \/\/ Redistributions in binary form must reproduce the above copyright<br \/>\n#~ \/\/ notice, this list of conditions and the following disclaimer in the<br \/>\n#~ \/\/ documentation and\/or other materials provided with the<br \/>\n#~ \/\/ distribution.  Neither the name of Kurian Os nor the<br \/>\n#~ \/\/ names of its contributors may be used to endorse or promote<br \/>\n#~ \/\/ products derived from this software without specific prior written<br \/>\n#~ \/\/ permission.<br \/>\n#~ \/\/<br \/>\n#~ \/\/ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS<br \/>\n#~ \/\/ &#8220;AS IS&#8221; AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT<br \/>\n#~ \/\/ LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS<br \/>\n#~ \/\/ FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE<br \/>\n#~ \/\/ COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,<br \/>\n#~ \/\/ INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES<br \/>\n#~ \/\/ (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR<br \/>\n#~ \/\/ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)<br \/>\n#~ \/\/ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,<br \/>\n#~ \/\/ STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)<br \/>\n#~ \/\/ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED<br \/>\n#~ \/\/ OF THE POSSIBILITY OF SUCH DAMAGE.<br \/>\n#~ \/\/<br \/>\n#~ \/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/\/<br \/>\n__authors__ = [&#8220;kurian.os&#8221;]<br \/>\n__date__ = &#8216;$Date:  Aug 7, 2011 12:00:00 PM$&#8217;.split()[1]<br \/>\n__copyright__ = &#8216;2011&#8217;<br \/>\n__license__ = &#8220;Copyright Kurian O.S&#8221;<br \/>\n__contact__ = &#8220;kurianos@gmail.com&#8221;<br \/>\n__status__ = &#8220;Release&#8221;<\/p>\n<p>import os<br \/>\nimport re<br \/>\nimport sys<br \/>\nimport time<br \/>\nimport urllib<br \/>\nimport urllib2<br \/>\nimport commands<br \/>\nimport subprocess<\/p>\n<p>from PyQt4 import QtGui, QtCore, uic<br \/>\nYOU_Panel, YOU_Widget= uic.loadUiType(os.path.join(os.path.split(__file__)[0], &#8220;youtube.ui&#8221;))<\/p>\n<p>class YOUTUBELISTVIEW(YOU_Widget,YOU_Panel):<\/p>\n<p>\tdef __init__(self,*args):<br \/>\n\t\tself.resourcePath = &#8220;%s\/resource&#8221;%os.path.split(__file__)[0]<br \/>\n\t\tYOU_Widget.__init__(self, None, QtCore.Qt.WindowStaysOnTopHint)<br \/>\n\t\tself.setupUi(self)<br \/>\n\t\tself.setFocusPolicy(QtCore.Qt.StrongFocus)<br \/>\n\t\tself.setAttribute(QtCore.Qt.WA_QuitOnClose, True)<br \/>\n\t\tself.setWindowIcon(QtGui.QIcon(&#8216;%s\/video.png&#8217;%(self.resourcePath)))<br \/>\n\t\tself.connect(self.you_browse, QtCore.SIGNAL(&#8216;clicked()&#8217;),self.loadDestinationfolder)<br \/>\n\t\tself.connect(self.you_get, QtCore.SIGNAL(&#8216;clicked()&#8217;),self.fetchPlayList)<br \/>\n\t\tself.connect(self.you_down, QtCore.SIGNAL(&#8216;clicked()&#8217;),self.listDownload)<br \/>\n\t\tself.show()<\/p>\n<p>\tdef loadDestinationfolder(self):<br \/>\n\t\toptions = QtGui.QFileDialog.DontResolveSymlinks | QtGui.QFileDialog.ShowDirsOnly<br \/>\n\t\tfileName = QtGui.QFileDialog.getExistingDirectory(self, &#8216;*.*&#8217;, &#8216; &#8216;, options)<br \/>\n\t\tself.you_dest.setText(fileName)<\/p>\n<p>\tdef fetchPlayList(self):<br \/>\n\t\tgetPlayList=self.you_link.text()<br \/>\n\t\tgetDestNation=self.you_browse.text()<br \/>\n\t\tif getPlayList == &#8221; or getPlayList == &#8216; &#8216; or getPlayList == None or getDestNation == &#8221; or getDestNation == &#8216; &#8216; or getDestNation == None:<br \/>\n\t\t\tQtGui.QMessageBox.critical(self, &#8216;Error!&#8217;, &#8216;Please enter a youtube playlist and destination folder path!&#8217;, QtGui.QMessageBox.Ok)<br \/>\n\t\t\tself.you_log.append(&#8220;Please enter a youtube playlist and destination folder path!&#8221;)<br \/>\n\t\telse:<br \/>\n\t\t\tself.openYouTubePlayList(str(getPlayList))<\/p>\n<p>\tdef openYouTubePlayList(self,playListURL):<br \/>\n\t\tgetFile=urllib.urlopen(str(playListURL))<br \/>\n\t\tself.openYouTubeLink(playListURL)<br \/>\n\t\ttry:<br \/>\n\t\t\tplayListPages=[]<br \/>\n\t\t\tfor eachLine in getFile:<br \/>\n\t\t\t\tif &#8216;pagerNotCurrent&#8217; in eachLine:<br \/>\n\t\t\t\t\tplayListCnt=eachLine.split(&#8216;class=&#8217;)<br \/>\n\t\t\t\t\tplayListCnt=playListCnt[0].strip()<br \/>\n\t\t\t\t\tplayListPages.append(playListCnt[len(playListCnt)-2])<br \/>\n\t\t\tplayListPages=self.removeDupList(playListPages)<br \/>\n\t\t\tfor eachCnt in playListPages:<br \/>\n\t\t\t\tsendPlayListUrl=playListURL+&#8217;&#038;page=%s&#8217;%eachCnt<br \/>\n\t\t\t\tself.openYouTubeLink(str(sendPlayListUrl))<br \/>\n\t\texcept Exception,e:<br \/>\n\t\t\tself.you_log.append(str(e))<\/p>\n<p>\tdef openYouTubeLink(self,currentUrl):<br \/>\n\t\tgetFile=urllib.urlopen(currentUrl)<br \/>\n\t\torginalSourcePath=[]<br \/>\n\t\tfor eachline in getFile:<br \/>\n\t\t\ttry:<br \/>\n\t\t\t\tif &#8216;watch?v&#8217; and &#8220;index=&#8221; in eachline:<br \/>\n\t\t\t\t\tif &#8220;href&#8221; in eachline:<br \/>\n\t\t\t\t\t\tyoutube_video = eachline.split(&#8221; &#8220;)<br \/>\n\t\t\t\t\t\tyoutube_video = filter(bool, youtube_video)<br \/>\n\t\t\t\t\t\tyoutube_video=youtube_video[1][6:].split(&#8220;;&#8221;)[0]<\/p>\n<p>\t\t\t\tif &#8220;title video-title&#8221; in eachline:<br \/>\n\t\t\t\t\ttitle = re.compile(r&#8217;<span class=\"title video-title\">(.*?)<\/span>&#8216;).search(eachline)<br \/>\n\t\t\t\t\ttitle = title.group(1)<br \/>\n\t\t\t\t\tif youtube_video:<br \/>\n\t\t\t\t\t\titem = QtGui.QListWidgetItem(title)<br \/>\n\t\t\t\t\t\titem.setIcon(QtGui.QIcon(&#8216;%s\/video.png&#8217;%(self.resourcePath)))<br \/>\n\t\t\t\t\t\titem.setData(QtCore.Qt.UserRole,QtCore.QVariant(youtube_video))<br \/>\n\t\t\t\t\t\tself.you_list.addItem(item)<br \/>\n\t\t\t\t\t\tyoutube_video = None<br \/>\n\t\t\texcept Exception,e:<br \/>\n\t\t\t\tself.you_log.append(str(e))<\/p>\n<p>\tdef listDownload(self):<\/p>\n<p>\t\tif self.you_list.count() >= 1:<br \/>\n\t\t\tfor i in range(self.you_list.count()):<br \/>\n\t\t\t\tget_data = self.you_list.item(i).data(QtCore.Qt.UserRole).toString()<br \/>\n\t\t\t\tget_title = str(self.you_list.item(i).text())<br \/>\n\t\t\t\tself.doYouTubeDownLoad(get_data,get_title)<br \/>\n\t\telse:<br \/>\n\t\t\tself.you_log.append(&#8220;No item found in list&#8221;)<\/p>\n<p>\tdef doYouTubeDownLoad(self,videoURL,filename):<br \/>\n\t\tvideoURL = videoURL.split(&#8220;&#038;&#8221;)[0]<br \/>\n\t\tdownTemp=&#8217;http:\/\/www.youtube.com%s&#8217;%videoURL<br \/>\n\t\tdestFolder = str(self.you_dest.text())<br \/>\n\t\tfilename = filename.replace(&#8221; &#8220;,&#8221;_&#8221;)<br \/>\n\t\tfilename = &#8216;%s\/%s.flv&#8217;%(destFolder,filename)<br \/>\n\t\tdir = os.path.abspath( __file__ )<br \/>\n\t\tyoutubeDL = os.path.dirname(dir) +&#8217;\/youtube-dl.py&#8217;<br \/>\n\t\tcommandPras=&#8217;python %s -o %s %s&#8217;%(youtubeDL,filename,downTemp)<br \/>\n\t\toutput = self.execute(commandPras)<\/p>\n<p>\tdef removeDupList(self,seq, idfun=None):<br \/>\n\t\tif idfun is None:<br \/>\n\t\t\tdef idfun(x): return x<br \/>\n\t\tseen = {}<br \/>\n\t\tresult = []<br \/>\n\t\tfor item in seq:<br \/>\n\t\t\tmarker = idfun(item)<br \/>\n\t\t\tif marker in seen: continue<br \/>\n\t\t\tseen[marker] = 1<br \/>\n\t\t\tresult.append(item)<br \/>\n\t\treturn result<\/p>\n<p>if __name__ == &#8220;__main__&#8221;:<br \/>\n    from PyQt4 import QtGui, QtCore<br \/>\n    app = QtGui.QApplication(sys.argv)<br \/>\n    t = YOUTUBELISTVIEW(None)<br \/>\n    t.show()<br \/>\n    sys.exit(app.exec_())<br \/>\n[\/Python]<\/p>\n","protected":false},"excerpt":{"rendered":"<p>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 [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"ngg_post_thumbnail":0,"footnotes":""},"categories":[15,14],"tags":[],"class_list":["post-534","post","type-post","status-publish","format-standard","hentry","category-linux","category-python"],"_links":{"self":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/534","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=534"}],"version-history":[{"count":13,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/534\/revisions"}],"predecessor-version":[{"id":556,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=\/wp\/v2\/posts\/534\/revisions\/556"}],"wp:attachment":[{"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=534"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=534"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.kurianos.com\/wordpress\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=534"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}