Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[plugin.audio.tripler] 3.0.0 #4392

Merged
merged 1 commit into from
Jul 7, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion plugin.audio.tripler/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
Copyright (c) 2023 Simon Mollema

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@@ -14,4 +16,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
THE SOFTWARE.
88 changes: 88 additions & 0 deletions plugin.audio.tripler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
# plugin.audio.tripler

A Kodi plugin for Triple R: an independent community radio station in Melbourne, Australia.

![Triple R Logo](resources/icon.png)

-----

## Frequently Asked Questions

### What is Triple R?

For more than 40 years Triple R has shaped and inspired the culture of Melbourne. Since its inception as an educational broadcaster in 1976, Triple R has become Australia's most influential community radio station with nearly 21,000 paid subscribers and broadcasting live to over 1,000,000 listeners per month across FM and digital (DAB+ digital radio, podcasts and online).

Broadcasting on 102.7FM and 3RRR Digital, the Triple R grid houses over 60 diverse programs. Music shows cover every genre imaginable from pop to punk rock, from R&B and electro to jazz, hip hop, country and metal. Specialist talks programs delve into topics as varied as the environment, human rights, politics, medical issues, gardening, cultural ventures and local interests.

### What does this plugin do?

This plugin aims to provide as much content as possible from the [Triple R Website, rrr.org.au,](https://www.rrr.org.au) in the Kodi media player. Currently provided are the following:

- Listen Live!
- Browse by Program
- Browse by Date
- Latest Segments
- Audio Archives
- Album Of The Week
- Soundscapes
- Events
- Subscriber Giveaways (for logged in users only!)

-----

## Installation

If you don't already use [Kodi](https://kodi.tv/), download and install that first.

### Release Version

If you would like to use the release version with automatic updates, please install [the published release in the Kodi repository](https://kodi.tv/addons/matrix/plugin.audio.tripler/) with the following steps:

- Open Kodi.
- Navigate to Add-ons > Install from Repository.
- Navigate to Kodi Add-on repository > Music add-ons > Triple R.
- Select "Install".

### Latest Development Version

If you would instead like to use the latest development version, [download the zip file](https://github.com/molzy/plugin.audio.tripler/archive/refs/heads/scraper.zip) to the same computer that is running Kodi. Afterwareds, follow these steps:

- Open Kodi.
- From the main menu, navigate to Settings > System > Add-ons.
- Enable "Unknown Sources".
- Go back to the main menu, and navigate to Add-ons > Install from Zip File.
- If you are prompted to confirm, select "Yes" on the prompt.
- Navigate to the downloaded zip file on your filesystem.
- Select "OK".

-----

## Screenshots

### Menu
![Plugin Menu](resources/screenshots/menu.jpg)

### Browse By Program
![Browse By Program](resources/screenshots/browse-by-program.jpg)

### Broadcast + Playlist
![Broadcast + Playlist](resources/screenshots/broadcast-playlist.jpg)

### Album Of The Week
![Album Of The Week](resources/screenshots/album-of-the-week.jpg)

### Browse By Date
![Browse By Date](resources/screenshots/browse-by-date.jpg)

### Soundscape
![Soundscape](resources/screenshots/soundscape.jpg)

-----

## License

This plugin was initially forked from a Triple R plugin written by [Damon Toumbourou](https://github.com/DamonToumbourou/plugin.audio.tripler).

The plugin was then fully rewritten by Simon Mollema.

The plugin is released under the terms of [the MIT license](LICENSE.txt).
2 changes: 1 addition & 1 deletion plugin.audio.tripler/addon.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import resources.lib.tripler as tripler

if __name__ == '__main__':
tripler.instance.run()
result = tripler.instance.parse()
36 changes: 25 additions & 11 deletions plugin.audio.tripler/addon.xml
Original file line number Diff line number Diff line change
@@ -1,30 +1,44 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<addon id="plugin.audio.tripler" name="Triple R" version="2.0.0" provider-name="Simon Mollema">
<addon id="plugin.audio.tripler" name="Triple R" version="3.0.0" provider-name="Simon Mollema">
<requires>
<import addon="xbmc.python" version="3.0.0"/>
<import addon="script.module.xbmcswift2" version="19.0.7"/>
<import addon="script.module.beautifulsoup4" version="4.9.3+matrix.1"/>
<import addon="xbmc.python" version="3.0.0" />
<import addon="script.module.pytz" version="2021.3.0+matrix.1" />
<import addon="script.module.beautifulsoup4" version="4.9.3+matrix.1" />
<import addon="plugin.video.youtube" version="6.8.18+matrix.1" optional="true" />
<import addon="plugin.audio.kxmxpxtx.bandcamp" version="0.4.1+matrix.1" optional="true" />
<import addon="plugin.audio.soundcloud" version="4.0.2" optional="true" />
<import addon="plugin.audio.indigitube" version="1.0.0" optional="true" />
</requires>
<extension point="xbmc.python.pluginsource" library="addon.py">
<provides>audio</provides>
</extension>
<extension point="xbmc.addon.metadata">
<platform>all</platform>
<language>en</language>
<summary lang="en_GB">Listen to podcasts avaliable from the Triple R: Independent Melbourne Radio station.</summary>
<summary lang="en_GB">Listen to Triple R: an independent community radio station in Melbourne, Australia.</summary>
<description lang="en_GB">For more than 40 years Triple R has shaped and inspired the culture of Melbourne. Since its inception as an educational broadcaster in 1976, Triple R has become Australia's most influential community radio station with nearly 21,000 paid subscribers and broadcasting live to over 1,000,000 listeners per month across FM and digital (DAB+ digital radio, podcasts and online). Broadcasting on 102.7FM and 3RRR Digital, the Triple R grid houses over 60 diverse programs. Music shows cover every genre imaginable from pop to punk rock, from R&amp;B and electro to jazz, hip hop, country and metal. Specialist talks programs delve into topics as varied as the environment, human rights, politics, medical issues, gardening, cultural ventures and local interests.</description>
<license>MIT</license>
<email>[email protected]</email>
<source>https://github.com/molzy/plugin.audio.tripler</source>
<news>Version 2.0.0
- Rewritten for Matrix / Python 3.
- Now scraping media information directly from new Triple R website.

Version 1.0.1
- Initial working version</news>
<news>Version 3.0.0
- Rewritten with more flexible parser
- More content added from website
- Improved user interface and menus
- Browsing programs by name and date now possible
- Broadcast track playlists are available
- Support for playing music through Bandcamp, YouTube and indigiTUBE
- Support for searching for music content by title and artist
- Subscriber-only giveaways can now be entered by signing in
</news>
<assets>
<icon>resources/icon.png</icon>
<fanart>resources/fanart.png</fanart>
<screenshot>resources/screenshots/menu.jpg</screenshot>
<screenshot>resources/screenshots/browse-by-program.jpg</screenshot>
<screenshot>resources/screenshots/browse-by-date.jpg</screenshot>
<screenshot>resources/screenshots/broadcast-playlist.jpg</screenshot>
<screenshot>resources/screenshots/album-of-the-week.jpg</screenshot>
<screenshot>resources/screenshots/soundscape.jpg</screenshot>
</assets>
</extension>
</addon>
Original file line number Diff line number Diff line change
@@ -25,36 +25,324 @@ msgctxt "Addon Description"
msgid "For more than 40 years Triple R has shaped and inspired the culture of Melbourne. Since its inception as an educational broadcaster in 1976, Triple R has become Australia's most influential community radio station with nearly 21,000 paid subscribers and broadcasting live to over 1,000,000 listeners per month across FM and digital (DAB+ digital radio, podcasts and online). Broadcasting on 102.7FM and 3RRR Digital, the Triple R grid houses over 60 diverse programs. Music shows cover every genre imaginable from pop to punk rock, from R&B and electro to jazz, hip hop, country and metal. Specialist talks programs delve into topics as varied as the environment, human rights, politics, medical issues, gardening, cultural ventures and local interests."
msgstr ""

msgctxt "#30999"
msgid ""
msgstr ""

#Plugin name

msgctxt "#30000"
msgid "Triple R"
msgstr ""

msgctxt "#30001"
msgid "Triple R - Live Stream"
msgstr ""

msgctxt "#30002"
msgid "On Demand - Segments"
msgstr ""

msgctxt "#30003"
msgid "On Demand - Episodes"
msgid "Listen Live!"
msgstr ""

msgctxt "#30004"
msgid "On Demand - Audio Archives"
msgid "> Next Page"
msgstr ""

msgctxt "#30005"
msgid "> Next Page"
msgid ">> Last Page"
msgstr ""

msgctxt "#30006"
msgid "aired %s"
msgstr ""

msgctxt "#30007"
msgid "Aired on %s."
msgid "Dated %s, Melbourne time."
msgstr ""

msgctxt "#30008"
msgid "Play with %s"
msgstr ""

msgctxt "#30009"
msgid "Settings"
msgstr ""

# Settings - Account

msgctxt "#30010"
msgid "Subscriber Account"
msgstr ""

msgctxt "#30011"
msgid "Use Account"
msgstr ""

msgctxt "#30012"
msgid "Email Address"
msgstr ""

msgctxt "#30013"
msgid "Sign In"
msgstr ""

msgctxt "#30014"
msgid "Sign Out"
msgstr ""

msgctxt "#30015"
msgid "Enter Email Address"
msgstr ""

msgctxt "#30016"
msgid "Enter Password"
msgstr ""

msgctxt "#30017"
msgid "Full Name"
msgstr ""

msgctxt "#30020"
msgid "Sign in to your Triple R account using your email address and password"
msgstr ""

msgctxt "#30021"
msgid "Sign out of your Triple R account"
msgstr ""

# Settings - Image Quality

msgctxt "#30022"
msgid "Image Quality"
msgstr ""

msgctxt "#30023"
msgid "Set the desired quality level for album art and band images"
msgstr ""

msgctxt "#30024"
msgid "High"
msgstr ""

msgctxt "#30025"
msgid "Medium"
msgstr ""

msgctxt "#30026"
msgid "Low"
msgstr ""

# Main Menu

msgctxt "#30032"
msgid "Browse by Program"
msgstr ""

msgctxt "#30033"
msgid "Browse by Date"
msgstr ""

msgctxt "#30034"
msgid "Latest Programs"
msgstr ""

msgctxt "#30035"
msgid "Latest Segments"
msgstr ""

msgctxt "#30036"
msgid "Audio Archives"
msgstr ""

msgctxt "#30037"
msgid "Album Of The Week"
msgstr ""

msgctxt "#30038"
msgid "Soundscapes"
msgstr ""

msgctxt "#30039"
msgid "Events"
msgstr ""

msgctxt "#30040"
msgid "Subscriber Giveaways"
msgstr ""

msgctxt "#30041"
msgid "Search"
msgstr ""

msgctxt "#30042"
msgid "Videos"
msgstr ""

# Broadcasts

msgctxt "#30049"
msgid "Broadcast"
msgstr ""

msgctxt "#30050"
msgid "Full Broadcast"
msgstr ""

msgctxt "#30051"
msgid "Segment"
msgstr ""

msgctxt "#30052"
msgid "Track Search"
msgstr ""

# Date Selection

msgctxt "#30059"
msgid "Next Day (%s)"
msgstr ""

msgctxt "#30060"
msgid "Today (%s)"
msgstr ""

msgctxt "#30061"
msgid "Previous Day (%s)"
msgstr ""

msgctxt "#30062"
msgid "%s (%s)"
msgstr ""

msgctxt "#30063"
msgid "This Month (%s)"
msgstr ""

msgctxt "#30064"
msgid "This Year (%s)"
msgstr ""

msgctxt "#30065"
msgid "Select Date (%s)"
msgstr ""

# Searching

msgctxt "#30066"
msgid "Search playlists instead"
msgstr ""

msgctxt "#30067"
msgid "Enter Search Query"
msgstr ""

msgctxt "#30068"
msgid "Enter Playlist Search Query"
msgstr ""

# Subscription

msgctxt "#30069"
msgid "Enter Giveaway"
msgstr ""

msgctxt "#30070"
msgid "Select to enter this giveaway."
msgstr ""

msgctxt "#30071"
msgid "Giveaway Entered"
msgstr ""

msgctxt "#30072"
msgid "Thanks for being a Triple R subscriber!"
msgstr ""

msgctxt "#30073"
msgid "Cannot Enter Giveaway"
msgstr ""

msgctxt "#30074"
msgid "Already entered!"
msgstr ""

msgctxt "#30075"
msgid "Is your subscription active?"
msgstr ""

msgctxt "#30076"
msgid "Subscribe and sign in to enter!"
msgstr ""

msgctxt "#30077"
msgid "%s signed in"
msgstr ""

msgctxt "#30078"
msgid "Thanks for subscribing!"
msgstr ""

msgctxt "#30079"
msgid "%s signed out"
msgstr ""

msgctxt "#30081"
msgid "Subscribe To Listen"
msgstr ""

msgctxt "#30082"
msgid "https://www.rrr.org.au/subscribe - Subscribe and sign in to enter the below giveaways!"
msgstr ""

msgctxt "#30083"
msgid "https://www.rrr.org.au/subscribe - Subscribe and sign in to listen to all audio archives!"
msgstr ""

msgctxt "#30084"
msgid "Subscribers Only"
msgstr ""

msgctxt "#30085"
msgid "Sign in failure"
msgstr ""

msgctxt "#30086"
msgid "%s could not sign in"
msgstr ""

msgctxt "#30087"
msgid "Sign out failure"
msgstr ""

msgctxt "#30088"
msgid "%s could not sign out"
msgstr ""

# Context Menus

msgctxt "#30100"
msgid "%s using the context menu."
msgstr ""

msgctxt "#30101"
msgid "View playlist"
msgstr ""

msgctxt "#30102"
msgid "Search for this track"
msgstr ""

msgctxt "#30103"
msgid "Search for this artist"
msgstr ""

msgctxt "#30104"
msgid "Search for '%s'"
msgstr ""

msgctxt "#30105"
msgid "Search for '%s' on Triple R"
msgstr ""

msgctxt "#30106"
msgid "Search for '%s' on Bandcamp"
msgstr ""

msgctxt "#30107"
msgid "Search for '%s' on YouTube"
msgstr ""
152 changes: 152 additions & 0 deletions plugin.audio.tripler/resources/lib/media.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import re

class Media:
RE_BANDCAMP_ALBUM_ID = re.compile(r'https://bandcamp.com/EmbeddedPlayer/.*album=(?P<media_id>[^/]+)')
RE_BANDCAMP_ALBUM_ART = re.compile(r'"art_id":(\w+)')
BANDCAMP_ALBUM_PLUGIN_BASE_URL = 'plugin://plugin.audio.kxmxpxtx.bandcamp/?mode=list_songs'
BANDCAMP_ALBUM_PLUGIN_FORMAT = '{}&album_id={}&item_type=a'
BANDCAMP_ALBUM_ART_URL = 'https://bandcamp.com/api/mobile/24/tralbum_details?band_id=1&tralbum_type=a&tralbum_id={}'

RE_BANDCAMP_ALBUM_LINK_ID = re.compile(r'(?P<media_id>https?://[^/\.]+\.bandcamp.com/album/[\w\-]+)')
RE_BANDCAMP_BAND_LINK_ID = re.compile(r'(?P<media_id>https?://[^/\.]+\.bandcamp.com/)$')

RE_BANDCAMP_TRACK_ID = re.compile(r'(?P<media_id>https?://[^/\.]+\.bandcamp.com/(track|album)/[\w\-]+)')
BANDCAMP_TRACK_PLUGIN_BASE_URL = 'plugin://plugin.audio.kxmxpxtx.bandcamp/?mode=url'
BANDCAMP_TRACK_PLUGIN_FORMAT = '{}&url={}'
RE_BANDCAMP_TRACK_ART = re.compile(r'art_id&quot;:(?P<art_id>\d+),')
RE_BANDCAMP_TRACK_BAND_ART = re.compile(r'data-band="[^"]*image_id&quot;:(?P<band_art_id>\d+)}"')

RE_BANDCAMP_ART_QUALITY_SEARCH = r'/img/(?P<art>[^_]+)_(?P<quality>\d+)\.jpg'

RE_SOUNDCLOUD_PLAYLIST_ID = re.compile(r'.+soundcloud\.com/playlists/(?P<media_id>[^&]+)')
SOUNDCLOUD_PLUGIN_BASE_URL = 'plugin://plugin.audio.soundcloud/'
SOUNDCLOUD_PLUGIN_FORMAT = '{}?action=call&call=/playlists/{}'

RE_YOUTUBE_VIDEO_ID = re.compile(r'^(?:(?:https?:)?\/\/)?(?:(?:www|m)\.)?(?:youtube(?:-nocookie)?\.com|youtu.be)(?:\/(?:[\w\-]+\?v=|embed\/|v\/)?)(?P<media_id>[\w\-]+)(?!.*list)\S*$')
YOUTUBE_PLUGIN_BASE_URL = 'plugin://plugin.video.youtube/play/'
YOUTUBE_VIDEO_PLUGIN_FORMAT = '{}?video_id={}&play=1'
YOUTUBE_VIDEO_ART_URL_FORMAT = 'https://i.ytimg.com/vi/{}/hqdefault.jpg'

RE_YOUTUBE_PLAYLIST_ID = re.compile(r'^(?:(?:https?:)?\/\/)?(?:(?:www|m)\.)?(?:youtube(?:-nocookie)?\.com|youtu.be)\/.+\?.*list=(?P<media_id>[\w\-]+)')
YOUTUBE_PLAYLIST_PLUGIN_FORMAT = '{}?playlist_id={}&order=default&play=1'
YOUTUBE_PLAYLIST_ART_URL = 'https://youtube.com/oembed?url=https%3A//www.youtube.com/playlist%3Flist%3D{}&format=json'

RE_INDIGITUBE_ALBUM_ID = re.compile(r'https://www.indigitube.com.au/embed/album/(?P<media_id>[^"]+)')
INDIGITUBE_ALBUM_PLUGIN_BASE_URL = 'plugin://plugin.audio.indigitube/?mode=list_songs'
INDIGITUBE_ALBUM_PLUGIN_FORMAT = '{}&album_id={}'

RE_SPOTIFY_ALBUM_ID = re.compile(r'.+spotify\.com(\/embed)?\/album\/(?P<media_id>[^&?\/]+)')
RE_SPOTIFY_PLAYLIST_ID = re.compile(r'.+spotify\.com(\/embed)?\/playlist\/(?P<media_id>[^&]+)')

RE_APPLE_ALBUM_ID = re.compile(r'.+music\.apple\.com\/au\/album\/(?P<media_id>.+)')
APPLE_ALBUM_URL = 'https://music.apple.com/au/album/{}'

EXT_SEARCH_PLUGIN_FORMAT = 'plugin://plugin.audio.tripler/tracks/ext_search?q={search}'

RE_MEDIA_URLS = {
'bandcamp': {
're': RE_BANDCAMP_ALBUM_ID,
'base': BANDCAMP_ALBUM_PLUGIN_BASE_URL,
'format': BANDCAMP_ALBUM_PLUGIN_FORMAT,
'name': 'Bandcamp',
},
'bandcamp_track': {
're': RE_BANDCAMP_TRACK_ID,
'base': BANDCAMP_TRACK_PLUGIN_BASE_URL,
'format': BANDCAMP_TRACK_PLUGIN_FORMAT,
'name': 'Bandcamp',
},
'bandcamp_link': {
're': RE_BANDCAMP_ALBUM_LINK_ID,
'base': BANDCAMP_TRACK_PLUGIN_BASE_URL,
'format': BANDCAMP_TRACK_PLUGIN_FORMAT,
'name': 'Bandcamp',
},
'bandcamp_band_link': {
're': RE_BANDCAMP_BAND_LINK_ID,
'format': EXT_SEARCH_PLUGIN_FORMAT,
'name': 'Bandcamp Band Search',
},
'soundcloud': {
're': RE_SOUNDCLOUD_PLAYLIST_ID,
'base': SOUNDCLOUD_PLUGIN_BASE_URL,
'format': SOUNDCLOUD_PLUGIN_FORMAT,
'name': 'SoundCloud',
},
'youtube': {
're': RE_YOUTUBE_VIDEO_ID,
'base': YOUTUBE_PLUGIN_BASE_URL,
'format': YOUTUBE_VIDEO_PLUGIN_FORMAT,
'name': 'YouTube',
},
'youtube_playlist': {
're': RE_YOUTUBE_PLAYLIST_ID,
'base': YOUTUBE_PLUGIN_BASE_URL,
'format': YOUTUBE_PLAYLIST_PLUGIN_FORMAT,
'name': 'YouTube',
},
'indigitube': {
're': RE_INDIGITUBE_ALBUM_ID,
'base': INDIGITUBE_ALBUM_PLUGIN_BASE_URL,
'format': INDIGITUBE_ALBUM_PLUGIN_FORMAT,
'name': 'indigiTUBE',
},
'spotify': {
're': RE_SPOTIFY_ALBUM_ID,
'format': EXT_SEARCH_PLUGIN_FORMAT,
'name': 'Album Search',
},
'spotify_playlist': {
're': RE_SPOTIFY_PLAYLIST_ID,
'format': EXT_SEARCH_PLUGIN_FORMAT,
'name': 'Playlist Search',
},
'apple': {
're': RE_APPLE_ALBUM_ID,
'format': EXT_SEARCH_PLUGIN_FORMAT,
'name': 'Album Search',
},
}

def __init__(self, quality):
self.quality = quality

def parse_media_id(self, plugin, media_id, search=''):
info = self.RE_MEDIA_URLS.get(plugin, {})
if info:
return info.get('format', '').format(info.get('base', ''), media_id, search=search)
else:
return ''

def parse_art(self, art):
if art and 'f4.bcbits.com' in art:
band = '/img/a' not in art
quality = self._bandcamp_band_quality() if band else self._bandcamp_album_quality()
art = re.sub(self.RE_BANDCAMP_ART_QUALITY_SEARCH, f'/img/\g<art>_{quality}.jpg', art)
if art and '/600x600bf-60.jpg' in art:
art = art.replace('/600x600bf-60.jpg', self._apple_album_quality())
return art

def _bandcamp_band_quality(self):
if self.quality == 0:
return 1 # full resolution
if self.quality == 1:
return 10 # 1200px wide
if self.quality == 2:
return 25 # 700px wide

def _bandcamp_album_quality(self):
if self.quality == 0:
return 5 # 700px wide
if self.quality == 1:
return 2 # 350px wide
if self.quality == 2:
return 9 # 210px wide

def _apple_album_quality(self):
if self.quality == 0:
return '/600x600bf.jpg'
if self.quality == 1:
return '/600x600bf-60.jpg'
if self.quality == 2:
return '/300x300bb-60.jpg'
2,230 changes: 2,230 additions & 0 deletions plugin.audio.tripler/resources/lib/scraper.py

Large diffs are not rendered by default.

753 changes: 607 additions & 146 deletions plugin.audio.tripler/resources/lib/tripler.py

Large diffs are not rendered by default.

131 changes: 131 additions & 0 deletions plugin.audio.tripler/resources/lib/website.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,131 @@
from resources.lib.scraper import USER_AGENT

from urllib.request import Request, build_opener, HTTPCookieProcessor
from urllib.parse import urlencode
from urllib.error import HTTPError

import http.cookiejar
import os

class TripleRWebsite():
def __init__(self, cookiepath):
self._cookiepath = cookiepath
self.cj = http.cookiejar.LWPCookieJar()

def _loadcj(self):
if os.path.isfile(self._cookiepath):
self.cj.load(self._cookiepath)
return True
else:
return False

def _delcj(self):
self.cj = http.cookiejar.LWPCookieJar()
try:
os.remove(self._cookiepath)
except:
pass

def request(self, url, data=None):
if data:
req = Request(url, data.encode())
else:
req = Request(url)
req.add_header('User-Agent', USER_AGENT)

opener = build_opener(HTTPCookieProcessor(self.cj))

try:
response = opener.open(req)
except HTTPError as e:
return e

source = response.read().decode()
response.close()

return source

def login(self, emailaddress, password):
if password is None and self._loadcj():
account_url = 'https://www.rrr.org.au/account'
source = self.request(account_url)
if self._check_login(source, emailaddress):
return self.cj
else:
return False

if emailaddress and password:
login_url = 'https://www.rrr.org.au/sign-in'
login_data = urlencode(
{
'subscriber_account[email]': emailaddress,
'subscriber_account[password]': password,
'_csrf': ['', 'javascript-disabled'],
}
)

source = self.request(login_url, data=login_data)

if isinstance(source, HTTPError):
return False

if source and self._check_login(source, emailaddress):
self.cj.save(self._cookiepath)
return self.cj
else:
return False

def _check_login(self, source, emailaddress):
if emailaddress.lower() in source.lower():
return True
else:
return False

def logout(self):
logout_url = 'https://www.rrr.org.au/sign-out'
logout_data = urlencode(
{
'_csrf': ['', 'javascript-disabled'],
}
)
source = self.request(logout_url, data=logout_data)
if isinstance(source, HTTPError):
if source.code == 500:
return True
else:
return False
if source:
self._delcj()
return True
else:
return False

def logged_in(self):
return self._loadcj()

def subscribed(self):
check_url = 'https://www.rrr.org.au/account/check-active.json'
source = self.request(check_url)
if isinstance(source, HTTPError):
if source.code == 500:
return True
else:
return False
return self._check_subscription(source)

def _check_subscription(self, source):
if '"active":' in source and 'true' in source:
return True
else:
return False

def enter(self, resource_path):
entry_url = ''.join(('https://www.rrr.org.au/subscriber-', resource_path[1:]))
entry_data = urlencode(
{
'entry[null]': '',
'_csrf': ['', 'javascript-disabled'],
}
)

return self.request(entry_url, entry_data)
Binary file added plugin.audio.tripler/resources/qr-subscribe.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
112 changes: 112 additions & 0 deletions plugin.audio.tripler/resources/settings.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
<?xml version="1.0" ?>
<settings version="1">
<section id="plugin.audio.tripler">
<category id="subscriber account" label="30010" help="">
<group id="1">
<setting id="authenticated" type="boolean" label="30999" help="">
<level>4</level>
<default>false</default>
</setting>
<setting id="fullname" type="string" label="30017" help="">
<level>0</level>
<default/>
<enable>false</enable>
<constraints>
<allowempty>true</allowempty>
</constraints>
<dependencies>
<dependency type="visible">
<condition operator="!is" setting="authenticated">false</condition>
</dependency>
</dependencies>
<control type="edit" format="string">
<heading>30017</heading>
</control>
</setting>
<setting id="emailaddress" type="string" label="30012" help="">
<level>0</level>
<default/>
<enable>false</enable>
<constraints>
<allowempty>true</allowempty>
</constraints>
<dependencies>
<dependency type="visible">
<condition operator="!is" setting="authenticated">false</condition>
</dependency>
</dependencies>
<control type="edit" format="string">
<heading>30012</heading>
</control>
</setting>
<setting id="subscribed" type="integer" label="30075" help="30075">
<level>0</level>
<default>0</default>
<enable>false</enable>
<constraints>
<options>
<option label="No">0</option>
<option label="Yes">1</option>
</options>
</constraints>
<dependencies>
<dependency type="visible">
<condition operator="!is" setting="authenticated">false</condition>
</dependency>
</dependencies>
<control type="list" format="string">
<heading>30075</heading>
</control>
</setting>
<setting id="subscribed-check" type="string" label="30999" help="">
<level>4</level>
<default/>
<constraints>
<allowempty>true</allowempty>
</constraints>
<control type="edit" format="string">
<heading>30999</heading>
</control>
</setting>
<setting id="sign-in" type="action" label="30013" help="30020">
<level>0</level>
<dependencies>
<dependency type="visible">
<condition operator="!is" setting="authenticated">true</condition>
</dependency>
</dependencies>
<control type="button" format="action">
<data>RunPlugin("plugin://plugin.audio.tripler/sign-in")</data>
</control>
</setting>
<setting id="sign-out" type="action" label="30014" help="30021">
<level>0</level>
<dependencies>
<dependency type="visible">
<condition operator="!is" setting="authenticated">false</condition>
</dependency>
</dependencies>
<control type="button" format="action">
<data>RunPlugin("plugin://plugin.audio.tripler/sign-out")</data>
</control>
</setting>
</group>
<group id="2">
<setting id="image_quality" type="integer" label="30022" help="30023">
<level>0</level>
<default>1</default>
<constraints>
<options>
<option label="30024">0</option>
<option label="30025">1</option>
<option label="30026">2</option>
</options>
</constraints>
<control type="list" format="string">
<heading>30022</heading>
</control>
</setting>
</group>
</category>
</section>
</settings>