Repository: yt-dlp/yt-dlp

Issue:
LastFM support
### Checklist

- [X] I'm reporting a new site support request
- [X] I've verified that I'm running yt-dlp version **2022.02.04**. ([update instructions](https://github.com/yt-dlp/yt-dlp#update))
- [X] I've checked that all provided URLs are alive and playable in a browser
- [X] I've checked that none of provided URLs [violate any copyrights](https://github.com/ytdl-org/youtube-dl#can-you-add-support-for-this-anime-video-site-or-site-which-shows-current-movies-for-free) or contain any [DRM](https://en.wikipedia.org/wiki/Digital_rights_management) to the best of my knowledge
- [X] I've searched the [bugtracker](https://github.com/yt-dlp/yt-dlp/issues?q=) for similar issues including closed ones. DO NOT post duplicates
- [X] I've read the [guidelines for opening an issue](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#opening-an-issue)
- [X] I've read about [sharing account credentials](https://github.com/yt-dlp/yt-dlp/blob/master/CONTRIBUTING.md#are-you-willing-to-share-account-details-if-needed) and am willing to share it if required

### Region

France

### Example URLs

- Single audio : https://www.last.fm/music/The+Postal+Service/_/Such+Great+Heights
- Playlist : https://www.last.fm/tag/rock/tracks
- Artist page : https://www.last.fm/music/Nirvana

### Description

It look like last fm play music from youtube as a visitor (cf screenshot)
![image](https://user-images.githubusercontent.com/25008828/156901810-3865a4e6-63ab-49fd-8518-737ae3c5bc0f.png)

so it should be possible to fallback to youtube extractor somehow ?

### Verbose log

```shell
[debug] Command-line config: ['https://www.last.fm/music/The+Postal+Service/_/Such+Great+Heights', '-vU']
[debug] Encodings: locale cp1252, fs utf-8, out utf-8, err utf-8, pref cp1252
[debug] yt-dlp version 2022.02.04 [c1653e9ef]
[debug] Python version 3.9.9 (CPython 64bit) - Windows-10-10.0.19044-SP0
[debug] exe versions: ffmpeg 4.4-essentials_build-www.gyan.dev (setts), ffprobe 4.4-essentials_build-www.gyan.dev
[debug] Optional libraries: Cryptodome, mutagen, sqlite, websockets
[debug] Proxy map: {}
Latest version: 2022.02.04, Current version: 2022.02.04
yt-dlp is up to date (2022.02.04)
[debug] [generic] Extracting URL: https://www.last.fm/music/The+Postal+Service/_/Such+Great+Heights
[generic] Such+Great+Heights: Requesting header
WARNING: [generic] Falling back on generic information extractor.
[generic] Such+Great+Heights: Downloading webpage
[generic] Such+Great+Heights: Extracting information
[debug] Looking for video embeds
ERROR: Unsupported URL: https://www.last.fm/music/The+Postal+Service/_/Such+Great+Heights
Traceback (most recent call last):
  File "C:\Users\dysta\AppData\Local\Programs\Python\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 1381, in wrapper
    return func(self, *args, **kwargs)
  File "C:\Users\dysta\AppData\Local\Programs\Python\Python39\lib\site-packages\yt_dlp\YoutubeDL.py", line 1451, in __extract_info
    ie_result = ie.extract(url)
  File "C:\Users\dysta\AppData\Local\Programs\Python\Python39\lib\site-packages\yt_dlp\extractor\common.py", line 612, in extract
    ie_result = self._real_extract(url)
  File "C:\Users\dysta\AppData\Local\Programs\Python\Python39\lib\site-packages\yt_dlp\extractor\generic.py", line 3986, in _real_extract
    raise UnsupportedError(url)
yt_dlp.utils.UnsupportedError: Unsupported URL: https://www.last.fm/music/The+Postal+Service/_/Such+Great+Heights
```



Discussion:

Resolving patch:
diff --git a/yt_dlp/extractor/extractors.py b/yt_dlp/extractor/extractors.py
--- a/yt_dlp/extractor/extractors.py
+++ b/yt_dlp/extractor/extractors.py
@@ -731,6 +731,11 @@
     EHFTVIE,
     ITTFIE,
 )
+from .lastfm import (
+    LastFMIE,
+    LastFMPlaylistIE,
+    LastFMUserIE,
+)
 from .lbry import (
     LBRYIE,
     LBRYChannelIE,
diff --git a/yt_dlp/extractor/lastfm.py b/yt_dlp/extractor/lastfm.py
new file mode 100644
--- /dev/null
+++ b/yt_dlp/extractor/lastfm.py
@@ -0,0 +1,129 @@
+# coding: utf-8
+from __future__ import unicode_literals
+
+import re
+
+from .common import InfoExtractor
+from ..utils import int_or_none, format_field
+
+
+class LastFMPlaylistBaseIE(InfoExtractor):
+    def _entries(self, url, playlist_id):
+        webpage = self._download_webpage(url, playlist_id)
+        start_page_number = int_or_none(self._search_regex(
+            r'\bpage=(\d+)', url, 'page', default=None)) or 1
+        last_page_number = int_or_none(self._search_regex(
+            r'>(\d+)</a>[^<]*</li>[^<]*<li[^>]+class="pagination-next', webpage, 'last_page', default=None))
+
+        for page_number in range(start_page_number, (last_page_number or start_page_number) + 1):
+            webpage = self._download_webpage(
+                url, playlist_id,
+                note='Downloading page %d%s' % (page_number, format_field(last_page_number, template=' of %d')),
+                query={'page': page_number})
+            page_entries = [
+                self.url_result(player_url, 'Youtube')
+                for player_url in set(re.findall(r'data-youtube-url="([^"]+)"', webpage))
+            ]
+
+            for e in page_entries:
+                yield e
+
+    def _real_extract(self, url):
+        playlist_id = self._match_id(url)
+        return self.playlist_result(self._entries(url, playlist_id), playlist_id)
+
+
+class LastFMPlaylistIE(LastFMPlaylistBaseIE):
+    _VALID_URL = r'https?://(?:www\.)?last\.fm/(music|tag)/(?P<id>[^/]+)(?:/[^/]+)?/?(?:[?#]|$)'
+    _TESTS = [{
+        'url': 'https://www.last.fm/music/Oasis/(What%27s+the+Story)+Morning+Glory%3F',
+        'info_dict': {
+            'id': 'Oasis',
+        },
+        'playlist_count': 11,
+    }, {
+        'url': 'https://www.last.fm/music/Oasis',
+        'only_matching': True,
+    }, {
+        'url': 'https://www.last.fm/music/Oasis/',
+        'only_matching': True,
+    }, {
+        'url': 'https://www.last.fm/music/Oasis?top_tracks_date_preset=ALL#top-tracks',
+        'only_matching': True,
+    }, {
+        'url': 'https://www.last.fm/music/Oasis/+tracks',
+        'only_matching': True,
+    }, {
+        'url': 'https://www.last.fm/music/Oasis/+tracks?page=2',
+        'only_matching': True,
+    }, {
+        'url': 'https://www.last.fm/music/Oasis/+tracks?date_preset=LAST_90_DAYS#top-tracks',
+        'only_matching': True,
+    }, {
+        'url': 'https://www.last.fm/tag/rock',
+        'only_matching': True,
+    }, {
+        'url': 'https://www.last.fm/tag/rock/tracks',
+        'only_matching': True,
+    }]
+
+
+class LastFMUserIE(LastFMPlaylistBaseIE):
+    _VALID_URL = r'https?://(?:www\.)?last\.fm/user/[^/]+/playlists/(?P<id>[^/#?]+)'
+    _TESTS = [{
+        'url': 'https://www.last.fm/user/mehq/playlists/12319471',
+        'info_dict': {
+            'id': '12319471',
+        },
+        'playlist_count': 30,
+    }]
+
+
+class LastFMIE(InfoExtractor):
+    _VALID_URL = r'https?://(?:www\.)?last\.fm/music(?:/[^/]+){2}/(?P<id>[^/#?]+)'
+    _TESTS = [{
+        'url': 'https://www.last.fm/music/Oasis/_/Wonderwall',
+        'md5': '9c4a70c2e84c03d54fe24229b9e13b7b',
+        'info_dict': {
+            'id': '6hzrDeceEKc',
+            'ext': 'mp4',
+            'title': 'Oasis - Wonderwall  (Official Video)',
+            'thumbnail': r're:^https?://i.ytimg.com/.*\.jpg$',
+            'description': 'md5:0848669853c10687cc28e88b5756738f',
+            'uploader': 'Oasis',
+            'uploader_id': 'oasisinetofficial',
+            'upload_date': '20080207',
+            'album': '(What\'s The Story) Morning Glory? (Remastered)',
+            'track': 'Wonderwall (Remastered)',
+            'channel_id': 'UCUDVBtnOQi4c7E8jebpjc9Q',
+            'view_count': int,
+            'live_status': 'not_live',
+            'channel_url': 'https://www.youtube.com/channel/UCUDVBtnOQi4c7E8jebpjc9Q',
+            'tags': 'count:39',
+            'creator': 'Oasis',
+            'uploader_url': 're:^https?://www.youtube.com/user/oasisinetofficial',
+            'duration': 279,
+            'alt_title': 'Wonderwall (Remastered)',
+            'age_limit': 0,
+            'channel': 'Oasis',
+            'channel_follower_count': int,
+            'categories': ['Music'],
+            'availability': 'public',
+            'like_count': int,
+            'playable_in_embed': True,
+            'artist': 'Oasis',
+        },
+        'add_ie': ['Youtube'],
+    }, {
+        'url': 'https://www.last.fm/music/Oasis/_/Don%27t+Look+Back+In+Anger+-+Remastered/',
+        'only_matching': True,
+    }, {
+        'url': 'https://www.last.fm/music/Guns+N%27+Roses/_/Sweet+Child+o%27+Mine',
+        'only_matching': True,
+    }]
+
+    def _real_extract(self, url):
+        video_id = self._match_id(url)
+        webpage = self._download_webpage(url, video_id)
+        player_url = self._search_regex(r'(?s)class="header-new-playlink"\s+href="([^"]+)"', webpage, 'player_url')
+        return self.url_result(player_url, 'Youtube')


Test patch: