diff options
| author | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2024-06-18 19:08:53 -0400 |
|---|---|---|
| committer | Jakob L. Kreuze <zerodaysfordays@sdf.org> | 2024-06-18 19:09:10 -0400 |
| commit | deee3198c61da48e262ee7447335cd0515578195 (patch) | |
| tree | 223d7e15313be868296bcdddf70a2397c51d6b2b | |
| parent | 93cc0d954c5a36fc42f13d29799090196b082f29 (diff) | |
Scrape additional video metadata
| -rw-r--r-- | addon.py | 62 |
1 files changed, 60 insertions, 2 deletions
@@ -18,6 +18,7 @@ Video plugin for animations posted to Newgrounds. """ import concurrent.futures +import dateutil import os import sys from urllib.parse import urlencode, parse_qsl @@ -143,9 +144,47 @@ def get_addon_video_info(url): """ html = requests.get(url).text soup = BeautifulSoup(html, "html.parser") + + title = soup.find("div", id="embed_header").h2.string + thumbnail = soup.find("meta", property="og:image")["content"] + sidestats_popularity = soup.find_all('dl', 'sidestats')[0].find_all('dd') + views = sidestats_popularity[0].string + faves = sidestats_popularity[1].a.string + votes = sidestats_popularity[2].string + score = sidestats_popularity[3].span.string + sidestats_date_and_genre = soup.find_all('dl', 'sidestats')[1].find_all('dd') + upload_date = sidestats_date_and_genre[0].string + upload_time = sidestats_date_and_genre[1].string + genre = sidestats_date_and_genre[2].a.string + try: + tags = [tag.string for tag in soup.find('dd', 'tags').find_all('a')] + except AttributeError as e: + tags = [] + author_comments = ''.join([s for s in soup.find('div', id='author_comments').strings]).strip() + authors = [author.string for author in soup.find('ul', 'authorlinks').find_all('a') if author.get("class") is None] + if len(soup.find_all('h2', 'rated-a')) != 0: + rating = 'a' + elif len(soup.find_all('h2', 'rated-m')) != 0: + rating = 'm' + elif len(soup.find_all('h2', 'rated-t')) != 0: + rating = 't' + else: + rating = 'e' + return { - "title": soup.find("div", id="embed_header").h2.string, - "thumbnail": soup.find("meta", property="og:image")["content"], + "title": title, + "thumbnail": thumbnail, + "views": views, + "faves": faves, + "votes": votes, + "score": score, + "upload_date": upload_date, + "upload_time": upload_time, + "genre": genre, + "tags": tags, + "description": author_comments, + "authors": authors, + "rating": rating, "url": url, } @@ -211,6 +250,25 @@ def list_videos(genre, category=0, offset=0): info_tag = list_item.getVideoInfoTag() info_tag.setMediaType("movie") info_tag.setTitle(video["title"]) + + info_tag.setYear(int(video["upload_date"][-4:])) + info_tag.setRating(float(video["score"]), int(video["votes"].replace(',', ''))) + info_tag.setPlaycount(int(video["views"].replace(',', ''))) + info_tag.setPlot(video["description"]) + info_tag.setGenres([video["genre"]]) + info_tag.setDirectors(video["authors"]) + info_tag.setPremiered(dateutil.parser.parse(video["upload_date"]).strftime("%Y-%m-%d")) + info_tag.setTags(video["tags"]) + + if video["rating"] == "a": + info_tag.setMpaa("NC-17") + elif video["rating"] == "m": + info_tag.setMpaa("R") + elif video["rating"] == "t": + info_tag.setMpaa("PG-13") + else: + info_tag.setMpaa("PG") + # info_tag.setGenres([genre_info['genre']]) # info_tag.setPlot(video['plot']) # info_tag.setYear(video['year']) |