Playing media from 4shared.com

  Thread Rating:
  • 0 Votes - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Post Reply
pakee Offline
Senior Member
Posts: 222
Joined: Jan 2012
Reputation: 4
Post: #1
Hi,
While writing my plugin, I uncovered an online list of artists/albums/songs as well as links to the page where they are posted on 4shared.com. From the 4shared page's source, I extracted the media link and passed this on to the XBMC player and it used to work fine. Recently it stopped and I realized that if I am logged into the website and paste in the same url into the browser, the stream opens fine. If I sign out and retry, it doesn't work

for example, from this 4shared page, I get this media link

Has anyone had any experience with this? I have tried messing around with cookiejar and mechanize browser but haven't been able to get it to work yet. Also looked at the 4shared REST/SOAP apis but they seem to require going through search to find the 4shared urls (which doesn't work for files which are not public)

Thanks!
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 803
Joined: Oct 2010
Reputation: 17
Post: #2
Head over to xbmchub.com and take a look at urlresolver. It should be going into the main repo soon and should do exactly what you want. There are 30 some resolvers tested and working, so plenty of example code.
find quote
pakee Offline
Senior Member
Posts: 222
Joined: Jan 2012
Reputation: 4
Post: #3
Thanks for the info. I spent some time looking at the code of the resolvers and it seems they are all exercises in parsing out links from html pages.
I already have extracted out the required url but the problem I am running into is that the media file does not start playing unless a user is logged in.
That's actually the part I needed help with and unfortunately I couldn't find a resolver that does that
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 803
Joined: Oct 2010
Reputation: 17
Post: #4
The Real-debrid resolver uses the login function: https://github.com/Eldorados/script.modu...ldebrid.py
find quote
pakee Offline
Senior Member
Posts: 222
Joined: Jan 2012
Reputation: 4
Post: #5
Thanks for the pointer. Finally got some time to look at it and got something to work. Is there a way to pass the cookie to the player (along with the url)? Currently I am having to save the file (using the opener with the cj) to temp and pass the location of the temp file on to the player. Was wondering if that step could be bypassed? Also I'm trying to set the "now playing" label to be the song title using listitem.setinfo but seems like the player is ignoring it

Code:
import cookielib
def play_fourshared(url, name):
    username = 'username'
    password = 'password'
    cookie_file = os.path.join(__profilepath__, 'temp.cookies')
    media_file = os.path.join(__profilepath__, "temp.mp3")
    cj = cookielib.LWPCookieJar()

    #login to 4shared using opener
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    loginurl = 'https://www.4shared.com/login?login=%s&password=%s' % (username, password)
    resp = opener.open(loginurl)

    #save the cookie
    cj.save(cookie_file, ignore_discard=True)
    cj.load(cookie_file, ignore_discard=True)

    #update opener to use the saved cookie
    opener = urllib2.build_opener(urllib2.HTTPCookieProcessor(cj))
    urllib2.install_opener(opener)

    #read the file
    usock = opener.open(url)
    data = usock.read()
    usock.close()

    #save the file to temp
    fp = open(media_file, 'wb')
    fp.write(data)
    fp.close()

    #pass the location of the temp file to player
    print "playing stream name: " + str(name) + " url: " + str(media_file)
    listitem = xbmcgui.ListItem( label = str(name), iconImage = "DefaultVideo.png", thumbnailImage = xbmc.getInfoImage( "ListItem.Thumb" ), path=media_file )
    listitem.setInfo( type="video", infoLabels={ "Title": name, "Plot" : name } )
    xbmc.Player( xbmc.PLAYER_CORE_DVDPLAYER ).play( str(media_file), listitem)
(This post was last modified: 2012-05-09 23:06 by pakee.)
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 803
Joined: Oct 2010
Reputation: 17
Post: #6
You can play it directly without manually saving it to a local file, but you're skipping over the point where you'd do that.

data = usock.read() is saying "just start the download process for whatever it returns"

Instead of reading the data, you just want to get the url and feed that to Player.play(). I think usock.geturl() should give it to you.

Looks like you're setting it to video labels, not audio:
listitem.setInfo( type="video", infoLabels={ "Title": name, "Plot" : name } )
find quote
pakee Offline
Senior Member
Posts: 222
Joined: Jan 2012
Reputation: 4
Post: #7
Thanks, you're right..changing the type, mimetype fixed the label issue

Yes, for all the other scenarios I am simply passing the url of the media file directly to the player. But in this scenario, passing the url alone is not sufficient because a user has to be logged in in order for the url to get resolved to the mp3. By passing the url alone to the player, it seems a new session is created (which does not have the cj information)
Thats why I was trying to figure out a way to get the player to make the request using the cj info (similar to how the opener is making the request)
find quote
Bstrdsmkr Offline
Posting Freak
Posts: 803
Joined: Oct 2010
Reputation: 17
Post: #8
Does it work in a browser with cookies disabled? Maybe there's an alternate option. Otherwise, I think download then play is the only option
find quote
pakee Offline
Senior Member
Posts: 222
Joined: Jan 2012
Reputation: 4
Post: #9
No can't get it to work with cookies disabled...keeps saying "Your session has either timed out or has not been correctly established. Please login again."
Looks like downloading first is as good as it gets.

Thanks!
find quote