Check-in [34f8a3d27b]
Overview
| Comment: | Prepare row() and play() wrappers. No genre requests yet. (Still just a planned channel pugin.) |
|---|---|
| Downloads: | Tarball | ZIP archive | SQL archive |
| Timelines: | family | ancestors | descendants | both | trunk |
| Files: | files | file ages | folders |
| SHA1: |
34f8a3d27b98ac005a747f63bcffd20c |
| User & Date: | mario on 2015-05-01 23:30:41 |
| Other Links: | manifest | tags |
Context
|
2015-05-02
| ||
| 05:39 | More specific log.HTTP messages (GET vs POST) check-in: 8ede46a0a1 user: mario tags: trunk | |
|
2015-05-01
| ||
| 23:30 | Prepare row() and play() wrappers. No genre requests yet. (Still just a planned channel pugin.) check-in: 34f8a3d27b user: mario tags: trunk | |
| 23:10 | Rename 8tracks module to have a legal Python identifier (rather than the globals()/module rename workaround). check-in: 8cd49580a4 user: mario tags: trunk | |
Changes
Modified contrib/eighttracks.py from [d541531c5f] to [dbd3df8c86].
1 2 3 4 5 6 7 8 9 10 11 12 13 |
# encoding: UTF-8
# api: streamtuner2
# title: 8tracks
# description: radio created by people, not algorithms
# version: 0.1
# type: channel
# category: collection
# config:
# { name: eighttracks_apikey, value: "", type: text, description: Custom API access key. }
# priority: optional
# url: http://8tracks.com/
# documentation: https://8tracks.com/developers
#
| > | > | | > > > | | | | | | > > > > > > > > > > > > > > > > > > > > > > > | > > > > > > > | > > > > | > > > | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# encoding: UTF-8
# api: streamtuner2
# title: 8tracks
# description: radio created by people, not algorithms
# version: 0.1
# type: channel
# category: collection
# config:
# { name: eighttracks_apikey, value: "", type: text, description: Custom API access key. }
# { name: eighttracks_safe, value: 1, type: bool, description: Filter explicit/NSFW tracks. }
# priority: optional
# url: http://8tracks.com/
# documentation: https://8tracks.com/developers
#
# Requires a pingback on playing a track
# → which is near impossible without player control.
# → Automatic/implied notifications could work.
# → Or checking via dbus/mpris even (less assertable).
# → Else a customized playlist export with the reporting URL as
# faux first entry even.
# → Or an external URL redirector just (api.i-o/cache service).
#
import json
import re
from config import *
from channels import *
import ahttp
# 8tracks mix tapes
class eighttracks (ChannelPlugin):
# description
has_search = False
listformat = "pls"
titles = dict(listeners=False, playing="Location")
categories = ["none"]
catmap = {}
base = "http://8tracks.com/mixes/1?format=json&api_key=%s" # or X-Api-Key: header
cid = ""
# Mix types, genres, etc?
def update_categories(self):
self.categories = []
# Excerpt newest or most popular
def update_streams(self, cat, search=None):
row = {
"url": "urn:8tracks",
"id": "$mix_id-12345",
}
return []
# Craft a stream URL with play token
def row(self):
self.status("Retrieving playback token...")
r = ChannelPlugin.row(self)
token = self.api("sets/new")["play_token"]
track = self.api("sets/{}/play".format(r["id"]))
r["url"] = track["set"]["track"]["track_file_stream_url"]
# Call after .play()
def report(self, mixid)
self.api("sets/{}/report".format(mixid), {"track_id": mixid, "mix_id": mixid})
#def play(self):
# ChannelPlugin.play(self)
# self.report()
# Patch API url together, send request, decode JSON and whathaveyou
def api(self, method="mix_sets/all", *params):
params.update({
"api_version": 3,
"api_key": conf.eighttracks_apikey or self.cid,
#"include": "mixes",
})
try:
j = ahttp.get("http://8tracks.com/{}.json".format(method), params)
r = json.loads(j)
# test for mishaps
if "errors" in r and r["errors"]:
self.status(r["errors"])
raise Exception(r)
return r
except Exception as e:
log.ERR("8tracks API request failed:", e)
return []
|