Esempio n. 1
0
        def get_info(self):
            if self.type in ("f", "u"):
                if not os.path.exists(self.source):
                    return
                song = mutagen.File(self.source, None, True)
                if song is None:
                    return
                tags = song.tags
                if tags is None:
                    return
                else:
                    if '.flac' in self.source:
                        artist = tags.get("ARTIST")
                        title = tags.get("TITLE")
                    else:
                        artist = tags.get("artist")
                        title = tags.get("title")

                    if artist is not None and len(artist) > 0:
                        self.artist = artist[0]
                    if title is not None and len(title) > 0:
                        self.title = title[0]
            elif self.type in ("yt"):
                info = youtube_search.YoutubeSearch(self.source,
                                                    max_results=1).to_dict()[0]
                # self.artist = info.get("channel")
                self.title = info.get("title")
Esempio n. 2
0
def searchCurrent():
    chn = Channel.objects.filter(
        channelStatus='trusted').order_by('-channelSubscriberCount')
    query = [
        'Ethiopian Music', 'Ethiopian Movie', 'Ethiopian News',
        'Ethiopian Mezmur'
    ]
    chn_list = list(ch.channelTitle for ch in chn)
    querys = chn_list + query

    b = {}
    for query in querys:
        print('Querying 📺📺📺 = ' + query)
        b = youtube_search.YoutubeSearch(credenentials_path, query, max_result,
                                         '', published_after, published_before)

        new_videos = (o['videoId'] for o in b.response)
        new_videoIds = list(new_videos)
        diff = list(set(new_videoIds) - set(saved_videoIds))
        for row in b.response:
            if row['videoId'] in diff:
                print("i found it! 😅😅😅" + row['videoId'])
                save(row)

    searchFinished()
Esempio n. 3
0
 def search(self, search_phrase):
     """Returns a list of tuples containing TITLE, DURATION, URL_SUFFIX,
        and THUMBNAIL_URL of the videos searched for"""
     results = youtube_search.YoutubeSearch(search_phrase).to_dict()
     video_data = [(v['title'], v['duration'], v['url_suffix'],
                    v['thumbnails'][0]) for v in results]
     return video_data
Esempio n. 4
0
def search(next_page_token):
    print('Next ' + next_page_token)

    chn = Channel.objects.filter(channelStatus='trusted')
    chn_list = []
    querys = [
        'Ethiopian Music', 'Ethiopian Movie', 'Ethiopian News',
        'Ethiopian Mezmur'
    ]
    for ch in chn:
        chn_list.append(ch.channelTitle)

    querys = querys + chn_list

    b = {}
    for query in querys:
        print('Querying = ' + query)
        b = youtube_search.YoutubeSearch(credenentials_path, query, max_result,
                                         next_page_token, published_after,
                                         published_before)
        process(b.response)

    if b:
        #        search(b.response[0]['nextPageToken'])
        searchUpdateFinished(b.response[0]['nextPageToken'])
    else:
        searchUpdateFinished(next_page_token)
Esempio n. 5
0
def search(next_page_token, published_after):
    chn = Channel.objects.filter(
        channelStatus='trusted').order_by('-channelSubscriberCount')
    #    query=['Ethiopian Music','Ethiopian Movie','Ethiopian News','Ethiopian Mezmur']

    chn_list = list(ch.channelTitle for ch in chn)
    querys = chn_list
    #+query

    b = {}
    for query in querys:
        print('Querying = ' + query)

        b = youtube_search.YoutubeSearch(credenentials_path, query, max_result,
                                         next_page_token, published_after,
                                         published_before)

        new_videos = (o['videoId'] for o in b.response)
        new_videoIds = list(new_videos)

        print(
            "------------------------------------------------------------------"
        )

        for row in b.response:
            if row['videoId'] in saved_videoIds:
                update(row)
def get_url_from_song_name(song_name: str) -> str:
    """
    This function return the url in youtube that play the selected song
    :param song_name: The name of the selected song
    :return: The url of the selected song
    """
    results = youtube_search.YoutubeSearch(song_name).to_dict()
    return BASE_YOUTUBE_URL + results[0][URL_KEY]
Esempio n. 7
0
def getTriler(name):
    results = youtube_search.YoutubeSearch(
        name + " trailer", max_results=10).to_dict()  #lista de dictionare
    x = results[1]
    print(type(x))
    link = 'https://www.youtube.com/' + x['url_suffix']
    print(link)
    return (link)
Esempio n. 8
0
def search_youtube(request):
    query = request.GET.get('search')

    b = {}
    if query:
        b = youtube_search.YoutubeSearch(settings.CREDENTIALS_PATH, query, 50,
                                         '', '', 'date').response

    top_list = Video.objects.filter(
        Q(publishedAt__gte=now - timedelta(days=datetime.today().weekday()))
        & (Q(status='downloaded')
           | Q(channel__channelStatus='trusted'))).order_by('-view_count')

    context = {
        'video_list': b,
        'top_list': top_list[:10],
    }
    template = loader.get_template('search.html')
    return HttpResponse(template.render(context, request))
Esempio n. 9
0
    def play_youtube(self,video_name):
        """
        -----------------------------------------------------------------------------------
        Bi.play_youtube(self, video_name):

        # Params: video_name là tên video muốn mở
        # Chức năng: mở video đầu tiên tìm được trong tab mới bằng google chrome
        # Trả về: text thông báo kết quả
            + thành công: text='Tôi mở rồi đấy. Mời bạn thưởng thức nhá'
            + exception: text='Hình như hết tiền mạng rồi :D'
        -----------------------------------------------------------------------------------
        """
        self.speak('Chờ chút có ngay')
        try:
            video = youtube_search.YoutubeSearch(video_name, max_results=1).to_dict()
            webbrowser.register('chrome',None,webbrowser.BackgroundBrowser("C:\Program Files\Google\Chrome\Application\chrome.exe"))
            webbrowser.get('chrome').open_new_tab('https://www.youtube.com/watch?v='+video[0]['id'])
            return self.multiprocess_speak('Tôi mở rồi đấy. Mời bạn thưởng thức nhá')
        except Exception as e:
            return self.multiprocess_speak("Hình như hết tiền mạng rồi :D")
Esempio n. 10
0
 def search(self, search_terms):
     self.search_results = youtube_search.YoutubeSearch(
         search_terms, max_results=5).to_dict()
Esempio n. 11
0
def search():
    b = youtube_search.YoutubeSearch(credenentials_path, query, max_result,
                                     next_page_token, '', published_before)
    return b.response
Esempio n. 12
0
def search(query: str, N=5):  #returns list[{title, link, id}]
    results = youtube_search.YoutubeSearch(query, N).to_dict()
    #TODO return video duration
    return results
Esempio n. 13
0
                print(" ")
                ydl.download([link])
                print(" ")
        elif "https://cdn.discordapp.com/attachments/" in link:
            name=link.split("/")
            name=name[-1]
            name=name.split(".")
            extlink=name[-1]
            name=name[0]
            ext="mp3"
            if extlink == "png" or extlink == "jpg":
                ext="png"
            print(" ")
            os.system(f"curl {link} -o {name}.{ext}")
            print(" ")
        elif "https://open.spotify.com/track/" in link:
            r=requests.get(link)
            content=(r.text).splitlines()
            content=content[0]
            titlestart=content.find("<title>")
            titleend=content.find("</title>")
            name=content[titlestart+7:titleend]
            search=(youtube_search.YoutubeSearch(name, max_results=1).to_dict()[0])["url_suffix"]
            ytlink=(f"https://www.youtube.com{search}")
            with youtube_dl.YoutubeDL(ydl_opts) as ydl:
                print(" ")
                ydl.download([ytlink])
                print(" ")
    except:
        print("\nPlease Try Again\n")