Ejemplo n.º 1
0
	def testDownloadVideosReferencedInPlaylistForPlaylistUrl_with_timeFrame(self):
		playlistName = 'Test_title_one_time_frame_extract'
		downloadDir = AUDIO_DIR_TEST + DIR_SEP + playlistName
		# timeInfo = '(e0:0:5-0:0:10)'

		if not os.path.exists(downloadDir):
			os.mkdir(downloadDir)
		
		# deleting files in downloadDir
		files = glob.glob(downloadDir + DIR_SEP + '*')
		
		for f in files:
			os.remove(f)
		
		guiOutput = GuiOutputStub()
		youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
		playlistUrl = "https://www.youtube.com/playlist?list=PLzwWSJNcZTMTB7GasAttwVnPPk3-WTMNJ"
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, downloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		downloadVideoInfoDic, accessError = youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(playlistUrl, downloadVideoInfoDic)
		targetAudioDir = downloadVideoInfoDic.getPlaylistDownloadDir()

		sys.stdout = stdout

		self.assertIsNone(accessError)
		self.assertEqual(['downloading "Wear a mask. Help slow the spread of Covid-19." audio ...',
 '',
 '"Wear a mask. Help slow the spread of Covid-19." audio downloaded.',
 '',
 '"Test_title_one_time_frame_extract" playlist audio(s) download terminated.',
 '',
 ''], outputCapturingString.getvalue().split('\n'))

		self.assertEqual([[5, 10]], downloadVideoInfoDic.getExtractStartEndSecondsListsForVideoIndex(1))
		self.assertEqual(downloadDir, targetAudioDir)
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19.', downloadVideoInfoDic.getVideoTitleForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk', downloadVideoInfoDic.getVideoUrlForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk', downloadVideoInfoDic.getVideoUrlForVideoTitle('Wear a mask. Help slow the spread of Covid-19.'))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3', downloadVideoInfoDic.getVideoFileNameForVideoIndex(1))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3', downloadVideoInfoDic.getVideoFileNameForVideoTitle('Wear a mask. Help slow the spread of Covid-19.'))

		self.assertEqual(['1'], downloadVideoInfoDic.getVideoIndexes())

		if os.name == 'posix':
			self.assertEqual('/storage/emulated/0/Download/Audiobooks/test/' + playlistName,
			                 downloadDir)
		else:
			self.assertEqual('D:\\Users\\Jean-Pierre\\Downloads\\Audiobooks\\test\\' + playlistName,
			                 downloadDir)

		fileNameLst = [x.split(DIR_SEP)[-1] for x in glob.glob(downloadDir + DIR_SEP + '*.*')]
		self.assertEqual(sorted(['Test_title_one_time_frame_extract_dic.txt',
								 'Wear a mask. Help slow the spread of Covid-19..mp3']), sorted(fileNameLst))
		self.assertEqual([[5, 10]], downloadVideoInfoDic.getExtractStartEndSecondsListsForVideoIndex(1))
Ejemplo n.º 2
0
	def testDownloadVideosReferencedInPlaylistForPlaylistUrlMultipleVideo(self):
		playlistName = 'test_audio_downloader_two_files'
		downloadDir = AUDIO_DIR_TEST + DIR_SEP + playlistName
		
		if not os.path.exists(downloadDir):
			os.mkdir(downloadDir)
		
		# deleting files in downloadDir
		files = glob.glob(downloadDir + DIR_SEP + '*')
		
		for f in files:
			os.remove(f)
		
		guiOutput = GuiOutputStub()
		youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
		playlistUrl = "https://www.youtube.com/playlist?list=PLzwWSJNcZTMRGA1T1vOn500RuLFo_lGJv"
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, downloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		downloadVideoInfoDic, accessError = youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(playlistUrl, downloadVideoInfoDic)
		targetAudioDir = downloadVideoInfoDic.getPlaylistDownloadDir()
		sys.stdout = stdout

		self.assertIsNone(accessError)
		self.assertEqual(['downloading "Wear a mask. Help slow the spread of Covid-19." audio ...',
 '',
 '"Wear a mask. Help slow the spread of Covid-19." audio downloaded.',
 '',
 'downloading "Here to help: Give him what he wants" audio ...',
 '',
 '"Here to help: Give him what he wants" audio downloaded.',
 '',
 '"test_audio_downloader_two_files" playlist audio(s) download terminated.',
 '',
 ''], outputCapturingString.getvalue().split('\n'))

		self.assertEqual(downloadDir, targetAudioDir)
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19.', downloadVideoInfoDic.getVideoTitleForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk', downloadVideoInfoDic.getVideoUrlForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk', downloadVideoInfoDic.getVideoUrlForVideoTitle('Wear a mask. Help slow the spread of Covid-19.'))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3', downloadVideoInfoDic.getVideoFileNameForVideoIndex(1))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3', downloadVideoInfoDic.getVideoFileNameForVideoTitle('Wear a mask. Help slow the spread of Covid-19.'))

		self.assertEqual('Here to help: Give him what he wants', downloadVideoInfoDic.getVideoTitleForVideoIndex(2))
		self.assertEqual('https://www.youtube.com/watch?v=Eqy6M6qLWGw', downloadVideoInfoDic.getVideoUrlForVideoIndex(2))
		self.assertEqual('https://www.youtube.com/watch?v=Eqy6M6qLWGw', downloadVideoInfoDic.getVideoUrlForVideoTitle('Here to help: Give him what he wants'))
		self.assertEqual('Here to help - Give him what he wants.mp3', downloadVideoInfoDic.getVideoFileNameForVideoIndex(2))
		self.assertEqual('Here to help - Give him what he wants.mp3', downloadVideoInfoDic.getVideoFileNameForVideoTitle('Here to help: Give him what he wants'))

		self.assertEqual(['1', '2'], downloadVideoInfoDic.getVideoIndexes())

		fileNameLst = [x.split(DIR_SEP)[-1] for x in glob.glob(downloadDir + DIR_SEP + '*.*')]
		self.assertEqual(sorted(['Here to help - Give him what he wants.mp3',
								 'Wear a mask. Help slow the spread of Covid-19..mp3',
								 'test_audio_downloader_two_files_dic.txt']), sorted(fileNameLst))
Ejemplo n.º 3
0
    def testDownloadSingleVideoForUrl_targetFolder_not_exist(self):
        expectedVideoTitle = 'Funny suspicious looking dog'
        audioSubDirName = 'Various_test_new'
        downloadDir = AUDIO_DIR_TEST + DIR_SEP + audioSubDirName

        # deleting downloadDir (dir and content)
        if os.path.exists(downloadDir):
            shutil.rmtree(downloadDir)

        guiOutput = GuiOutputStub()
        youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
        videoUrl = "https://youtu.be/vU1NEZ9sTOM"

        stdout = sys.stdout
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString

        _, downloadVideoInfoDic, videoTitle, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(
            videoUrl)

        self.assertIsNone(downloadVideoInfoDic)
        self.assertIsNone(accessError)
        self.assertEqual(expectedVideoTitle, videoTitle)

        youtubeAccess.downloadSingleVideoForUrl(videoUrl, videoTitle,
                                                downloadDir)

        sys.stdout = stdout

        if os.name == 'posix':
            self.assertEqual([
                'directory', 'Audiobooks/Various_test_new', 'was created.', '',
                'downloading "Funny suspicious looking dog" audio ...', '',
                '"Funny suspicious looking dog" audio downloaded in '
                'test/Various_test_new directory.', '', ''
            ],
                             outputCapturingString.getvalue().split('\n'))
            self.assertEqual(
                '/storage/emulated/0/Download/Audiobooks/test/' +
                audioSubDirName, downloadDir)
        else:
            self.assertEqual([
                'directory', 'test\\Various_test_new', 'was created.', '',
                'downloading "Funny suspicious looking dog" audio ...', '',
                '"Funny suspicious looking dog" audio downloaded in '
                'test\\Various_test_new directory.', '', ''
            ],
                             outputCapturingString.getvalue().split('\n'))
            self.assertEqual(
                'D:\\Users\\Jean-Pierre\\Downloads\\Audiobooks\\test\\' +
                audioSubDirName, downloadDir)

        fileNameLst = [
            x.split(DIR_SEP)[-1]
            for x in glob.glob(downloadDir + DIR_SEP + '*.*')
        ]
        self.assertEqual(sorted(['Funny suspicious looking dog.mp3']),
                         sorted(fileNameLst))
Ejemplo n.º 4
0
    def testTrimAudioFile(self):
        playListName = 'test_audio_controller'
        targetAudioDir = AUDIO_DIR_TEST + DIR_SEP + playListName
        audioFileName = 'LExpérience de Mort Imminente de Madame Mirjana Uzoh.mp3'
        audioFilePathName = targetAudioDir + DIR_SEP + audioFileName

        expectedExtractedFileDuration_1 = 63
        expectedExtractedFileDuration_2 = 62

        if not os.path.isdir(targetAudioDir):
            os.mkdir(targetAudioDir)

        # deleting files in downloadDir
        files = glob.glob(targetAudioDir + DIR_SEP + '*')

        for f in files:
            os.remove(f)

        # restoring mp4 file

        shutil.copy(
            'D:\\Development\\Python\\audiodownload\\test\\testData\\' +
            audioFileName, targetAudioDir + '\\' + audioFileName)

        guiOutput = GuiOutputStub()
        audioController = AudioController(guiOutput, AUDIO_DIR_TEST)

        stdout = sys.stdout
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString

        audioController.trimAudioFile(audioFilePathName)

        sys.stdout = stdout

        videoAndAudioFileList = os.listdir(targetAudioDir)
        self.assertEqual([
            'LExpérience de Mort Imminente de Madame Mirjana Uzoh.mp3',
            'LExpérience de Mort Imminente de Madame Mirjana Uzoh_1.mp3',
            'LExpérience de Mort Imminente de Madame Mirjana Uzoh_2.mp3'
        ], videoAndAudioFileList)

        from mutagen.mp3 import MP3
        extractedMp3FileName_1 = videoAndAudioFileList[1]
        extractedMp3FileName_2 = videoAndAudioFileList[2]
        audio = MP3(targetAudioDir + DIR_SEP + extractedMp3FileName_1)
        self.assertAlmostEquals(expectedExtractedFileDuration_1,
                                audio.info.length,
                                delta=0.1)
        audio = MP3(targetAudioDir + DIR_SEP + extractedMp3FileName_2)
        self.assertAlmostEquals(expectedExtractedFileDuration_2,
                                audio.info.length,
                                delta=0.1)
Ejemplo n.º 5
0
	def testDownloadVideosReferencedInPlaylistForPlaylistUrl_empty_url(self):
		guiOutput = GuiOutputStub()
		youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
		playlistUrl = ""
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, downloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		downloadVideoInfoDic, accessError = youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(playlistUrl, downloadVideoInfoDic)
		
		sys.stdout = stdout
		
		self.assertEqual('the URL obtained from clipboard is empty.\nnothing to download.', accessError.errorMsg)
Ejemplo n.º 6
0
	def testDownloadVideosReferencedInPlaylistForPlaylistUrl_invalid_url(self):
		guiOutput = GuiOutputStub()
		youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
		playlistUrl = "https://www.youtube.com/playlist?list=invalid"
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, downloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		downloadVideoInfoDic, accessError = youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(playlistUrl, downloadVideoInfoDic)
		
		sys.stdout = stdout
		
		self.assertEqual('trying to get the video title for the URL obtained from clipboard did not succeed.\nfailing URL: https://www.youtube.com/playlist?list=invalid\nerror info: regex_search: could not find match for (?:v=|\/)([0-9A-Za-z_-]{11}).*\nnothing to download.', accessError.errorMsg)
Ejemplo n.º 7
0
	def testDownloadVideosReferencedInPlaylistForPlaylistUrl_targetFolder_not_exist(self):
		playlistName = 'test_audio_downloader_one_file'
		downloadDir = AUDIO_DIR_TEST + DIR_SEP + playlistName

		# deleting downloadDir (dir and content)
		if os.path.exists(downloadDir):
			shutil.rmtree(downloadDir)
		
		guiOutput = GuiOutputStub()
		youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
		playlistUrl = "https://www.youtube.com/playlist?list=PLzwWSJNcZTMRxj8f47BrkV9S6WoxYWYDS"
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, downloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(playlistUrl, downloadVideoInfoDic)

		sys.stdout = stdout

		if os.name == 'posix':
			self.assertEqual(['directory',
 'test/test_audio_downloader_one_file',
 'was created.',
 '',
 'downloading "Wear a mask. Help slow the spread of Covid-19." audio ...',
 '',
 '"Wear a mask. Help slow the spread of Covid-19." audio downloaded.',
 '',
 ''], outputCapturingString.getvalue().split('\n'))
		else:
			self.assertEqual(['directory',
 'test\\test_audio_downloader_one_file',
 'was created.',
 '',
 'downloading "Wear a mask. Help slow the spread of Covid-19." audio ...',
 '',
 '"Wear a mask. Help slow the spread of Covid-19." audio downloaded.',
 '',
 '"test_audio_downloader_one_file" playlist audio(s) download terminated.',
 '',
 ''], outputCapturingString.getvalue().split('\n'))

		fileNameLst = [x.split(DIR_SEP)[-1] for x in glob.glob(downloadDir + DIR_SEP + '*.*')]
		self.assertEqual(sorted(['Wear a mask. Help slow the spread of Covid-19..mp3',
								 'test_audio_downloader_one_file_dic.txt']), sorted(fileNameLst))
Ejemplo n.º 8
0
    def testDownloadSingleVideoForUrl_redownloading_video(self):
        expectedVideoTitle = 'Funny suspicious looking dog'
        audioSubDirName = 'Various_test'
        downloadDir = AUDIO_DIR_TEST + DIR_SEP + audioSubDirName

        if not os.path.exists(downloadDir):
            os.mkdir(downloadDir)

        # deleting files in downloadDir
        files = glob.glob(downloadDir + DIR_SEP + '*')

        for f in files:
            os.remove(f)

        guiOutput = GuiOutputStub()
        youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
        videoUrl = "https://youtu.be/vU1NEZ9sTOM"
        videoUrl = 'https://youtu.be/vU1NEZ9sTOM'

        _, downloadVideoInfoDic, videoTitle, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(
            videoUrl)

        self.assertIsNone(downloadVideoInfoDic)
        self.assertIsNone(accessError)
        self.assertEqual(expectedVideoTitle, videoTitle)

        youtubeAccess.downloadSingleVideoForUrl(videoUrl, videoTitle,
                                                downloadDir)

        stdout = sys.stdout
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString

        youtubeAccess.downloadSingleVideoForUrl(videoUrl, videoTitle,
                                                downloadDir)

        sys.stdout = stdout

        self.assertEqual([
            '"Funny suspicious looking dog" audio already downloaded. Video skipped.',
            '', ''
        ],
                         outputCapturingString.getvalue().split('\n'))
Ejemplo n.º 9
0
	def testDownloadVideosReferencedInPlaylistForPlaylistUrlMultipleVideo_withTimeFrames_redownloading_the_playlist_after_adding_a_new_video(self):
		# re-downloading playlist with clearing all files but one in the destination dir
		# playlist title: test_audio_downloader_two_files_with_time_frames (e0:0:2-0:0:8) (s0:0:2-0:0:5 s0:0:7-0:0:10)
		playlistName = 'Test 3 short videos'
		downloadDir = AUDIO_DIR_TEST + DIR_SEP + playlistName
		
		if not os.path.exists(downloadDir):
			os.mkdir(downloadDir)
		
		# deleting files in downloadDir
		files = glob.glob(downloadDir + DIR_SEP + '*')
		
		for f in files:
			os.remove(f)
		
		guiOutput = GuiOutputStub()
		youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
		playlistUrl = 'https://www.youtube.com/playlist?list=PLzwWSJNcZTMShenMgwyjHC8o5bU8QUPbn'
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, downloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		downloadVideoInfoDic, accessError = youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(playlistUrl,
		                                                                                                   downloadVideoInfoDic)
		
		sys.stdout = stdout
		
		self.assertIsNone(accessError)
		self.assertEqual(
			['downloading "Wear a mask. Help slow the spread of Covid-19." audio ...',
			 '',
			 '"Wear a mask. Help slow the spread of Covid-19." audio downloaded.',
			 '',
			 'downloading "Here to help: Give him what he wants" audio ...',
			 '',
			 '"Here to help: Give him what he wants" audio downloaded.',
			 '',
			 'downloading "Funny suspicious looking dog" audio ...',
			 '',
			 '"Funny suspicious looking dog" audio downloaded.',
			 '',
			 '"Test 3 short videos" playlist audio(s) download terminated.',
			 '',
			 ''], outputCapturingString.getvalue().split('\n'))
		
		fileNameLst = [x.split(DIR_SEP)[-1] for x in glob.glob(downloadDir + DIR_SEP + '*.*')]
		self.assertEqual(
			sorted(['Funny suspicious looking dog.mp3',
 'Here to help - Give him what he wants.mp3',
 'Test 3 short videos_dic.txt',
 'Wear a mask. Help slow the spread of Covid-19..mp3']), sorted(fileNameLst))
		
		# re-downloading the playlist after suppressing the files and data for
		# the last video
		
		# the last video files in downloadDir
		files = glob.glob(downloadDir + DIR_SEP + '*.mp3')
		
		for f in files:
			if 'Funny suspicious looking dog' in f:
				os.remove(f)
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, redownloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		redownloadVideoInfoDic.removeVideoInfoForVideoTitle('Funny suspicious looking dog')
		
		redownloadVideoInfoDic, accessError = youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(
			playlistUrl, redownloadVideoInfoDic)
		targetAudioDir = downloadVideoInfoDic.getPlaylistDownloadDir()
		
		sys.stdout = stdout
		
		self.assertIsNone(accessError)
		self.assertEqual(['"Wear a mask. Help slow the spread of Covid-19." audio already downloaded. '
 'Video skipped.',
 '',
 '"Here to help: Give him what he wants" audio already downloaded. Video '
 'skipped.',
 '',
 'downloading "Funny suspicious looking dog" audio ...',
 '',
 '"Funny suspicious looking dog" audio downloaded.',
 '',
 '"Test 3 short videos" playlist audio(s) download terminated.',
 '',
 ''], outputCapturingString.getvalue().split('\n'))
		
		self.assertEqual(downloadDir, targetAudioDir)
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19.',
		                 redownloadVideoInfoDic.getVideoTitleForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk',
		                 redownloadVideoInfoDic.getVideoUrlForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk',
		                 redownloadVideoInfoDic.getVideoUrlForVideoTitle(
			                 'Wear a mask. Help slow the spread of Covid-19.'))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoIndex(1))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoTitle(
			                 'Wear a mask. Help slow the spread of Covid-19.'))
		
		self.assertEqual('Here to help: Give him what he wants',
		                 redownloadVideoInfoDic.getVideoTitleForVideoIndex(2))
		self.assertEqual('https://www.youtube.com/watch?v=Eqy6M6qLWGw',
		                 redownloadVideoInfoDic.getVideoUrlForVideoIndex(2))
		self.assertEqual('https://www.youtube.com/watch?v=Eqy6M6qLWGw',
		                 redownloadVideoInfoDic.getVideoUrlForVideoTitle('Here to help: Give him what he wants'))
		self.assertEqual('Here to help - Give him what he wants.mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoIndex(2))
		self.assertEqual('Here to help - Give him what he wants.mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoTitle(
			                 'Here to help: Give him what he wants'))
		
		self.assertEqual('Funny suspicious looking dog',
		                 redownloadVideoInfoDic.getVideoTitleForVideoIndex(3))
		self.assertEqual('https://www.youtube.com/watch?v=vU1NEZ9sTOM',
		                 redownloadVideoInfoDic.getVideoUrlForVideoIndex(3))
		self.assertEqual('https://www.youtube.com/watch?v=vU1NEZ9sTOM',
		                 redownloadVideoInfoDic.getVideoUrlForVideoTitle('Funny suspicious looking dog'))
		self.assertEqual('Funny suspicious looking dog.mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoIndex(3))
		self.assertEqual('Funny suspicious looking dog.mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoTitle(
			                 'Funny suspicious looking dog'))
		
		fileNameLst = [x.split(DIR_SEP)[-1] for x in glob.glob(downloadDir + DIR_SEP + '*.*')]
		self.assertEqual(
			sorted(['Funny suspicious looking dog.mp3',
 'Here to help - Give him what he wants.mp3',
 'Test 3 short videos_dic.txt',
 'Wear a mask. Help slow the spread of Covid-19..mp3']), sorted(fileNameLst))
Ejemplo n.º 10
0
	def testDownloadVideosReferencedInPlaylistForPlaylistUrlMultipleVideo_withTimeFrames_redownloading_the_playlist(self):
		# playlist title: test_audio_downloader_two_files_with_time_frames (e0:0:2-0:0:8) (s0:0:2-0:0:5 s0:0:7-0:0:10)
		playlistName = 'test_audio_downloader_two_files_with_time_frames'
		downloadDir = AUDIO_DIR_TEST + DIR_SEP + playlistName
		
		if not os.path.exists(downloadDir):
			os.mkdir(downloadDir)
		
		# deleting files in downloadDir
		files = glob.glob(downloadDir + DIR_SEP + '*')
		
		for f in files:
			os.remove(f)
		
		guiOutput = GuiOutputStub()
		youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
		playlistUrl = "https://www.youtube.com/playlist?list=PLzwWSJNcZTMSFWGrRGKOypqN29MlyuQvn"
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, downloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		downloadVideoInfoDic, accessError = youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(playlistUrl, downloadVideoInfoDic)
		targetAudioDir = downloadVideoInfoDic.getPlaylistDownloadDir()

		sys.stdout = stdout
		
		self.assertIsNone(accessError)
		self.assertEqual(
			['downloading "Wear a mask. Help slow the spread of Covid-19." audio ...',
			 '',
			 '"Wear a mask. Help slow the spread of Covid-19." audio downloaded.',
			 '',
			 'downloading "Here to help: Give him what he wants" audio ...',
			 '',
			 '"Here to help: Give him what he wants" audio downloaded.',
			 '',
			 '"test_audio_downloader_two_files_with_time_frames" playlist audio(s) download terminated.',
			 '',
			 ''], outputCapturingString.getvalue().split('\n'))
		
		# playlist title: test_audio_downloader_two_files_with_time_frames
		# (e0:0:2-0:0:8) (s0:0:2-0:0:5 s0:0:7-0:0:10)
		startEndSecondsList_extract_firstVideo_firstTimeFrame = [2, 8]
		
		startEndSecondsList_suppress_secondVideo_firstTimeFrame = [2, 5]
		startEndSecondsList_suppress_secondVideo_secondTimeFrame = [7, 10]
		
		self.assertEqual([startEndSecondsList_extract_firstVideo_firstTimeFrame],
		                 downloadVideoInfoDic.getExtractStartEndSecondsListsForVideoIndex(1))
		self.assertEqual([],
		                 downloadVideoInfoDic.getSuppressStartEndSecondsListsForVideoIndex(1))
		
		self.assertEqual([],
		                 downloadVideoInfoDic.getExtractStartEndSecondsListsForVideoIndex(2))
		self.assertEqual([startEndSecondsList_suppress_secondVideo_firstTimeFrame,
		                  startEndSecondsList_suppress_secondVideo_secondTimeFrame],
		                 downloadVideoInfoDic.getSuppressStartEndSecondsListsForVideoIndex(2))
		
		self.assertEqual(downloadDir, targetAudioDir)
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19.',
		                 downloadVideoInfoDic.getVideoTitleForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk',
		                 downloadVideoInfoDic.getVideoUrlForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk',
		                 downloadVideoInfoDic.getVideoUrlForVideoTitle(
			                 'Wear a mask. Help slow the spread of Covid-19.'))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3',
		                 downloadVideoInfoDic.getVideoFileNameForVideoIndex(1))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3',
		                 downloadVideoInfoDic.getVideoFileNameForVideoTitle(
			                 'Wear a mask. Help slow the spread of Covid-19.'))
		
		self.assertEqual('Here to help: Give him what he wants',
		                 downloadVideoInfoDic.getVideoTitleForVideoIndex(2))
		self.assertEqual('https://www.youtube.com/watch?v=Eqy6M6qLWGw',
		                 downloadVideoInfoDic.getVideoUrlForVideoIndex(2))
		self.assertEqual('https://www.youtube.com/watch?v=Eqy6M6qLWGw',
		                 downloadVideoInfoDic.getVideoUrlForVideoTitle('Here to help: Give him what he wants'))
		self.assertEqual('Here to help - Give him what he wants.mp3',
		                 downloadVideoInfoDic.getVideoFileNameForVideoIndex(2))
		self.assertEqual('Here to help - Give him what he wants.mp3',
		                 downloadVideoInfoDic.getVideoFileNameForVideoTitle(
			                 'Here to help: Give him what he wants'))
		
		self.assertEqual(['1', '2'], downloadVideoInfoDic.getVideoIndexes())
		
		fileNameLst = [x.split(DIR_SEP)[-1] for x in glob.glob(downloadDir + DIR_SEP + '*.*')]
		self.assertEqual(
			sorted(['Here to help - Give him what he wants.mp3',
			        'Wear a mask. Help slow the spread of Covid-19..mp3',
			        'test_audio_downloader_two_files_with_time_frames_dic.txt']), sorted(fileNameLst))

		# re-downloading the playlist
		
		youtubeAccess_redownload = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
		
		stdout = sys.stdout
		outputCapturingString = StringIO()
		sys.stdout = outputCapturingString
		
		_, redownloadVideoInfoDic, _, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(playlistUrl)
		redownloadVideoInfoDic, accessError = youtubeAccess.downloadVideosReferencedInPlaylistForPlaylistUrl(playlistUrl, redownloadVideoInfoDic)
		targetAudioDir = downloadVideoInfoDic.getPlaylistDownloadDir()

		sys.stdout = stdout
		
		self.assertIsNone(accessError)
		self.assertEqual(['"Wear a mask. Help slow the spread of Covid-19." audio already downloaded. '
 'Video skipped.',
 '',
 '"Here to help: Give him what he wants" audio already downloaded. Video '
 'skipped.',
 '',
 '"test_audio_downloader_two_files_with_time_frames" playlist audio(s) '
 'download terminated.',
 '',
 ''], outputCapturingString.getvalue().split('\n'))
		
		self.assertEqual([startEndSecondsList_extract_firstVideo_firstTimeFrame],
		                 redownloadVideoInfoDic.getExtractStartEndSecondsListsForVideoIndex(1))
		self.assertEqual([],
		                 redownloadVideoInfoDic.getSuppressStartEndSecondsListsForVideoIndex(1))
		
		self.assertEqual([],
		                 redownloadVideoInfoDic.getExtractStartEndSecondsListsForVideoIndex(2))
		self.assertEqual([startEndSecondsList_suppress_secondVideo_firstTimeFrame,
		                  startEndSecondsList_suppress_secondVideo_secondTimeFrame],
		                 redownloadVideoInfoDic.getSuppressStartEndSecondsListsForVideoIndex(2))
		
		self.assertEqual(downloadDir, targetAudioDir)
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19.',
		                 redownloadVideoInfoDic.getVideoTitleForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk',
		                 redownloadVideoInfoDic.getVideoUrlForVideoIndex(1))
		self.assertEqual('https://www.youtube.com/watch?v=9iPvLx7gotk',
		                 redownloadVideoInfoDic.getVideoUrlForVideoTitle(
			                 'Wear a mask. Help slow the spread of Covid-19.'))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoIndex(1))
		self.assertEqual('Wear a mask. Help slow the spread of Covid-19..mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoTitle(
			                 'Wear a mask. Help slow the spread of Covid-19.'))
		
		self.assertEqual('Here to help: Give him what he wants',
		                 redownloadVideoInfoDic.getVideoTitleForVideoIndex(2))
		self.assertEqual('https://www.youtube.com/watch?v=Eqy6M6qLWGw',
		                 redownloadVideoInfoDic.getVideoUrlForVideoIndex(2))
		self.assertEqual('https://www.youtube.com/watch?v=Eqy6M6qLWGw',
		                 redownloadVideoInfoDic.getVideoUrlForVideoTitle('Here to help: Give him what he wants'))
		self.assertEqual('Here to help - Give him what he wants.mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoIndex(2))
		self.assertEqual('Here to help - Give him what he wants.mp3',
		                 redownloadVideoInfoDic.getVideoFileNameForVideoTitle(
			                 'Here to help: Give him what he wants'))
		
		self.assertEqual(['1', '2'], redownloadVideoInfoDic.getVideoIndexes())
		
		fileNameLst = [x.split(DIR_SEP)[-1] for x in glob.glob(downloadDir + DIR_SEP + '*.*')]
		self.assertEqual(
			sorted(['Here to help - Give him what he wants.mp3',
			        'Wear a mask. Help slow the spread of Covid-19..mp3',
			        'test_audio_downloader_two_files_with_time_frames_dic.txt']), sorted(fileNameLst))
Ejemplo n.º 11
0
    def testDownloadSingleVideoForUrl_succeed_on_Windows_only(self):
        """
		As unit test, works on Android although the downloaded file is not fully valid:
		can be played, but without setting position.
		"""
        expectedVideoTitle = 'Is NEO Worth Buying? - Price Prediction 2020/2021 🚀🚀🚀'
        audioSubDirName = 'Various_test'
        downloadDir = AUDIO_DIR_TEST + DIR_SEP + audioSubDirName

        if not os.path.exists(downloadDir):
            os.mkdir(downloadDir)

        # deleting files in downloadDir
        files = glob.glob(downloadDir + DIR_SEP + '*')

        for f in files:
            os.remove(f)

        guiOutput = GuiOutputStub()
        youtubeAccess = YoutubeDlAudioDownloader(guiOutput, AUDIO_DIR_TEST)
        videoUrl = "https://youtu.be/LhH9uX3kgTI"

        stdout = sys.stdout
        outputCapturingString = StringIO()
        sys.stdout = outputCapturingString

        _, downloadVideoInfoDic, videoTitle, accessError = youtubeAccess.getDownloadVideoInfoDicOrSingleVideoTitleFortUrl(
            videoUrl)

        self.assertIsNone(downloadVideoInfoDic)
        self.assertIsNone(accessError)
        self.assertEqual(expectedVideoTitle, videoTitle)

        youtubeAccess.downloadSingleVideoForUrl(videoUrl, videoTitle,
                                                downloadDir)

        sys.stdout = stdout

        if os.name == 'posix':
            self.assertEqual([
                'downloading "Is NEO Worth Buying? - Price Prediction 2020/2021 🚀🚀🚀" audio '
                '...', '',
                '"Is NEO Worth Buying? - Price Prediction 2020/2021 🚀🚀🚀" audio downloaded in '
                'test/Various_test directory.', '', ''
            ],
                             outputCapturingString.getvalue().split('\n'))
        else:
            self.assertEqual([
                'downloading "Is NEO Worth Buying? - Price Prediction 2020/2021 🚀🚀🚀" audio '
                '...', '',
                '"Is NEO Worth Buying? - Price Prediction 2020/2021 🚀🚀🚀" audio downloaded in '
                'test\\Various_test directory.', '', ''
            ],
                             outputCapturingString.getvalue().split('\n'))

        if os.name == 'posix':
            self.assertEqual(
                '/storage/emulated/0/Download/Audiobooks/test/' +
                audioSubDirName, downloadDir)
        else:
            self.assertEqual(
                'D:\\Users\\Jean-Pierre\\Downloads\\Audiobooks\\test\\' +
                audioSubDirName, downloadDir)

        fileNameLst = [
            x.split(DIR_SEP)[-1]
            for x in glob.glob(downloadDir + DIR_SEP + '*.*')
        ]
        self.assertEqual(
            sorted([
                'Is NEO Worth Buying - Price Prediction 2020_2021 🚀🚀🚀.mp3'
            ]), sorted(fileNameLst))