def test_download_from_list_without_youtube_api(self):
     expect_title = "1. Tony's Videos VERY SHORT VIDEO 28.10.2016"
     const.args.youtube_api_key = None
     youtube_tools.set_api_key()
     content = youtube_tools.go_pafy(raw_song, metadata)
     title = youtube_tools.get_youtube_title(content, 1)
     assert title == expect_title
Exemplo n.º 2
0
    def download_single(self):
        """ Logic behind downloading a song. """

        if self._to_skip():
            return

        # "[number]. [artist] - [song]" if downloading from list
        # otherwise "[artist] - [song]"
        youtube_title = youtube_tools.get_youtube_title(
            self.content, self.number)
        log.info("{} ({})".format(youtube_title, self.content.watchv_url))

        # generate file name of the song to download
        songname = self.refine_songname(self.content.title)

        if const.args.dry_run:
            return

        song_existence = downloader.CheckExists(songname, self.meta_tags)
        if not song_existence.already_exists(self.raw_song):
            down_song = self._download_single(songname)
            if down_song:
                rs.songPusher.put([
                    'track', songname + const.args.output_ext, self.raw_song,
                    self.meta_tags, const.args
                ])
            return down_song
        else:
            rs.songPusher.put([
                'track', songname + const.args.output_ext, self.raw_song,
                self.meta_tags, const.args
            ])
 def test_download_from_list_without_youtube_api(self, metadata_fixture,
                                                 content_fixture):
     const.args.youtube_api_key = None
     youtube_tools.set_api_key()
     content_fixture = youtube_tools.go_pafy(TRACK_SEARCH, metadata_fixture)
     title = youtube_tools.get_youtube_title(content_fixture, 1, 1)
     assert title == "1/1: {0}".format(EXPECTED_TITLE)
Exemplo n.º 4
0
 def test_single_download_with_youtube_api(self):
     global content
     global title
     const.args.youtube_api_key = YT_API_KEY
     youtube_tools.set_api_key()
     content = youtube_tools.go_pafy(TRACK_SEARCH, metadata)
     title = youtube_tools.get_youtube_title(content)
     assert title == EXPECTED_TITLE
 def test_single_download_with_youtube_api(self):
     global content
     global title
     expect_title = "Tony's Videos VERY SHORT VIDEO 28.10.2016"
     key = 'AIzaSyAnItl3udec-Q1d5bkjKJGL-RgrKO_vU90'
     const.args.youtube_api_key = key
     youtube_tools.set_api_key()
     content = youtube_tools.go_pafy(raw_song, metadata)
     title = youtube_tools.get_youtube_title(content)
     assert title == expect_title
Exemplo n.º 6
0
def test_youtube_title(metadata_fixture, monkeypatch):
    monkeypatch.setattr(
        youtube_tools.GenerateYouTubeURL,
        "_fetch_response",
        loader.monkeypatch_youtube_search_page,
    )
    content = youtube_tools.go_pafy(SPOTIFY_TRACK_URL, metadata_fixture)
    pytest.content_fixture = content
    title = youtube_tools.get_youtube_title(content)
    assert title == EXPECTED_YOUTUBE_TITLE
Exemplo n.º 7
0
    def download_single(self):
        """ Logic behind downloading a song. """

        if self._to_skip():
            return

        # "[number]. [artist] - [song]" if downloading from list
        # otherwise "[artist] - [song]"
        youtube_title = youtube_tools.get_youtube_title(self.content, self.number)
        log.info("{} ({})".format(youtube_title, self.content.watchv_url))
        sys.stdout.flush()

        # generate file name of the song to download
        songname = self.refine_songname(self.content.title)

        if const.args.dry_run:
            return

        song_existence = CheckExists(songname, self.meta_tags)
        if not song_existence.already_exists(self.raw_song):
            return self._download_single(songname)
Exemplo n.º 8
0
def title_fixture(content_fixture):
    title = youtube_tools.get_youtube_title(content_fixture)
    return title
def test_youtube_title():
    global content
    content = youtube_tools.go_pafy(TRACK_URL, meta_tags)
    title = youtube_tools.get_youtube_title(content)
    assert title == EXPECTED_YT_TITLE
Exemplo n.º 10
0
def download_single(raw_song, number=None):
    """ Logic behind downloading a song. """

    if internals.is_youtube(raw_song):
        log.debug('Input song is a YouTube URL')
        content = youtube_tools.go_pafy(raw_song, meta_tags=None)
        raw_song = slugify(content.title).replace('-', ' ')
        meta_tags = spotify_tools.generate_metadata(raw_song)
    else:
        meta_tags = spotify_tools.generate_metadata(raw_song)
        content = youtube_tools.go_pafy(raw_song, meta_tags)

    if content is None:
        log.debug('Found no matching video')
        return

    if const.args.download_only_metadata and meta_tags is None:
        log.info('Found no metadata. Skipping the download')
        return

    # "[number]. [artist] - [song]" if downloading from list
    # otherwise "[artist] - [song]"
    youtube_title = youtube_tools.get_youtube_title(content, number)
    log.info('{} ({})'.format(youtube_title, content.watchv_url))

    # generate file name of the song to download
    songname = content.title

    if meta_tags is not None:
        refined_songname = internals.format_string(const.args.file_format,
                                                   meta_tags,
                                                   slugification=True)
        log.debug('Refining songname from "{0}" to "{1}"'.format(
            songname, refined_songname))
        if not refined_songname == ' - ':
            songname = refined_songname
    else:
        log.warning('Could not find metadata')
        songname = internals.sanitize_title(songname)

    if const.args.dry_run:
        return

    if not check_exists(songname, raw_song, meta_tags):
        # deal with file formats containing slashes to non-existent directories
        songpath = os.path.join(const.args.folder, os.path.dirname(songname))
        os.makedirs(songpath, exist_ok=True)
        input_song = songname + const.args.input_ext
        output_song = songname + const.args.output_ext
        if youtube_tools.download_song(input_song, content):
            try:
                convert.song(input_song,
                             output_song,
                             const.args.folder,
                             avconv=const.args.avconv,
                             trim_silence=const.args.trim_silence)
            except FileNotFoundError:
                encoder = 'avconv' if const.args.avconv else 'ffmpeg'
                log.warning(
                    'Could not find {0}, skipping conversion'.format(encoder))
                const.args.output_ext = const.args.input_ext
                output_song = songname + const.args.output_ext

            if not const.args.input_ext == const.args.output_ext:
                os.remove(os.path.join(const.args.folder, input_song))
            if not const.args.no_metadata and meta_tags is not None:
                metadata.embed(os.path.join(const.args.folder, output_song),
                               meta_tags)
            return True
Exemplo n.º 11
0
def download_single(raw_song, number=None):
    """ Logic behind downloading a song. """
    content, meta_tags = youtube_tools.match_video_and_metadata(raw_song)

    if content is None:
        log.debug("Found no matching video")
        return

    if const.args.download_only_metadata and meta_tags is None:
        log.info("Found no metadata. Skipping the download")
        return

    # "[number]. [artist] - [song]" if downloading from list
    # otherwise "[artist] - [song]"
    youtube_title = youtube_tools.get_youtube_title(content, number)
    log.info("{} ({})".format(youtube_title, content.watchv_url))

    # generate file name of the song to download
    songname = content.title

    if meta_tags is not None:
        refined_songname = internals.format_string(const.args.file_format,
                                                   meta_tags,
                                                   slugification=True)
        log.debug('Refining songname from "{0}" to "{1}"'.format(
            songname, refined_songname))
        if not refined_songname == " - ":
            songname = refined_songname
    else:
        if not const.args.no_metadata:
            log.warning("Could not find metadata")
        songname = internals.sanitize_title(songname)

    if const.args.dry_run:
        return

    if not check_exists(songname, raw_song, meta_tags):
        # deal with file formats containing slashes to non-existent directories
        songpath = os.path.join(const.args.folder, os.path.dirname(songname))
        os.makedirs(songpath, exist_ok=True)
        input_song = songname + const.args.input_ext
        output_song = songname + const.args.output_ext
        if youtube_tools.download_song(input_song, content):
            print("")
            try:
                convert.song(
                    input_song,
                    output_song,
                    const.args.folder,
                    avconv=const.args.avconv,
                    trim_silence=const.args.trim_silence,
                )
            except FileNotFoundError:
                encoder = "avconv" if const.args.avconv else "ffmpeg"
                log.warning(
                    "Could not find {0}, skipping conversion".format(encoder))
                const.args.output_ext = const.args.input_ext
                output_song = songname + const.args.output_ext

            if not const.args.input_ext == const.args.output_ext:
                os.remove(os.path.join(const.args.folder, input_song))
            if not const.args.no_metadata and meta_tags is not None:
                metadata.embed(os.path.join(const.args.folder, output_song),
                               meta_tags)
            return True
Exemplo n.º 12
0
def test_youtube_title():
    expect_title = 'Intro - David André Østby'
    global content
    content = youtube_tools.go_pafy(raw_song, meta_tags)
    title = youtube_tools.get_youtube_title(content)
    assert title == expect_title