Skip to content

Commit

Permalink
bili
Browse files Browse the repository at this point in the history
  • Loading branch information
yfang1644 committed Nov 5, 2017
1 parent 0417a60 commit 88636b9
Show file tree
Hide file tree
Showing 23 changed files with 857 additions and 470 deletions.
64 changes: 36 additions & 28 deletions plugin.audio.baidu/default.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# -*- coding: utf-8 -*-

from xbmcswift2 import Plugin
from urllib import quote_plus
import urllib2
from json import loads
from common import get_html
from iqiyi import video_from_vid as IQIYI_from_vid
Expand All @@ -11,6 +13,8 @@
__UserAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:6.0.2) Gecko/20100101 Firefox/6.0.2'

plugin = Plugin()
url_for = plugin.url_for

HOST = 'http://music.baidu.com'
BANNER_FMT = '[COLOR gold][%s][/COLOR]'

Expand All @@ -19,11 +23,14 @@ def pageList(tree, endpoint):
pages = tree.find_all('a', {'class': 'page-navigator-number'})
items = [{
'label': page.text.strip(),
'path': plugin.url_for(endpoint, url=page['href'].encode('utf-8'))
'path': url_for(endpoint, url=page['href'].encode('utf-8'))
} for page in pages]

return items

@plugin.route('/stay')
def stay():
pass

@plugin.route('/playMV/<source>/<tvid>/<vid>/<mvid>/<url>')
def playMV(source, tvid, vid, mvid, url):
Expand Down Expand Up @@ -61,13 +68,13 @@ def MVList(url):

items.append({
'label': item['title'],
'path': plugin.url_for('playMV',
source=item['source'],
tvid='0' if tvid == '' else tvid,
vid='0' if vid == '' else vid,
mvid='0' if mvid == '' else mvid,
url=file_link),
'info': {'duration': item['time']},
'path': url_for('playMV',
source=item['source'],
tvid='0' if tvid == '' else tvid,
vid='0' if vid == '' else vid,
mvid='0' if mvid == '' else mvid,
url=file_link),
'info': {'title': item['title'], 'duration': item['time']},
'is_playable': True
})

Expand All @@ -86,7 +93,7 @@ def musiclist(url):
items = [{
'label': item.a['title'],
'thumbnail': item.img['org_src'],
'path': plugin.url_for('MVList', url=item.a['href']),
'path': url_for('MVList', url=item.a['href']),
} for item in soup]

items += pageList(tree, 'musiclist')
Expand All @@ -106,7 +113,7 @@ def mv():
for item in p:
items.append({
'label': item.text.strip(),
'path': plugin.url_for('musiclist', url=item.a['href'])
'path': url_for('musiclist', url=item.a['href'])
})

return items
Expand All @@ -122,7 +129,6 @@ def playBD(sid):
plugin.set_resolved_url(url)



@plugin.route('/taglist/<url>')
def taglist(url):
if url[0] == '/':
Expand All @@ -140,8 +146,9 @@ def taglist(url):

items.append({
'label': js['songTitle'],
'path': plugin.url_for('playBD', sid=js['id']),
'is_playable': True
'path': url_for('playBD', sid=js['id']),
'is_playable': True,
'info': {'title': js['songTitle']}
})

items += pageList(tree, 'taglist')
Expand All @@ -155,12 +162,12 @@ def tag():
soups = tree.find_all('dl', {'class': 'tag-mod'})

for soup in soups:
items += [{'label': BANNER_FMT % soup.dt.text}]
items += [{'label': BANNER_FMT % soup.dt.text, 'path': url_for('stay')}]
p = soup.find_all('span', {'class': 'tag-list clearfix'})
for item in p:
items.append({
'label': item.text.strip(),
'path': plugin.url_for('taglist', url=item.a['href'])
'path': url_for('taglist', url=item.a['href'])
})

return items
Expand All @@ -177,7 +184,7 @@ def artistAlbum(url):
items = []

# songs
items += [{'label': '单曲'}]
items += [{'label': '单曲', 'path': url_for('stay')}]
soup1 = tree.find_all('div', {'class': 'song-list-wrap'})
soups = soup1[0].find_all('span', {'class': 'music-icon-hook'})
for item in soups:
Expand All @@ -186,35 +193,36 @@ def artistAlbum(url):

items.append({
'label': js['songTitle'],
'path': plugin.url_for('playBD', sid=js['id']),
'is_playable': True
'path': url_for('playBD', sid=js['id']),
'is_playable': True,
'info': {'title': js['songTitle']}
})

items += pageList(pages[0], 'artistAlbum')

# albums
items += [{'label': '专辑'}]
items += [{'label': '专辑', 'path': url_for('stay')}]
soup2 = tree.find_all('div', {'class': 'album-list-wrap'})
soups = soup2[0].find_all('div', {'class': 'album-cover'})
for item in soups:
js = loads(item['data-albumdata'])
items.append({
'label': js['albumTitle'],
'thumbnail': js['albumPic'],
'path': plugin.url_for('taglist', url='/album/'+js['id']),
'path': url_for('taglist', url='/album/'+js['id']),
})

items += pageList(pages[1], 'artistAlbum')

# mvs
items += [{'label': 'MV'}]
items += [{'label': 'MV', 'path': url_for('stay')}]
soup3 = tree.find_all('div', {'class': 'mv-list-wrap'})
soups = soup3[0].find_all('li', {'class': 'mv-item'})
for item in soups:
items.append({
'label': item.a['title'],
'thumbnail': item.img['org_src'],
'path': plugin.url_for('MVList', url=item.a['href']),
'path': url_for('MVList', url=item.a['href']),
})
items += pageList(pages[2], 'artistAlbum')
return items
Expand All @@ -235,7 +243,7 @@ def artistName(url):
try:
items.append({
'label': item.text.strip(),
'path': plugin.url_for('artistAlbum', url=item.a['href'])
'path': url_for('artistAlbum', url=item.a['href'])
})
except:
pass
Expand All @@ -254,7 +262,7 @@ def artist():
for item in p:
items.append({
'label': item.text.strip(),
'path': plugin.url_for('artistName', url=item.a['href'])
'path': url_for('artistName', url=item.a['href'])
})

return items
Expand All @@ -274,7 +282,7 @@ def albumlist(url):
c = item.find_all('p', {'class': 'text-title'})
items.append({
'label': c[0].text,
'path': plugin.url_for('MVList', url=c[0].a['href']),
'path': url_for('MVList', url=c[0].a['href']),
'thumbnail': item.img['src'],
})

Expand All @@ -292,12 +300,12 @@ def songlist():

items = []
for soup in soups:
items += [{'label': BANNER_FMT % soup.dt.text}]
items += [{'label': BANNER_FMT % soup.dt.text, 'path': url_for('stay')}]
p = soup.find_all('dd')
for item in p:
items.append({
'label': item.text.strip(),
'path': plugin.url_for('albumlist', url=item.a['href'].encode('utf-8'))
'path': url_for('albumlist', url=item.a['href'].encode('utf-8'))
})

return items
Expand All @@ -313,7 +321,7 @@ def root():

items = [{
'label': item,
'path': plugin.url_for(mainlist[item]),
'path': url_for(mainlist[item]),
} for item in mainlist]

return items
Expand Down
182 changes: 182 additions & 0 deletions plugin.audio.qingting/addon.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,182 @@
# -*- coding: utf-8 -*-

from xbmcswift2 import Plugin
from urllib import urlencode
import urllib2
from json import loads

userAgent = 'Opera/9.80 (Android 2.3.4; Linux; Opera Mobi/build-1107180945; U; en-GB) Presto/2.8.149 Version/11.10'
headers = {'User-Agent': userAgent}

plugin = Plugin()
url_for = plugin.url_for

HOST = 'http://www.qingting.fm'

BANNER_FMT = '[COLOR gold][%s][/COLOR]'
def get_html(url):
req = urllib2.Request(url, headers=headers)
response = urllib2.urlopen(req)
httpdata = response.read()
response.close()
return httpdata


@plugin.route('/stay')
def stay():
pass

@plugin.route('/pagelist/<id>')
def pagelist(id):
plugin.set_content('music')
pageAPI = 'http://i.qingting.fm/wapi/channels/{}/programs/page/1/pagesize/1000'
page = get_html(pageAPI.format(id))
js = loads(page)

for item in js['data']:
thisitem = {
'label': item['name'],
'info': {'title': item['name'], 'duration': int(item['duration'])}
}
path = item['file_path']
if path is not None:
thisitem['path'] = 'http://od.qingting.fm/' + path
thisitem['is_playable'] = True
else:
thisitem['path'] = url_for('stay')
yield thisitem


@plugin.route('/Regions/<id>/<page>')
def Regions(id, page=1):
req = {
'page': 1,
'pagesize': 12,
'with_total': 'true'
}

regionAPI = 'http://rapi.qingting.fm/categories/{}/channels?'
html = get_html(regionAPI.format(id) + urlencode(req))
js = loads(html)['Data']

page = int(page)
total_page = (js['total'] + 11) // 12
if page > 1:
yield {
'label': u'上一页 - {0}/{1}'.format(page, total_page),
'path': url_for('Regions', id=id, page=page-1)
}

for item in js['items']:
cid = item['content_id']
try:
title = item['title'] + '(%s)' % (item['nowplaying']['title'])
dur = int(item['nowplaying']['duration'])
except:
title = item['title']
dur = 0
yield {
'label': title,
'path': 'http://lhttp.qingting.fm/live/{}/64k.mp3'.format(cid),
'thumbnail': item['cover'],
'is_playable': True,
'info': {'title': title, 'duration': dur}
}
if page < total_page:
yield {
'label': u'下一页 - {0}/{1}'.format(page, total_page),
'path': url_for('Regions', id=id, page=page+1)
}


@plugin.route('/radiopage')
def radiopage():
radioPage = 'http://rapi.qingting.fm/categories'
page = get_html(radioPage)
js = loads(page)

data = js['Data']['regions'] + js['Data']['regions_map']

for item in data:
if item['id'] < 0:
continue
yield {
'label': item['title'],
'path': url_for('Regions', id=item['id'], page=1)
}

for topic in js['Data']['program_categories']:
continue
yield {
'label': topic['title'],
'path': url_for('Regions', id=topic['id'], page=1),
'thumbnail': topic['cover']
}

@plugin.route('/sublist/<id>/<attrs>/<page>')
def sublist(id, attrs=0, page=1):
req = {
'category': id,
'attrs': attrs,
'curpage': page
}
cateAPI = 'http://i.qingting.fm/capi/neo-channel-filter?'
html = get_html(cateAPI + urlencode(req))
js = loads(html)

total_page = (int(js['total']) + 11) // 12
page = int(page)
if page > 1:
yield {
'label': u'上一页 - {0}/{1}'.format(page, total_page),
'path': url_for('sublist', id=id, attrs=attrs, page=page-1)
}

for item in js['data']['channels']:
yield {
'label': item['title'],
'path': url_for('pagelist', id=item['id']),
'thumbnail': item['cover'],
'info': {'plot': item['description']}
}

if page < total_page:
yield {
'label': u'下一页 - {0}/{1}'.format(page, total_page),
'path': url_for('sublist', id=id, attrs=attrs, page=page+1)
}
for filter in js['data']['filters']:
for j in filter['values']:
yield {
'label': j['name'],
'path': url_for('sublist', id=id, attrs=j['id'], page=1)
}

@plugin.route('/categories')
def categories():
cateAPI = 'http://i.qingting.fm/capi/neo-channel-filter?'
page = get_html(cateAPI)
js = loads(page)

for item in js['data']['categories']:
yield {
'label': item['name'],
'path': url_for('sublist', id=item['id'], attrs=0, page=1)
}

@plugin.route('/')
def root():
mainlist = {
'分类': 'categories',
'电台': 'radiopage'
}

items = [{
'label': item,
'path': url_for(mainlist[item]),
} for item in mainlist]

return items

if __name__ == '__main__':
plugin.run()
Loading

0 comments on commit 88636b9

Please sign in to comment.