1

I'm trying to retrieve the @ from a string, for example: https://prnt.sc/DLoqh8x5L0EB

I'm currently retrieving the IDs, but it would save me a lot of time to be able to retrieve the @s to copy and paste the youtube links into my storage file.

I'd like to specify that I want to retrieve the tag and id so that I can use it in my data.yml, not to display it, since I'm already displaying the ID for strings with an ID. Ideally, I'd like to display the TAG, but as a first step, if my data.yml can retrieve a URL containing a tag, that would be a big step.

The aim is to quickly retrieve public information in order to develop a communication campaign. I have a "data.yml" storage file to store youtube channel links. as well as a result file to use these results

I want to retrieve the @ (TAG) as well as the ID because some channels still have the ID and it would save me time to have them both. Example : ID = AUIGDHBNDJ18632Y1NS @ or TAG = @MrBeast

I've tried various things but nothing conclusive. I've been working on this project for say 2 - 3 days and I'm completely at a loss if anyone has a solution I'd love to hear from you.

with open('data/data.yml', 'r') as yaml_file:
    data = yaml.safe_load(yaml_file)

channel_urls = [channel['url'] for channel in data['channels']]

youtube = build('youtube', 'v3', developerKey=api_key)
channel_results = []

for channel_url in channel_urls:
    channel_id = channel_url.split('/')[-1]

    try:
        # Votre code existant pour récupérer les informations de la chaîne

        channel_info = {
            'url': channel_url,
            'id': channel_id,
            # Autres informations de la chaîne récupérées
        }

        channel_results.append(channel_info)

        # Affichage des informations de la chaîne
        print(f"Nombre de chaînes : {len(channel_results)}\n")
        print("URL de la chaîne :", channel_url)
        print("ID de la chaîne :", channel_id)
        # Autres informations à afficher

        print()

    except Exception as e:
        print("Une erreur s'est produite lors de la récupération des informations de la chaîne :", channel_url)
        print("Erreur :", str(e))
        print()

# Écrire le nombre de chaînes en première ligne du fichier résultat
with open('output/channel_results.yml', 'w', encoding='utf-8') as yaml_file:
    yaml_file.write(f"Nombre de chaînes : {len(channel_results)}\n")
    yaml.dump({'channels': channel_results}, yaml_file, allow_unicode=True)
Benjamin Loison
  • 3,782
  • 4
  • 16
  • 33
  • Does [this answer](https://stackoverflow.com/a/75843807) solve your problem? – Benjamin Loison Jun 22 '23 at 16:33
  • No sorry, I tried with "etag" https://sourceb.in/taqXS3LBqC – JasonStatham Jun 22 '23 at 20:30
  • I don't understand what your question has to do with [etags](https://developers.google.com/youtube/v3/getting-started#etags), can you elaborate on that? – Benjamin Loison Jun 22 '23 at 20:34
  • The etag is the @, right? – JasonStatham Jun 22 '23 at 20:44
  • No, that's a [YouTube handle](https://www.youtube.com/handle). Can you elaborate on what you mean by [*I tried with *YouTube handle**](https://stackoverflow.com/questions/76528980/get-the-of-a-youtube-channel-with-python-and-the-youtube-data-v3-api#comment134944730_76528980)? – Benjamin Loison Jun 22 '23 at 20:46
  • I don't think I mentioned youtube handle because I didn't know it was called that, but I'd like to get it as I explained so that I can put youtube handles directly in my data.yml file instead of just IDs. – JasonStatham Jun 22 '23 at 20:50
  • I've tried regular expressions but I don't know what to do anymore. – JasonStatham Jun 22 '23 at 21:14

0 Answers0