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 .
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
#~ /////////////////////////////////////////////////////////////////////////////// #~ // #~ // 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'<span class="title video-title">(.*?)</span>').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_()) |