Exemple #1
0
def startDownload(url):
    global file_size
    path_to_save = askdirectory()
    if path_to_save is None:
        return
    try:
        yt = YouTube(url)
        st = yt.streams.first()
        yt.register_on_complete_callback(completeDownload)
        yt.register_on_progress_callback(progressDownload)

        file_size = st.filesize
        st.download(output_path=path_to_save)

    except Exception as e:
        print(e)
        print("Something Went wrong...Try again")
    def download_all(self, download_path=None):
        self.populate_video_urls()
        length = len(self.video_urls)
        print('Total videos found: ', length)
        print('Starting download')
        print('Complete:')

        for i, link in enumerate(self.video_urls):
            print_progress(i, length)
            yt = YouTube(link)
            dl_stream = yt.streams.filter(
                progressive=True,
                subtype='mp4',
            ).order_by('resolution').desc().first()
            logger.debug('download path: %s', download_path)
            dl_stream.download(download_path)
            logger.debug('download complete')
            print_progress(i + 1, length)
Exemple #3
0
    def download_all(self):
        """Download all the videos in the the playlist. Initially, download
        resolution is 720p (or highest available), later more option
        should be added to download resolution of choice

        TODO(nficano): Add option to download resolution of user's choice
        """

        self.populate_video_urls()
        logger.debug('total videos found: ', len(self.video_urls))
        logger.debug('starting download')

        for link in self.video_urls:
            yt = YouTube(link)

            yt.streams.filter(
                progressive=True,
                subtype='mp4',
            ).order_by('resolution').desc().first().download()

            logger.debug('download complete')
Exemple #4
0
    def download_all(
        self,
        download_path=None,
        prefix_number=True,
        reverse_numbering=False,
    ):
        """Download all the videos in the the playlist. Initially, download
		resolution is 720p (or highest available), later more option
		should be added to download resolution of choice

		TODO(nficano): Add option to download resolution of user's choice

		:param download_path:
			(optional) Output path for the playlist If one is not
			specified, defaults to the current working directory.
			This is passed along to the Stream objects.
		:type download_path: str or None
		:param prefix_number:
			(optional) Automatically numbers playlists using the
			_path_num_prefix_generator function.
		:type prefix_number: bool
		:param reverse_numbering:
			(optional) Lets you number playlists in reverse, since some
			playlists are ordered newest -> oldests.
		:type reverse_numbering: bool
		"""

        self.populate_video_urls()
        logger.debug('total videos found: %d', len(self.video_urls))
        logger.debug('starting download')

        prefix_gen = self._path_num_prefix_generator(reverse_numbering)

        for link in self.video_urls:
            try:
                yt = YouTube(link)

            except Exception as e:
                logger.debug(e)
                if not self.suppress_exception:
                    raise e
                else:
                    logger.debug('Exception suppressed')
            else:
                # TODO: this should not be hardcoded to a single user's
                # preference
                dl_stream = yt.streams.filter(
                    progressive=True,
                    subtype='mp4',
                ).order_by('resolution').desc().first()

                name = dl_stream.default_filename
                try:
                    caption = yt.captions.get_by_language_code(
                        'en').generate_srt_captions()
                except:
                    pass

                logger.debug('download path: %s', download_path)
                if prefix_number:
                    prefix = next(prefix_gen)
                    logger.debug('file prefix is: %s', prefix)
                    dl_stream.download(download_path, filename_prefix=prefix)
                    print(download_path)
                    try:
                        saveSrt = open(
                            str(download_path) + '/' + str(prefix) +
                            str(name) + '.srt', 'w')
                        saveSrt.write(caption)
                        saveSrt.close()
                    except:
                        pass
                    print('dowloaded: ' + str(prefix) + str(name))
                else:
                    dl_stream.download(download_path)
                    try:
                        saveSrt = open(
                            str(download_path) + '/' + str(name) + '.srt', 'w')
                        saveSrt.write(caption)
                        saveSrt.close()
                    except:
                        pass
                    print('dowloaded: ' + str(name))
                logger.debug('download complete')
Exemple #5
0
    def download_all(self,
                     download_path=None,
                     prefix_number=True,
                     reverse_numbering=False,
                     resolution="720p"):
        """Download all the videos in the the playlist. Initially, download
        resolution is 720p (or highest available), later more option
        should be added to download resolution of choice

        :param download_path:
            (optional) Output path for the playlist If one is not
            specified, defaults to the current working directory.
            This is passed along to the Stream objects.
        :type download_path: str or None
        :param prefix_number:
            (optional) Automatically numbers playlists using the
            _path_num_prefix_generator function.
        :type prefix_number: bool
        :param reverse_numbering:
            (optional) Lets you number playlists in reverse, since some
            playlists are ordered newest -> oldests.
        :type reverse_numbering: bool
        :param resolution:
            (optional) Let's you change the resolution at which the
            playlist will be downloaded. The input must be a string
            that's in the resolutions array.
        :type resolution:str

        :rtype: None
        """

        resolutions = ["720p", "480p", "360p", "240p", "144p"]
        if resolution not in resolutions:
            raise Resolution_Exception(
                "Resolution argument, needs to be one"
                " of these: {} \n Higher than 720p is "
                "not yet supported since no progressive"
                " stream is available. ".format(resolutions))

        self.populate_video_urls()
        logger.debug('total videos found: %d', len(self.video_urls))
        logger.debug('starting download')

        prefix_gen = self._path_num_prefix_generator(reverse_numbering)

        for link in self.video_urls:

            def get_stream(_resolution):
                stream = yt.streams.filter(progressive=True,
                                           subtype='mp4',
                                           resolution=resolution).first()
                if stream is not None:
                    return stream
                else:
                    res_idx = resolutions.index(_resolution)
                    if res_idx > 0:
                        return get_stream(resolutions[res_idx - 1])
                    else:
                        print("Pytube could not find resolution equal or "
                              "smaller than {0} for link: {}")
                        print("Downloading at lowest available quality.")
                        return yt.streams.filter(
                            progressive=True,
                            subtype='mp4',
                        ).order_by('resolution').desc().last()

            yt = YouTube(link)
            dl_stream = get_stream(resolution)

            logger.debug('download path: %s', download_path)
            if prefix_number:
                prefix = next(prefix_gen)
                logger.debug('file prefix is: %s', prefix)
                dl_stream.download(download_path, filename_prefix=prefix)
            else:
                dl_stream.download(download_path)
            logger.debug('download complete')
Exemple #6
0
def yt(li, url, vid, title, tag, summ, thumb):
    PLog('yt_embed_url: ' + url)
    watch_url = 'https://www.youtube.com/watch?v=' + vid
    PLog('yt_watch_url: ' + watch_url)
    PLog(tag)
    PLog(summ)
    PLog(thumb)
    title_org = title

    yt = YouTube(watch_url)
    # nur mp4-Videos laden
    Videos = yt.streams.filter(file_extension='mp4').all()
    PLog(len(Videos))
    PLog(str(Videos))

    if SETTINGS.getSetting('pref_video_direct') == 'true':
        PLog('Sofortstart: yt')
        #  <Stream: itag="22" mime_type="video/mp4" res="720p" fps="30fps"
        #	vcodec="avc1.64001F" acodec="mp4a.40.2">:
        stream = yt.streams.get_by_itag(22)
        res, fps, vcodec, acodec = get_stream_details(str(stream))
        yt_url = stream.download(only_url=True)
        if summ == '':
            summ = tag
        summ = "%s\n\n%s" % (summ, 'Youtube-Video: %s | %s | %s | %s' %
                             (res, fps, vcodec, acodec))
        PlayVideo(url=yt_url, title=title, thumb=thumb, Plot=summ, sub_path="")
        return

    download_list = []  # 2-teilige Liste für Download: 'Titel # url'
    i = 1
    for video in Videos:
        v = str(video)
        itag = stringextract('itag="', '"', v)
        mime_type = stringextract('mime_type="', '"', v)
        res, fps, vcodec, acodec = get_stream_details(v)
        PLog(video)
        PLog('itag: ' + itag)
        PLog(res)
        PLog(fps)
        PLog(vcodec)
        PLog(acodec)

        try:  # Videolänge kann fehlen
            duration = yt.length()
            duration = seconds_translate(sec)
        except:
            duration = ''

        stream = yt.streams.get_by_itag(itag)
        yt_url = stream.download(only_url=True)
        PLog('yt_url: ' + yt_url[:100])

        if res == '' and fps == '':
            summ = '%s. Youtube-Video (nur Audio): %s' % (str(i), acodec)
        else:
            if acodec:
                summ = '%s. Youtube-Video: %s | %s | %s | %s' % (
                    str(i), res, fps, vcodec, acodec)
            else:
                summ = '%s. Youtube-Video: %s | %s | %s' % (str(i), res, fps,
                                                            vcodec)

        download_list.append(summ + '#' +
                             yt_url)  # Download-Liste füllen	(Qual.#Url)

        if duration:
            tag = u"Dauer %s | %s" % (duration, tag)

        summ_par = "%s||||%s" % (tag, summ)
        title = "%s. %s" % (str(i), title_org)
        PLog(title)
        PLog(tag)
        PLog(summ)

        yt_url = py2_encode(yt_url)
        title = py2_encode(title)
        thumb = py2_encode(thumb)
        summ_par = py2_encode(summ_par)
        fparams="&fparams={'url': '%s', 'title': '%s', 'thumb': '%s', 'Plot': '%s'}" % \
         (quote(yt_url), quote(title), quote_plus(thumb), quote_plus(summ_par))
        addDir(li=li,
               label=title,
               action="dirList",
               dirID="PlayVideo",
               fanart=thumb,
               thumb=thumb,
               fparams=fparams,
               tagline=tag,
               summary=summ,
               mediatype='video')

        i = i + 1

    if download_list:  # Downloadbutton(s), high=0: 1. Video = höchste Qualität
        PLog(len(download_list))
        # Qualitäts-Index high: hier Basis Bitrate (s.o.)
        title_org = title_org
        summary_org = ''
        tagline_org = repl_json_chars(tag)
        # PLog(summary_org);PLog(tagline_org);PLog(thumb);
        li = ardundzdf.test_downloads(li,
                                      download_list,
                                      title_org,
                                      summary_org,
                                      tagline_org,
                                      thumb,
                                      high=0)

    # return li		# kann yt mehrfach aufrufen (trotz endOfDirectory in SingleBeitrag
    xbmcplugin.endOfDirectory(HANDLE)


pl = Playlist(url)
pl.populate_video_urls()
no = len(pl.video_urls)
print "there is total %s:" % len(pl.video_urls) 
print " videos available in playlist"

print "This are available files in your current directory"
print "Enter the number of videos downloaded of playlist"
num=input()
for i in range(num,no-1):
    print "downloading "+str(i+1)+" video started"
    url = pl.video_urls[i]
    YouTube(url).streams.first().download()
    print "video "+str(i+1)+" download complete"
    tube = YouTube(url)
    title = tube.title
    caption = tube.captions.get_by_language_code('en')
    if caption is not None:
                print "downloadind subtitle for "+str(i+1)+" video"
                subtitle = caption.generate_srt_captions()
                file = open(title+".srt", "w")
                file.writelines(subtitle) 
                print "subtitle file has saved"
            
            

#pl.download_all()
#yt = YouTube("https://www.youtube.com/watch?v=eVTXPUF4Oz4&list=PL93lkIr4wEXFyrkvOaxzmgBPkOiOKMX4t&t=0s&index=2")
    def download_all(self,
                     download_path=None,
                     prefix_number=True,
                     reverse_numbering=False,
                     skip_existing=False):
        """Download all the videos in the the playlist. Initially, download
        resolution is 720p (or highest available), later more option
        should be added to download resolution of choice

        TODO(nficano): Add option to download resolution of user's choice

        :param download_path:
            (optional) Output path for the playlist If one is not
            specified, defaults to the current working directory.
            This is passed along to the Stream objects.
        :type download_path: str or None
        :param prefix_number:
            (optional) Automatically numbers playlists using the
            _path_num_prefix_generator function.
        :type prefix_number: bool
        :param reverse_numbering:
            (optional) Lets you number playlists in reverse, since some
            playlists are ordered newest -> oldests.
        :type reverse_numbering: bool
        """

        self.populate_video_urls()
        logger.info('total videos found: %d', len(self.video_urls))
        logger.info('starting download')

        prefix_gen = self._path_num_prefix_generator(reverse_numbering)

        self.video_urls.reverse()  # To backup oldest first
        for link in self.video_urls:
            try:
                yt = YouTube(link)
            except Exception as e:
                logger.debug(e)
                if not self.suppress_exception:
                    raise e
                else:
                    logger.info('Exception suppressed')
            else:
                # TODO: this should not be hardcoded to a single user's
                # preference
                dl_stream = yt.streams.filter(
                    progressive=True,
                    subtype='mp4',
                ).order_by('resolution').desc().first()

                logger.debug('download path: %s', download_path)
                logger.info('downloading %s/%s',
                            self.video_urls.index(link) + 1,
                            len(self.video_urls))
                if prefix_number:
                    prefix = next(prefix_gen)
                    logger.debug('file prefix is: %s', prefix)
                    dl_stream.download(download_path,
                                       filename_prefix=prefix,
                                       skip_existing=skip_existing)
                else:
                    dl_stream.download(download_path,
                                       skip_existing=skip_existing)
                logger.info('download complete')